A pool... how cool!

- Pool walls are now working with Polymer
This commit is contained in:
Martin Prokoph
2024-07-29 13:59:46 +02:00
parent efb772ffd8
commit 1ad6529f09
3 changed files with 72 additions and 1 deletions

View File

@@ -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);
}
}

View File

@@ -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();
}
}

View File

@@ -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);
}
}