From 241682c95b56f47cbd09f79dd77c6ad8ee4489c5 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Wed, 20 Nov 2024 17:56:18 +0100 Subject: Init --- .../nea/funnyteleporters/ColouredChestBlock.java | 113 +++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/main/java/moe/nea/funnyteleporters/ColouredChestBlock.java (limited to 'src/main/java/moe/nea/funnyteleporters/ColouredChestBlock.java') diff --git a/src/main/java/moe/nea/funnyteleporters/ColouredChestBlock.java b/src/main/java/moe/nea/funnyteleporters/ColouredChestBlock.java new file mode 100644 index 0000000..eb68f95 --- /dev/null +++ b/src/main/java/moe/nea/funnyteleporters/ColouredChestBlock.java @@ -0,0 +1,113 @@ +package moe.nea.funnyteleporters; + +import com.mojang.serialization.MapCodec; +import eu.pb4.polymer.core.api.block.PolymerBlock; +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.AbstractChestBlock; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.ChestBlock; +import net.minecraft.block.DoubleBlockProperties; +import net.minecraft.block.EnderChestBlock; +import net.minecraft.block.FacingBlock; +import net.minecraft.block.HorizontalFacingBlock; +import net.minecraft.block.Waterloggable; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.ChestBlockEntity; +import net.minecraft.entity.ai.pathing.NavigationType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.Properties; +import net.minecraft.state.property.Property; +import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; + +public class ColouredChestBlock extends AbstractChestBlock implements PolymerBlock, Waterloggable { + static Property FACING = HorizontalFacingBlock.FACING; + static Property WATERLOGGED = Properties.WATERLOGGED; + + public ColouredChestBlock(Settings settings) { + super(settings, () -> FunnyRegistry.COLOURED_CHEST_ENTITY); + setDefaultState(getStateManager() + .getDefaultState() + .with(FACING, Direction.NORTH) + .with(WATERLOGGED, false)); + } + + @Override + public BlockState getPolymerBlockState(BlockState blockState) { + return Blocks.CHEST.getStateWithProperties(blockState); + } + + @Override + public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { + return new ColouredChestBlockEntity(pos, state); + } + + @Override + public BlockState getPlacementState(ItemPlacementContext ctx) { + return getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite()).with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER); + } + + @Override + protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { + // TODO: create a ui or something to configure frequency + player.sendMessage(Text.literal("Ender Chest geöffnet" + player)); + return super.onUse(state, world, pos, player, hit); + } + + @Override + protected BlockState rotate(BlockState state, BlockRotation rotation) { + return state.with(FACING, rotation.rotate(state.get(FACING))); + } + + @Override + protected BlockState mirror(BlockState state, BlockMirror mirror) { + return state.rotate(mirror.getRotation(state.get(FACING))); + } + + @Override + protected void appendProperties(StateManager.Builder builder) { + builder.add(FACING, WATERLOGGED); + } + + @Override + protected FluidState getFluidState(BlockState state) { + return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); + } + + @Override + protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { + if (state.get(WATERLOGGED)) + world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); + return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos); + } + + @Override + protected boolean canPathfindThrough(BlockState state, NavigationType type) { + return false; + } + + static final MapCodec CODEC = createCodec(ColouredChestBlock::new); + + @Override + protected MapCodec> getCodec() { + return CODEC; + } + + @Override + public DoubleBlockProperties.PropertySource getBlockEntitySource(BlockState state, World world, BlockPos pos, boolean ignoreBlocked) { + return DoubleBlockProperties.PropertyRetriever::getFallback; + } +} -- cgit