package net.mcreator.lemegeton.block; import org.checkerframework.checker.units.qual.s; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.common.util.ForgeSoundType; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.Dist; import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.material.PushReaction; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.SimpleWaterloggedBlock; import net.minecraft.world.level.block.Rotation; import net.minecraft.world.level.block.Mirror; import net.minecraft.world.level.block.HorizontalDirectionalBlock; import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.Level; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.ItemStack; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.MenuProvider; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionHand; import net.minecraft.world.Containers; import net.minecraft.util.RandomSource; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerLevel; import net.minecraft.resources.ResourceLocation; import net.minecraft.network.chat.Component; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.core.Direction; import net.minecraft.core.BlockPos; import net.minecraft.client.Minecraft; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.state.BooleanProperty; import net.minecraft.Util.math.BlockPos; import net.minecraft.world.IBlockReader; import net.mcreator.lemegeton.world.inventory.DecantationTableGUIMenu; import net.mcreator.lemegeton.procedures.DecantationVisualsProcedure; import net.mcreator.lemegeton.procedures.DecantationLogicProcedure; import net.mcreator.lemegeton.block.entity.DecantationTableBlockEntity; import java.util.List; import java.util.Collections; import io.netty.buffer.Unpooled; public class DecantationTableBlock extends Block implements SimpleWaterloggedBlock, EntityBlock { public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public static final BooleanProperty HAS_FUEL = BooleanProperty.create("has_fuel"); public static final IntegerProperty LIGHT_LEVEL = IntegerProperty.create("light_level",0,13); public DecantationTableBlock() { super(BlockBehaviour.Properties.of(Material.STONE) .sound(new ForgeSoundType(1.0f, 1.0f, () -> ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("block.stone.break")), () -> ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("block.glass.step")), () -> ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("block.stone.place")), () -> ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("block.stone.hit")), () -> ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("block.stone.fall")))) .strength(1f, 10f).noOcclusion().isRedstoneConductor((bs, br, bp) -> false)); this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, false)); this.setDefaultState(this.getStateContainer().getBaseState().with(HAS_FUEL, false).with(LIGHT_LEVEL, 0)); } @Override public int getLightValue(BlockState, IBlockReader world, BlockPos pos) { return state.get(HAS_FUEL) ? state.get(LIGHT_LEVEL) : 0; } @Override protected void fillStateContainer(stateContainer.Builder builder) { builder.add(HAS_FUEL, LIGHT_LEVEL); } @Override public void appendHoverText(ItemStack itemstack, BlockGetter world, List list, TooltipFlag flag) { super.appendHoverText(itemstack, world, list, flag); list.add(Component.literal("\"Its actually destilation!\"")); } @Override public boolean propagatesSkylightDown(BlockState state, BlockGetter reader, BlockPos pos) { return state.getFluidState().isEmpty(); } @Override public VoxelShape getVisualShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { return Shapes.empty(); } @Override public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) { return switch (state.getValue(FACING)) { default -> box(0, 0, 0, 16, 10, 16); case NORTH -> box(0, 0, 0, 16, 10, 16); case EAST -> box(0, 0, 0, 16, 10, 16); case WEST -> box(0, 0, 0, 16, 10, 16); }; } @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(FACING, WATERLOGGED); } @Override public BlockState getStateForPlacement(BlockPlaceContext context) { boolean flag = context.getLevel().getFluidState(context.getClickedPos()).getType() == Fluids.WATER; return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()).setValue(WATERLOGGED, flag); } public BlockState rotate(BlockState state, Rotation rot) { return state.setValue(FACING, rot.rotate(state.getValue(FACING))); } public BlockState mirror(BlockState state, Mirror mirrorIn) { return state.rotate(mirrorIn.getRotation(state.getValue(FACING))); } @Override public FluidState getFluidState(BlockState state) { return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); } @Override public BlockState updateShape(BlockState state, Direction facing, BlockState facingState, LevelAccessor world, BlockPos currentPos, BlockPos facingPos) { if (state.getValue(WATERLOGGED)) { world.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); } return super.updateShape(state, facing, facingState, world, currentPos, facingPos); } @Override public PushReaction getPistonPushReaction(BlockState state) { return PushReaction.BLOCK; } @Override public List getDrops(BlockState state, LootContext.Builder builder) { List dropsOriginal = super.getDrops(state, builder); if (!dropsOriginal.isEmpty()) return dropsOriginal; return Collections.singletonList(new ItemStack(this, 1)); } @Override public void onPlace(BlockState blockstate, Level world, BlockPos pos, BlockState oldState, boolean moving) { super.onPlace(blockstate, world, pos, oldState, moving); world.scheduleTick(pos, this, 1); } @Override public void tick(BlockState blockstate, ServerLevel world, BlockPos pos, RandomSource random) { super.tick(blockstate, world, pos, random); int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); DecantationLogicProcedure.execute(world, x, y, z); world.scheduleTick(pos, this, 1); } @OnlyIn(Dist.CLIENT) @Override public void animateTick(BlockState blockstate, Level world, BlockPos pos, RandomSource random) { super.animateTick(blockstate, world, pos, random); Player entity = Minecraft.getInstance().player; int x = pos.getX(); int y = pos.getY(); int z = pos.getZ(); DecantationVisualsProcedure.execute(world, x, y, z); } @Override public InteractionResult use(BlockState blockstate, Level world, BlockPos pos, Player entity, InteractionHand hand, BlockHitResult hit) { super.use(blockstate, world, pos, entity, hand, hit); if (entity instanceof ServerPlayer player) { NetworkHooks.openScreen(player, new MenuProvider() { @Override public Component getDisplayName() { return Component.literal("Decantation Table"); } @Override public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) { return new DecantationTableGUIMenu(id, inventory, new FriendlyByteBuf(Unpooled.buffer()).writeBlockPos(pos)); } }, pos); } return InteractionResult.SUCCESS; } @Override public MenuProvider getMenuProvider(BlockState state, Level worldIn, BlockPos pos) { BlockEntity tileEntity = worldIn.getBlockEntity(pos); return tileEntity instanceof MenuProvider menuProvider ? menuProvider : null; } @Override public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { return new DecantationTableBlockEntity(pos, state); } @Override public boolean triggerEvent(BlockState state, Level world, BlockPos pos, int eventID, int eventParam) { super.triggerEvent(state, world, pos, eventID, eventParam); BlockEntity blockEntity = world.getBlockEntity(pos); return blockEntity == null ? false : blockEntity.triggerEvent(eventID, eventParam); } @Override public void onRemove(BlockState state, Level world, BlockPos pos, BlockState newState, boolean isMoving) { if (state.getBlock() != newState.getBlock()) { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof DecantationTableBlockEntity be) { Containers.dropContents(world, pos, be); world.updateNeighbourForOutputSignal(pos, this); } super.onRemove(state, world, pos, newState, isMoving); } } @Override public boolean hasAnalogOutputSignal(BlockState state) { return true; } @Override public int getAnalogOutputSignal(BlockState blockState, Level world, BlockPos pos) { BlockEntity tileentity = world.getBlockEntity(pos); if (tileentity instanceof DecantationTableBlockEntity be) return AbstractContainerMenu.getRedstoneSignalFromContainer(be); else return 0; } }