From 1ad6529f095b85bdccc379cc4571d0cd7125d66d Mon Sep 17 00:00:00 2001 From: Martin Prokoph Date: Mon, 29 Jul 2024 13:59:46 +0200 Subject: [PATCH] A pool... how cool! - Pool walls are now working with Polymer --- .../motschen/decorative/block/PoolWall.java | 16 +++++- .../decorative/polymer/PolymerSupport.java | 2 + .../model/ItemDisplayPoolWallModel.java | 55 +++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/main/java/eu/midnightdust/motschen/decorative/polymer/model/ItemDisplayPoolWallModel.java diff --git a/src/main/java/eu/midnightdust/motschen/decorative/block/PoolWall.java b/src/main/java/eu/midnightdust/motschen/decorative/block/PoolWall.java index 8407269..6f25932 100755 --- a/src/main/java/eu/midnightdust/motschen/decorative/block/PoolWall.java +++ b/src/main/java/eu/midnightdust/motschen/decorative/block/PoolWall.java @@ -3,7 +3,9 @@ package eu.midnightdust.motschen.decorative.block; import com.mojang.serialization.MapCodec; import eu.midnightdust.motschen.decorative.DecorativeMain; import eu.midnightdust.motschen.decorative.blockstates.PoolShape; +import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplayPoolWallModel; import eu.pb4.factorytools.api.block.FactoryBlock; +import eu.pb4.polymer.virtualentity.api.ElementHolder; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -15,6 +17,8 @@ import net.minecraft.block.Waterloggable; import net.minecraft.fluid.FluidState; import net.minecraft.fluid.Fluids; import net.minecraft.item.ItemPlacementContext; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.BlockSoundGroup; import net.minecraft.state.StateManager; import net.minecraft.state.property.BooleanProperty; @@ -26,6 +30,7 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.BlockView; +import org.jetbrains.annotations.Nullable; public class PoolWall extends HorizontalFacingBlock implements Waterloggable, FactoryBlock { public static final DirectionProperty FACING = DoorBlock.FACING; @@ -149,6 +154,15 @@ public class PoolWall extends HorizontalFacingBlock implements Waterloggable, Fa // Polymer @Override public BlockState getPolymerBlockState(BlockState state) { - return Blocks.STRUCTURE_VOID.getDefaultState(); + return state.get(WATERLOGGED) ? Blocks.WATER.getDefaultState() : Blocks.BARRIER.getDefaultState(); + } + @Override + public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) { + return Blocks.WHITE_CONCRETE.getDefaultState(); + } + + @Override + public @Nullable ElementHolder createElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) { + return new ItemDisplayPoolWallModel(initialBlockState); } } diff --git a/src/main/java/eu/midnightdust/motschen/decorative/polymer/PolymerSupport.java b/src/main/java/eu/midnightdust/motschen/decorative/polymer/PolymerSupport.java index c8cf87b..68746cc 100644 --- a/src/main/java/eu/midnightdust/motschen/decorative/polymer/PolymerSupport.java +++ b/src/main/java/eu/midnightdust/motschen/decorative/polymer/PolymerSupport.java @@ -8,6 +8,7 @@ import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplayDigitalClock import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplayDirectionalModel; import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplayDoubleLampModel; import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplayLampModel; +import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplayPoolWallModel; public class PolymerSupport { public static void init() { @@ -19,5 +20,6 @@ public class PolymerSupport { ItemDisplayDoubleLampModel.initModels(); ItemDisplayLampModel.initModels(); ItemDisplayDirectionalModel.initModels(); + ItemDisplayPoolWallModel.initModels(); } } diff --git a/src/main/java/eu/midnightdust/motschen/decorative/polymer/model/ItemDisplayPoolWallModel.java b/src/main/java/eu/midnightdust/motschen/decorative/polymer/model/ItemDisplayPoolWallModel.java new file mode 100644 index 0000000..ae145e5 --- /dev/null +++ b/src/main/java/eu/midnightdust/motschen/decorative/polymer/model/ItemDisplayPoolWallModel.java @@ -0,0 +1,55 @@ +package eu.midnightdust.motschen.decorative.polymer.model; + +import eu.midnightdust.motschen.decorative.block.PoolWall; +import eu.midnightdust.motschen.decorative.blockstates.PoolShape; +import eu.midnightdust.motschen.decorative.config.DecorativeConfig; +import eu.pb4.factorytools.api.resourcepack.BaseItemProvider; +import eu.pb4.factorytools.api.virtualentity.BlockModel; +import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil; +import eu.pb4.polymer.virtualentity.api.attachment.BlockAwareAttachment; +import eu.pb4.polymer.virtualentity.api.attachment.HolderAttachment; +import eu.pb4.polymer.virtualentity.api.elements.ItemDisplayElement; +import net.minecraft.block.BlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.RotationAxis; +import org.joml.Vector3f; + +import static eu.midnightdust.motschen.decorative.DecorativeMain.id; + +public class ItemDisplayPoolWallModel extends BlockModel { + private final ItemDisplayElement main; + public static ItemStack REGULAR; + public static ItemStack CORNER; + + public static void initModels() { + REGULAR = BaseItemProvider.requestModel(id("block/pool_wall")); + CORNER = BaseItemProvider.requestModel(id("block/pool_wall_corner")); + } + + public ItemDisplayPoolWallModel(BlockState state) { + this.main = ItemDisplayElementUtil.createSimple(getModel(state)); + this.main.setDisplaySize(1, 1); + this.main.setScale(new Vector3f(2)); + this.main.setRightRotation(RotationAxis.POSITIVE_Y.rotationDegrees(getRotation(state))); + this.main.setViewRange((DecorativeConfig.viewDistance / 100f)); + this.addElement(this.main); + } + + @Override + public void notifyUpdate(HolderAttachment.UpdateType updateType) { + if (updateType == BlockAwareAttachment.BLOCK_STATE_UPDATE) { + var state = this.blockState(); + this.main.setRightRotation(RotationAxis.POSITIVE_Y.rotationDegrees(getRotation(state))); + this.main.setItem(getModel(state)); + + this.tick(); + } + } + public ItemStack getModel(BlockState state) { + return state.get(PoolWall.SHAPE) == PoolShape.STRAIGHT ? REGULAR : CORNER; + } + public float getRotation(BlockState state) { + return state.get(PoolWall.FACING).getHorizontal() * -90 + (state.get(PoolWall.SHAPE) == PoolShape.INNER_RIGHT ? 0 : 90); + } +} +