From 36783f0a395e8ead19502312a01c3e74619ef4dd Mon Sep 17 00:00:00 2001 From: sciwhiz12 Date: Sat, 23 Dec 2023 23:43:09 +0800 Subject: [PATCH] Remove glazed terracotta as farmland for `DESERT` plant type (#416) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #306 by removing glazed terracotta as acceptable farmland for the `DESERT` plant type. Also includes a related fix to expand `DESERT` plant types to be plantable on both uncolored/raw terracotta and stained terracotta, to match with the plantability of dead bushes on both. (This only really matters for modded plants, because dead bushes extend `BushBlock` and therefore have their `mayPlaceOn` method called to allow placing on stained terracotta anyway.) --- .../world/level/block/Block.java.patch | 2 +- .../neoforge/debug/block/BlockTests.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/patches/net/minecraft/world/level/block/Block.java.patch b/patches/net/minecraft/world/level/block/Block.java.patch index de4a188587..bff22f19b2 100644 --- a/patches/net/minecraft/world/level/block/Block.java.patch +++ b/patches/net/minecraft/world/level/block/Block.java.patch @@ -150,7 +150,7 @@ + return true; + + if (net.neoforged.neoforge.common.PlantType.DESERT.equals(type)) { -+ return state.is(BlockTags.SAND) || this == Blocks.TERRACOTTA || this instanceof GlazedTerracottaBlock; ++ return state.is(BlockTags.SAND) || state.is(BlockTags.TERRACOTTA); + } else if (net.neoforged.neoforge.common.PlantType.NETHER.equals(type)) { + return this == Blocks.SOUL_SAND; + } else if (net.neoforged.neoforge.common.PlantType.CROP.equals(type)) { diff --git a/tests/src/main/java/net/neoforged/neoforge/debug/block/BlockTests.java b/tests/src/main/java/net/neoforged/neoforge/debug/block/BlockTests.java index b93cee978b..40de055e23 100644 --- a/tests/src/main/java/net/neoforged/neoforge/debug/block/BlockTests.java +++ b/tests/src/main/java/net/neoforged/neoforge/debug/block/BlockTests.java @@ -7,6 +7,7 @@ import java.util.Optional; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.gametest.framework.GameTest; import net.minecraft.network.protocol.game.ClientboundSoundPacket; import net.minecraft.resources.ResourceLocation; @@ -17,6 +18,8 @@ import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.level.GameType; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelReader; @@ -32,6 +35,7 @@ import net.neoforged.testframework.annotation.ForEachTest; import net.neoforged.testframework.annotation.TestHolder; import net.neoforged.testframework.gametest.EmptyTemplate; +import net.neoforged.testframework.gametest.ExtendedGameTestHelper; import net.neoforged.testframework.registration.RegistrationHelper; import org.jetbrains.annotations.Nullable; @@ -96,4 +100,30 @@ public Optional getRespawnPosition(BlockState state, EntityType type, L 1, 3, 2)) .thenSucceed()); } + + @GameTest + @EmptyTemplate(floor = true) + @TestHolder(description = { + "Dead bushes should be placeable on regular terracotta (colored or not), but not on glazed terracotta", + "(neoforged/NeoForge#306)" + }) + static void deadBushTerracottaTest(final ExtendedGameTestHelper helper) { + final BlockPos farmlandBlock = new BlockPos(1, 1, 1); + helper.startSequence(() -> helper.makeTickingMockServerPlayerInCorner(GameType.SURVIVAL)) + .thenExecute(() -> helper.setBlock(farmlandBlock, Blocks.TERRACOTTA)) + .thenExecute(player -> helper.useBlock(farmlandBlock, player, new ItemStack(Items.DEAD_BUSH), Direction.UP)) + .thenExecute(() -> helper.assertBlockPresent(Blocks.DEAD_BUSH, farmlandBlock.above())) + + .thenExecute(() -> helper.setBlock(farmlandBlock.above(), Blocks.AIR)) + .thenExecute(() -> helper.setBlock(farmlandBlock, Blocks.WHITE_TERRACOTTA)) + .thenExecute(player -> helper.useBlock(farmlandBlock, player, new ItemStack(Items.DEAD_BUSH), Direction.UP)) + .thenExecute(() -> helper.assertBlockPresent(Blocks.DEAD_BUSH, farmlandBlock.above())) + + .thenExecute(() -> helper.setBlock(farmlandBlock.above(), Blocks.AIR)) + .thenExecute(() -> helper.setBlock(farmlandBlock, Blocks.WHITE_GLAZED_TERRACOTTA)) + .thenExecute(player -> helper.useBlock(farmlandBlock, player, new ItemStack(Items.DEAD_BUSH), Direction.UP)) + .thenExecute(() -> helper.assertBlockNotPresent(Blocks.DEAD_BUSH, farmlandBlock.above())) + + .thenSucceed(); + } }