From 4e0094a79b8a720c2f7b7cc11648c945da54cda7 Mon Sep 17 00:00:00 2001 From: FirstMegaGame4 <84094287+FirstMegaGame4@users.noreply.github.com> Date: Sat, 14 Oct 2023 17:52:18 +0200 Subject: [PATCH] Change CustomLilyPadBlock --- .../library/blocks/CustomLilyPadBlock.java | 85 +++++++++++++------ 1 file changed, 58 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/mmodding/mmodding_lib/library/blocks/CustomLilyPadBlock.java b/src/main/java/com/mmodding/mmodding_lib/library/blocks/CustomLilyPadBlock.java index a20fe68..b8fc31c 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/blocks/CustomLilyPadBlock.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/blocks/CustomLilyPadBlock.java @@ -1,48 +1,79 @@ package com.mmodding.mmodding_lib.library.blocks; -import net.minecraft.block.LilyPadBlock; +import net.minecraft.block.BlockState; +import net.minecraft.block.Material; +import net.minecraft.block.PlantBlock; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; import org.quiltmc.qsl.item.setting.api.QuiltItemSettings; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.BiPredicate; -public class CustomLilyPadBlock extends LilyPadBlock implements BlockRegistrable, BlockWithItem { +public class CustomLilyPadBlock extends PlantBlock implements BlockRegistrable, BlockWithItem { - private final AtomicBoolean registered = new AtomicBoolean(false); + private final AtomicBoolean registered = new AtomicBoolean(false); - private BlockItem item = null; + private BlockItem item = null; - public CustomLilyPadBlock(Settings settings) { - this(settings, false); - } + private final BiPredicate placementConditions; - public CustomLilyPadBlock(Settings settings, boolean hasItem) { - this(settings, hasItem, (ItemGroup) null); - } + public CustomLilyPadBlock(Settings settings) { + this(settings, false); + } + + public CustomLilyPadBlock(Settings settings, boolean hasItem) { + this(settings, hasItem, (ItemGroup) null); + } public CustomLilyPadBlock(Settings settings, boolean hasItem, ItemGroup itemGroup) { this(settings, hasItem, itemGroup != null ? new QuiltItemSettings().group(itemGroup) : new QuiltItemSettings()); } - public CustomLilyPadBlock(Settings settings, boolean hasItem, Item.Settings itemSettings) { - super(settings); - if (hasItem) this.item = new BlockItem(this, itemSettings); - } + public CustomLilyPadBlock(Settings settings, boolean hasItem, Item.Settings itemSettings) { + this((fluid, floor) -> fluid.isOf(Fluids.WATER) || floor.getMaterial().equals(Material.ICE), settings, hasItem, itemSettings); + } + + public CustomLilyPadBlock(BiPredicate placementConditions, Settings settings) { + this(placementConditions, settings, false); + } + + public CustomLilyPadBlock(BiPredicate placementConditions, Settings settings, boolean hasItem) { + this(placementConditions, settings, hasItem, (ItemGroup) null); + } + + public CustomLilyPadBlock(BiPredicate placementConditions, Settings settings, boolean hasItem, ItemGroup itemGroup) { + this(placementConditions, settings, hasItem, itemGroup != null ? new QuiltItemSettings().group(itemGroup) : new QuiltItemSettings()); + } + + public CustomLilyPadBlock(BiPredicate placementConditions, Settings settings, boolean hasItem, Item.Settings itemSettings) { + super(settings); + if (hasItem) this.item = new BlockItem(this, itemSettings); + this.placementConditions = placementConditions; + } + + @Override + protected boolean canPlantOnTop(BlockState floor, BlockView world, BlockPos pos) { + return this.placementConditions.test(world.getFluidState(pos), floor) && world.getFluidState(pos.up()).isEmpty(); + } @Override - public BlockItem getItem() { - return this.item; - } - - @Override - public boolean isNotRegistered() { - return !this.registered.get(); - } - - @Override - public void setRegistered() { - this.registered.set(true); - } + public BlockItem getItem() { + return this.item; + } + + @Override + public boolean isNotRegistered() { + return !this.registered.get(); + } + + @Override + public void setRegistered() { + this.registered.set(true); + } }