Skip to content

Commit 07327cf

Browse files
committed
Add support for dynamic map colors. Rename TileEntity to BlockEntity.
1 parent 60d6f3a commit 07327cf

25 files changed

+236
-160
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ org.gradle.daemon=false
55

66
#version info
77
minecraft_version=1.20.1
8-
mod_version=1.1.8.0
8+
mod_version=1.1.9.1

src/main/java/platinpython/rgbblocks/block/RGBBlock.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import net.minecraft.world.level.block.EntityBlock;
1111
import net.minecraft.world.level.block.entity.BlockEntity;
1212
import net.minecraft.world.level.block.state.BlockState;
13+
import net.minecraft.world.level.material.MapColor;
1314
import net.minecraft.world.phys.HitResult;
1415
import org.jspecify.annotations.Nullable;
1516

@@ -25,23 +26,28 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
2526

2627
@Override
2728
public void setPlacedBy(
28-
Level worldIn,
29+
Level level,
2930
BlockPos pos,
3031
BlockState state,
3132
@Nullable LivingEntity placer,
3233
ItemStack stack
3334
) {
34-
RGBBlockUtils.setPlacedBy(worldIn, pos, state, placer, stack);
35+
RGBBlockUtils.setPlacedBy(level, pos, stack);
3536
}
3637

3738
@Override
3839
public ItemStack getCloneItemStack(
3940
BlockState state,
4041
HitResult target,
41-
BlockGetter world,
42+
BlockGetter level,
4243
BlockPos pos,
4344
Player player
4445
) {
45-
return RGBBlockUtils.getCloneItemStack(state, target, world, pos, player);
46+
return RGBBlockUtils.getCloneItemStack(state, level, pos);
47+
}
48+
49+
@Override
50+
public MapColor getMapColor(BlockState state, BlockGetter level, BlockPos pos, MapColor defaultColor) {
51+
return RGBBlockUtils.getMapColor(level, pos, defaultColor);
4652
}
4753
}

src/main/java/platinpython/rgbblocks/block/RGBBlockUtils.java

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import net.minecraft.core.BlockPos;
44
import net.minecraft.core.Direction;
55
import net.minecraft.nbt.CompoundTag;
6-
import net.minecraft.world.entity.LivingEntity;
7-
import net.minecraft.world.entity.player.Player;
86
import net.minecraft.world.item.ItemStack;
97
import net.minecraft.world.level.BlockGetter;
108
import net.minecraft.world.level.Level;
@@ -16,63 +14,54 @@
1614
import net.minecraft.world.level.block.state.properties.Half;
1715
import net.minecraft.world.level.block.state.properties.SlabType;
1816
import net.minecraft.world.level.block.state.properties.StairsShape;
19-
import net.minecraft.world.phys.HitResult;
17+
import net.minecraft.world.level.material.MapColor;
2018
import org.jspecify.annotations.Nullable;
21-
import platinpython.rgbblocks.tileentity.RGBTileEntity;
19+
import platinpython.rgbblocks.block.entity.RGBBlockEntity;
2220
import platinpython.rgbblocks.util.Color;
23-
import platinpython.rgbblocks.util.registries.TileEntityRegistry;
21+
import platinpython.rgbblocks.util.registries.BlockEntityRegistry;
2422

2523
public final class RGBBlockUtils {
2624
public static @Nullable BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
27-
return TileEntityRegistry.RGB.get().create(pos, state);
25+
return BlockEntityRegistry.RGB.get().create(pos, state);
2826
}
2927

