Skip to content

Commit f31c183

Browse files
committed
Add the ability to make warning signs glow with glow ink sacks, closes #6003
1 parent 90044a6 commit f31c183

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- This comes with a new render function for datapacks to handle double-high crops, which is also used by hemp
88
- Add treated wood, steel and aluminium signs (BluSunrize)
99
- They work like vanilla signs, not much else to say
10+
- Add the ability to make warning signs glow with glow ink sacks (BluSunrize)
1011
- Remove CustomParticleManager (IMS)
1112
- Change High Explosive cartridges to return shells on use (voidsong-dragonfly)
1213
- Change hemp plants to use the same "half" property as vanilla double flowers (BluSunrize)

src/main/java/blusunrize/immersiveengineering/common/blocks/metal/WarningSignBlock.java

+48-1
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,46 @@
1414
import com.google.common.collect.ImmutableList;
1515
import net.minecraft.core.BlockPos;
1616
import net.minecraft.core.Direction;
17+
import net.minecraft.stats.Stats;
1718
import net.minecraft.util.StringRepresentable;
1819
import net.minecraft.util.Unit;
20+
import net.minecraft.world.InteractionHand;
21+
import net.minecraft.world.ItemInteractionResult;
22+
import net.minecraft.world.entity.player.Player;
23+
import net.minecraft.world.item.DyeColor;
24+
import net.minecraft.world.item.ItemStack;
25+
import net.minecraft.world.item.Items;
1926
import net.minecraft.world.item.context.BlockPlaceContext;
2027
import net.minecraft.world.level.BlockGetter;
28+
import net.minecraft.world.level.Level;
2129
import net.minecraft.world.level.block.Block;
30+
import net.minecraft.world.level.block.SoundType;
2231
import net.minecraft.world.level.block.state.BlockState;
2332
import net.minecraft.world.level.block.state.StateDefinition.Builder;
2433
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
34+
import net.minecraft.world.level.block.state.properties.BooleanProperty;
35+
import net.minecraft.world.level.gameevent.GameEvent;
36+
import net.minecraft.world.level.gameevent.GameEvent.Context;
37+
import net.minecraft.world.level.material.MapColor;
2538
import net.minecraft.world.phys.AABB;
39+
import net.minecraft.world.phys.BlockHitResult;
2640
import net.minecraft.world.phys.shapes.CollisionContext;
2741
import net.minecraft.world.phys.shapes.VoxelShape;
2842

2943
import java.util.Locale;
44+
import java.util.function.Supplier;
3045

3146
public class WarningSignBlock extends IEBaseBlock
3247
{
48+
private static final BooleanProperty GLOWING = BooleanProperty.create("glowing");
49+
public static final Supplier<Properties> PROPERTIES = () -> Block.Properties.of()
50+
.mapColor(MapColor.METAL)
51+
.sound(SoundType.METAL)
52+
.strength(3, 15)
53+
.requiresCorrectToolForDrops()
54+
.isViewBlocking((state, blockReader, pos) -> false)
55+
.lightLevel(b -> b.getValue(GLOWING)?9: 0);
56+
3357
private final WarningSignIcon icon;
3458

3559
public WarningSignBlock(WarningSignIcon icon, Properties properties)
@@ -42,7 +66,13 @@ public WarningSignBlock(WarningSignIcon icon, Properties properties)
4266
protected void createBlockStateDefinition(Builder<Block, BlockState> builder)
4367
{
4468
super.createBlockStateDefinition(builder);
45-
builder.add(IEProperties.FACING_HORIZONTAL, BlockStateProperties.WATERLOGGED);
69+
builder.add(IEProperties.FACING_HORIZONTAL, BlockStateProperties.WATERLOGGED, GLOWING);
70+
}
71+
72+
@Override
73+
protected BlockState getInitDefaultState()
74+
{
75+
return super.getInitDefaultState().setValue(GLOWING, false);
4676
}
4777

4878
@Override
@@ -61,6 +91,23 @@ public VoxelShape getShape(BlockState state, BlockGetter blockGetter, BlockPos b
6191
return SHAPES.get(Unit.INSTANCE, state.getValue(IEProperties.FACING_HORIZONTAL));
6292
}
6393

94+
@Override
95+
public ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult)
96+
{
97+
if(stack.is(Items.GLOW_INK_SAC))
98+
{
99+
if(!level.isClientSide())
100+
{
101+
player.awardStat(Stats.ITEM_USED.get(stack.getItem()));
102+
state = state.setValue(GLOWING, true);
103+
level.setBlock(pos, state, 3);
104+
level.gameEvent(GameEvent.BLOCK_CHANGE, pos, Context.of(player, state));
105+
stack.consume(1, player);
106+
}
107+
return ItemInteractionResult.SUCCESS;
108+
}
109+
return super.useItemOn(stack, state, level, pos, player, hand, hitResult);
110+
}
64111

65112
public enum WarningSignIcon implements StringRepresentable
66113
{

src/main/java/blusunrize/immersiveengineering/common/register/IEBlocks.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ private static void init()
580580
}
581581
for(WarningSignIcon icon : WarningSignIcon.values())
582582
WARNING_SIGNS.put(icon, new BlockEntry<>(
583-
"warning_sign_"+icon.getSerializedName(), METAL_PROPERTIES_NO_OVERLAY, blockProps -> new WarningSignBlock(icon, blockProps)
583+
"warning_sign_"+icon.getSerializedName(), WarningSignBlock.PROPERTIES, blockProps -> new WarningSignBlock(icon, blockProps)
584584
));
585585
}
586586
}

src/main/resources/assets/immersiveengineering/manual/en_us/warning_signs.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ Warning: Excessive signage ahead
33
Factories and warehouses are often grimy, unsafe, and riddled with chemicals and steam clouding the air.<br>
44
If reducing these hazards is inefficient, newly standardized Warning Signs can be used to warn of dangers instead.
55
<&sign_recipes>Warning signs can be crafted from any metal backing plate and yellow dye, to make sure the signs are visible on gloomy factory floors.<br>
6-
Signs can be placed on any vertical block face, but cannot be placed on the floor or on the ceiling.
6+
Signs can be placed on any vertical block face, but cannot be placed on the floor or on the ceiling.<br>
7+
Using a §2glow ink sack§r on a placed sign will make it emit a low amount of light.

0 commit comments

Comments
 (0)