diff --git a/src/main/java/io/github/cottonmc/templates/block/TemplateBlock.java b/src/main/java/io/github/cottonmc/templates/block/TemplateBlock.java index f7b8913..acffc6d 100644 --- a/src/main/java/io/github/cottonmc/templates/block/TemplateBlock.java +++ b/src/main/java/io/github/cottonmc/templates/block/TemplateBlock.java @@ -1,7 +1,7 @@ package io.github.cottonmc.templates.block; import io.github.cottonmc.templates.Templates; -import io.github.cottonmc.templates.block.entity.TemplateBlockEntity; +import io.github.cottonmc.templates.block.entity.TemplateEntity; import io.github.cottonmc.templates.util.StateContainer; import net.minecraft.block.Block; import net.minecraft.block.BlockEntityProvider; @@ -31,8 +31,8 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider @Override public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - if (world.isClient || !(world.getBlockEntity(pos) instanceof TemplateBlockEntity)) return true; - TemplateBlockEntity be = (TemplateBlockEntity) world.getBlockEntity(pos); + if (world.isClient || !(world.getBlockEntity(pos) instanceof TemplateEntity)) return true; + TemplateEntity be = (TemplateEntity) world.getBlockEntity(pos); ItemStack stack = player.getStackInHand(hand); if (stack.getItem() instanceof BlockItem) { Block block = ((BlockItem)stack.getItem()).getBlock(); @@ -69,8 +69,8 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider public void onBlockRemoved(BlockState state, World world, BlockPos pos, BlockState newState, boolean bool) { if (newState.getBlock() == Templates.SLOPE) return; BlockEntity be = world.getBlockEntity(pos); - if (be instanceof TemplateBlockEntity) { - TemplateBlockEntity template = (TemplateBlockEntity)be; + if (be instanceof TemplateEntity) { + TemplateEntity template = (TemplateEntity)be; if (template.getRenderedState().getBlock() != Blocks.AIR) { ItemStack stack = new ItemStack(template.getRenderedState().getBlock()); ItemEntity entity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), stack); @@ -93,8 +93,8 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider @Override public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos posFrom, boolean bool) { BlockEntity be = world.getBlockEntity(pos); - if (be instanceof TemplateBlockEntity) { - TemplateBlockEntity template = (TemplateBlockEntity)be; + if (be instanceof TemplateEntity) { + TemplateEntity template = (TemplateEntity)be; BlockState beState = template.getRenderedState(); world.setBlockState(pos, state.with(LIGHT, template.hasGlowstone()? 15 : beState.getLuminance()).with(REDSTONE, template.hasRedstone() || beState.emitsRedstonePower())); } @@ -113,8 +113,8 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider @Override public int getWeakRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction dir) { BlockEntity be = view.getBlockEntity(pos); - if (be instanceof TemplateBlockEntity) { - TemplateBlockEntity template = (TemplateBlockEntity)be; + if (be instanceof TemplateEntity) { + TemplateEntity template = (TemplateEntity)be; if (template.hasRedstone()) return 15; BlockState beState = template.getRenderedState(); return beState.getWeakRedstonePower(view, pos, dir); @@ -125,8 +125,8 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider @Override public int getStrongRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction dir) { BlockEntity be = view.getBlockEntity(pos); - if (be instanceof TemplateBlockEntity) { - TemplateBlockEntity template = (TemplateBlockEntity)be; + if (be instanceof TemplateEntity) { + TemplateEntity template = (TemplateEntity)be; if (template.hasRedstone()) return 15; BlockState beState = template.getRenderedState(); return beState.getStrongRedstonePower(view, pos, dir); @@ -137,7 +137,13 @@ public abstract class TemplateBlock extends Block implements BlockEntityProvider @Override public BlockState getContainedState(World world, BlockPos pos) { BlockEntity be = world.getBlockEntity(pos); - if (be instanceof TemplateBlockEntity) return ((TemplateBlockEntity)be).getRenderedState(); + if (be instanceof TemplateEntity) return ((TemplateEntity)be).getRenderedState(); return Blocks.AIR.getDefaultState(); } + + @Override + public void setContainedState(World world, BlockPos pos, BlockState state) { + BlockEntity be = world.getBlockEntity(pos); + if (be instanceof TemplateEntity) ((TemplateEntity)be).setRenderedState(state); + } } diff --git a/src/main/java/io/github/cottonmc/templates/block/entity/SlopeEntity.java b/src/main/java/io/github/cottonmc/templates/block/entity/SlopeEntity.java index 6f2380f..9d669a9 100644 --- a/src/main/java/io/github/cottonmc/templates/block/entity/SlopeEntity.java +++ b/src/main/java/io/github/cottonmc/templates/block/entity/SlopeEntity.java @@ -2,7 +2,7 @@ package io.github.cottonmc.templates.block.entity; import io.github.cottonmc.templates.Templates; -public class SlopeEntity extends TemplateBlockEntity { +public class SlopeEntity extends TemplateEntity { public SlopeEntity() { super(Templates.SLOPE_ENTITY, Templates.SLOPE); } diff --git a/src/main/java/io/github/cottonmc/templates/block/entity/TemplateBlockEntity.java b/src/main/java/io/github/cottonmc/templates/block/entity/TemplateEntity.java similarity index 92% rename from src/main/java/io/github/cottonmc/templates/block/entity/TemplateBlockEntity.java rename to src/main/java/io/github/cottonmc/templates/block/entity/TemplateEntity.java index 2e235b7..45d54a5 100644 --- a/src/main/java/io/github/cottonmc/templates/block/entity/TemplateBlockEntity.java +++ b/src/main/java/io/github/cottonmc/templates/block/entity/TemplateEntity.java @@ -13,13 +13,13 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.math.Direction; -public abstract class TemplateBlockEntity extends BlockEntity implements BlockEntityClientSerializable, RenderAttachmentBlockEntity { +public abstract class TemplateEntity extends BlockEntity implements BlockEntityClientSerializable, RenderAttachmentBlockEntity { protected BlockState renderedState = Blocks.AIR.getDefaultState(); protected boolean glowstone = false; protected boolean redstone = false; private Block baseBlock; - public TemplateBlockEntity(BlockEntityType type, Block baseBlock) { + public TemplateEntity(BlockEntityType type, Block baseBlock) { super(type); this.baseBlock = baseBlock; } diff --git a/src/main/java/io/github/cottonmc/templates/model/TemplateModelVariantProvider.java b/src/main/java/io/github/cottonmc/templates/model/TemplateModelVariantProvider.java index c6934b1..6bcf308 100644 --- a/src/main/java/io/github/cottonmc/templates/model/TemplateModelVariantProvider.java +++ b/src/main/java/io/github/cottonmc/templates/model/TemplateModelVariantProvider.java @@ -23,7 +23,7 @@ public class TemplateModelVariantProvider implements ModelVariantProvider { return variants.get(modelId); } - public void registerTemplateModels(Block block, BlockState itemState, Function model) { + public void registerTemplateModels(Block block, BlockState itemState, Function model) { for (BlockState state : block.getStateFactory().getStates()) { variants.put(BlockModels.getModelId(state), (SimpleUnbakedModel)() -> model.apply(state)); } diff --git a/src/main/java/io/github/cottonmc/templates/util/StateContainer.java b/src/main/java/io/github/cottonmc/templates/util/StateContainer.java index 56237bf..1b9acd9 100644 --- a/src/main/java/io/github/cottonmc/templates/util/StateContainer.java +++ b/src/main/java/io/github/cottonmc/templates/util/StateContainer.java @@ -6,4 +6,5 @@ import net.minecraft.world.World; public interface StateContainer { BlockState getContainedState(World world, BlockPos pos); + void setContainedState(World world, BlockPos pos, BlockState state); }