30-
public static void setPlacedBy(
31-
Level worldIn,
32-
BlockPos pos,
33-
BlockState state,
34-
@Nullable LivingEntity placer,
35-
ItemStack stack
36-
) {
37-
BlockEntity tileEntity = worldIn.getBlockEntity(pos);
38-
if (stack.hasTag() && tileEntity instanceof RGBTileEntity rgbTileEntity) {
28+
public static void setPlacedBy(Level level, BlockPos pos, ItemStack stack) {
29+
BlockEntity blockEntity = level.getBlockEntity(pos);
30+
if (stack.hasTag() && blockEntity instanceof RGBBlockEntity rgbBlockEntity) {
3931
// noinspection DataFlowIssue
40-
rgbTileEntity.setColor(stack.getTag().getInt("color"));
32+
rgbBlockEntity.setColor(stack.getTag().getInt("color"));
4133
}
4234
}
4335

44-
public static ItemStack getCloneItemStack(
45-
BlockState state,
46-
HitResult target,
47-
BlockGetter world,
48-
BlockPos pos,
49-
Player player
50-
) {
36+
public static ItemStack getCloneItemStack(BlockState state, BlockGetter level, BlockPos pos) {
5137
ItemStack stack = new ItemStack(state.getBlock().asItem());
52-
BlockEntity tileEntity = world.getBlockEntity(pos);
53-
if (tileEntity instanceof RGBTileEntity) {
38+
if (level.getBlockEntity(pos) instanceof RGBBlockEntity blockEntity) {
5439
CompoundTag tag = new CompoundTag();
55-
tag.putInt("color", ((RGBTileEntity) tileEntity).getColor());
40+
tag.putInt("color", blockEntity.getColor());
5641
stack.setTag(tag);
5742
}
5843
return stack;
5944
}
6045

61-
public static float @Nullable [] getBeaconColorMultiplier(
62-
BlockState state,
63-
LevelReader world,
64-
BlockPos pos,
65-
BlockPos beaconPos
66-
) {
67-
BlockEntity tileEntity = world.getBlockEntity(pos);
68-
if (tileEntity instanceof RGBTileEntity rgbTileEntity) {
69-
return new Color(rgbTileEntity.getColor()).getRGBColorComponents();
46+
public static MapColor getMapColor(BlockGetter level, BlockPos pos, MapColor defaultColor) {
47+
BlockEntity blockEntity = level.getBlockEntity(pos);
48+
if (blockEntity instanceof RGBBlockEntity rgbBlockEntity) {
49+
return rgbBlockEntity.getMapColor();
50+
} else {
51+
return defaultColor;
52+
}
53+
}
54+
55+
public static float @Nullable [] getBeaconColorMultiplier(LevelReader level, BlockPos pos) {
56+
BlockEntity blockEntity = level.getBlockEntity(pos);
57+
if (blockEntity instanceof RGBBlockEntity rgbBlockEntity) {
58+
return new Color(rgbBlockEntity.getColor()).getRGBColorComponents();
7059
} else {
7160
return null;
7261
}
7362
}
7463

75-
public static boolean blockSkipRendering(BlockState state, BlockState adjacentBlockState, Direction side) {
64+
public static boolean blockSkipRendering(BlockState adjacentBlockState, Direction side) {
7665
if (adjacentBlockState.getBlock() instanceof RGBBlock) {
7766
return true;
7867
} else if (adjacentBlockState.getBlock() instanceof RGBGlassSlabBlock) {

src/main/java/platinpython/rgbblocks/block/RGBCarpetBlock.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.minecraft.world.level.block.WoolCarpetBlock;
1313
import net.minecraft.world.level.block.entity.BlockEntity;
1414
import net.minecraft.world.level.block.state.BlockState;
15+
import net.minecraft.world.level.material.MapColor;
1516
import net.minecraft.world.phys.HitResult;
1617
import org.jspecify.annotations.Nullable;
1718

@@ -27,23 +28,28 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
2728

2829
@Override
2930
public void setPlacedBy(
30-
Level worldIn,
31+
Level level,
3132
BlockPos pos,
3233
BlockState state,
3334
@Nullable LivingEntity placer,
3435
ItemStack stack
3536
) {
36-
RGBBlockUtils.setPlacedBy(worldIn, pos, state, placer, stack);
37+
RGBBlockUtils.setPlacedBy(level, pos, stack);
3738
}
3839

3940
@Override
4041
public ItemStack getCloneItemStack(
4142
BlockState state,
4243
HitResult target,
43-
BlockGetter world,
44+
BlockGetter level,
4445
BlockPos pos,
4546
Player player
4647
) {
47-
return RGBBlockUtils.getCloneItemStack(state, target, world, pos, player);
48+
return RGBBlockUtils.getCloneItemStack(state, level, pos);
49+
}
50+
51+
@Override
52+
public MapColor getMapColor(BlockState state, BlockGetter level, BlockPos pos, MapColor defaultColor) {
53+
return RGBBlockUtils.getMapColor(level, pos, defaultColor);
4854
}
4955
}

src/main/java/platinpython/rgbblocks/block/RGBConcretePowderBlock.java

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
import net.minecraft.world.level.block.entity.BlockEntity;
1616
import net.minecraft.world.level.block.state.BlockState;
1717
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
18+
import net.minecraft.world.level.material.MapColor;
1819
import net.minecraft.world.phys.HitResult;
1920
import org.jspecify.annotations.Nullable;
21+
import platinpython.rgbblocks.block.entity.RGBBlockEntity;
2022
import platinpython.rgbblocks.entity.RGBFallingBlockEntity;
21-
import platinpython.rgbblocks.tileentity.RGBTileEntity;
2223
import platinpython.rgbblocks.util.registries.BlockRegistry;
2324

2425
public class RGBConcretePowderBlock extends ConcretePowderBlock implements EntityBlock {
@@ -33,74 +34,79 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
3334

3435
@Override
3536
public void setPlacedBy(
36-
Level worldIn,
37+
Level level,
3738
BlockPos pos,
3839
BlockState state,
3940
@Nullable LivingEntity placer,
4041
ItemStack stack
4142
) {
42-
RGBBlockUtils.setPlacedBy(worldIn, pos, state, placer, stack);
43+
RGBBlockUtils.setPlacedBy(level, pos, stack);
4344
}
4445

4546
@Override
4647
public ItemStack getCloneItemStack(
4748
BlockState state,
4849
HitResult target,
49-
BlockGetter world,
50+
BlockGetter level,
5051
BlockPos pos,
5152
Player player
5253
) {
53-
return RGBBlockUtils.getCloneItemStack(state, target, world, pos, player);
54+
return RGBBlockUtils.getCloneItemStack(state, level, pos);
5455
}
5556

5657
@Override
57-
public void tick(BlockState state, ServerLevel worldIn, BlockPos pos, RandomSource rand) {
58-
if (worldIn.isEmptyBlock(pos.below()) || isFree(worldIn.getBlockState(pos.below())) && pos.getY() >= 0) {
59-
BlockEntity tileEntity = worldIn.getBlockEntity(pos);
58+
public MapColor getMapColor(BlockState state, BlockGetter level, BlockPos pos, MapColor defaultColor) {
59+
return RGBBlockUtils.getMapColor(level, pos, defaultColor);
60+
}
61+
62+
@Override
63+
public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource rand) {
64+
if (level.isEmptyBlock(pos.below()) || isFree(level.getBlockState(pos.below())) && pos.getY() >= 0) {
65+
BlockEntity blockEntity = level.getBlockEntity(pos);
6066
RGBFallingBlockEntity fallingBlockEntity = new RGBFallingBlockEntity(
61-
worldIn, (double) pos.getX() + 0.5D, pos.getY(), (double) pos.getZ() + 0.5D,
67+
level, (double) pos.getX() + 0.5D, pos.getY(), (double) pos.getZ() + 0.5D,
6268
state.hasProperty(BlockStateProperties.WATERLOGGED)
6369
? state.setValue(BlockStateProperties.WATERLOGGED, Boolean.FALSE)
6470
: state,
65-
tileEntity instanceof RGBTileEntity ? ((RGBTileEntity) tileEntity).getColor() : 0
71+
blockEntity instanceof RGBBlockEntity rgbBlockEntity ? rgbBlockEntity.getColor() : 0
6672
);
67-
worldIn.setBlock(pos, state.getFluidState().createLegacyBlock(), 3);
68-
worldIn.addFreshEntity(fallingBlockEntity);
73+
level.setBlock(pos, state.getFluidState().createLegacyBlock(), 3);
74+
level.addFreshEntity(fallingBlockEntity);
6975
this.falling(fallingBlockEntity);
7076
}
7177
}
7278

7379
@SuppressWarnings("deprecation")
7480
@Override
75-
public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
81+
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
7682
if (!state.is(BlockRegistry.RGB_CONCRETE_POWDER.get()) && !newState.is(BlockRegistry.RGB_CONCRETE.get())) {
7783
if (state.hasBlockEntity() && (!state.is(newState.getBlock()) || !newState.hasBlockEntity())) {
78-
worldIn.removeBlockEntity(pos);
84+
level.removeBlockEntity(pos);
7985
}
8086
}
8187
}
8288

8389
@Override
8490
public void onLand(
85-
Level world,
91+
Level level,
8692
BlockPos blockPos,
8793
BlockState blockBlockState,
8894
BlockState entityBlockState,
8995
FallingBlockEntity entity
9096
) {
91-
super.onLand(world, blockPos, blockBlockState, entityBlockState, entity);
92-
if (entity instanceof RGBFallingBlockEntity) {
93-
RGBTileEntity tileEntity = new RGBTileEntity(blockPos, entityBlockState);
94-
tileEntity.setColor(((RGBFallingBlockEntity) entity).getColor());
95-
world.setBlockEntity(tileEntity);
97+
super.onLand(level, blockPos, blockBlockState, entityBlockState, entity);
98+
if (entity instanceof RGBFallingBlockEntity rgbFallingBlockEntity) {
99+
RGBBlockEntity blockEntity = new RGBBlockEntity(blockPos, entityBlockState);
100+
blockEntity.setColor(rgbFallingBlockEntity.getColor());
101+
level.setBlockEntity(blockEntity);
96102
}
97103
}
98104

99105
@Override
100106
public int getDustColor(BlockState blockState, BlockGetter blockReader, BlockPos blockPos) {
101-
BlockEntity tileEntity = blockReader.getBlockEntity(blockPos.above());
102-
if (tileEntity instanceof RGBTileEntity rgbTileEntity) {
103-
return rgbTileEntity.getColor();
107+
BlockEntity blockEntity = blockReader.getBlockEntity(blockPos.above());
108+
if (blockEntity instanceof RGBBlockEntity rgbBlockEntity) {
109+
return rgbBlockEntity.getColor();
104110
}
105111
return super.getDustColor(blockState, blockReader, blockPos);
106112
}

src/main/java/platinpython/rgbblocks/block/RGBGlassBlock.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ public RGBGlassBlock() {
1616
@Override
1717
public float @Nullable [] getBeaconColorMultiplier(
1818
BlockState state,
19-
LevelReader world,
19+
LevelReader level,
2020
BlockPos pos,
2121
BlockPos beaconPos
2222
) {
23-
return RGBBlockUtils.getBeaconColorMultiplier(state, world, pos, beaconPos);
23+
return RGBBlockUtils.getBeaconColorMultiplier(level, pos);
2424
}
2525

2626
@SuppressWarnings("deprecation")
2727
@Override
2828
public boolean skipRendering(BlockState state, BlockState adjacentBlockState, Direction side) {
29-
return RGBBlockUtils.blockSkipRendering(state, adjacentBlockState, side);
29+
return RGBBlockUtils.blockSkipRendering(adjacentBlockState, side);
3030
}
3131

3232
@SuppressWarnings("deprecation")
3333
@Override
34-
public float getShadeBrightness(BlockState state, BlockGetter worldIn, BlockPos pos) {
34+
public float getShadeBrightness(BlockState state, BlockGetter level, BlockPos pos) {
3535
return 1.0F;
3636
}
3737

src/main/java/platinpython/rgbblocks/block/RGBGlassPaneBlock.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ public RGBGlassPaneBlock() {
1616
@Override
1717
public float @Nullable [] getBeaconColorMultiplier(
1818
BlockState state,
19-
LevelReader world,
19+
LevelReader level,
2020
BlockPos pos,
2121
BlockPos beaconPos
2222
) {
23-
return RGBBlockUtils.getBeaconColorMultiplier(state, world, pos, beaconPos);
23+
return RGBBlockUtils.getBeaconColorMultiplier(level, pos);
2424
}
2525

2626
@Override
2727
public boolean skipRendering(BlockState state, BlockState adjacentBlockState, Direction side) {
28-
return RGBBlockUtils.blockSkipRendering(state, adjacentBlockState, side);
28+
return RGBBlockUtils.blockSkipRendering(adjacentBlockState, side);
2929
}
3030

3131
@SuppressWarnings("deprecation")
3232
@Override
33-
public float getShadeBrightness(BlockState state, BlockGetter worldIn, BlockPos pos) {
33+
public float getShadeBrightness(BlockState state, BlockGetter level, BlockPos pos) {
3434
return 1.0F;
3535
}
3636

src/main/java/platinpython/rgbblocks/block/RGBGlassSlabBlock.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public RGBGlassSlabBlock() {
1616
@Override
1717
public float @Nullable [] getBeaconColorMultiplier(
1818
BlockState state,
19-
LevelReader world,
19+
LevelReader level,
2020
BlockPos pos,
2121
BlockPos beaconPos
2222
) {
23-
return RGBBlockUtils.getBeaconColorMultiplier(state, world, pos, beaconPos);
23+
return RGBBlockUtils.getBeaconColorMultiplier(level, pos);
2424
}
2525

2626
@SuppressWarnings("deprecation")
@@ -31,7 +31,7 @@ public boolean skipRendering(BlockState state, BlockState adjacentBlockState, Di
3131

3232
@SuppressWarnings("deprecation")
3333
@Override
34-
public float getShadeBrightness(BlockState state, BlockGetter worldIn, BlockPos pos) {
34+
public float getShadeBrightness(BlockState state, BlockGetter level, BlockPos pos) {
3535
return 1.0F;
3636
}
3737

0 commit comments

Comments
 (0)