mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Keep the server placement check inside Iris
- Ask canSurvive from Iris itself instead of VolmLib, by runtime names on Bukkit and directly on modded - Platforms bind their rule through PlantPlacement, block states answer from the table when none is bound - Route sugar cane through the same check - Bind the rule on Bukkit enable and modded bootstrap, restore it on shutdown
This commit is contained in:
1 parent
202d9bbbd4
commit
60a9b5c7c4
15 files changed
+602
-73
No files matched your search
@@ -121,7 +121,7 @@ public class B {
|
||||
}
|
||||
|
||||
public static boolean canPlaceOnto(NativeBlockState mat, NativeBlockState onto) {
|
||||
return mat != null && onto != null && mat.canPlaceOnto(onto);
|
||||
return mat != null && onto != null && PlantPlacement.canPlaceOnto(mat, onto);
|
||||
}
|
||||
|
||||
public static boolean matches(NativeBlockState filter, NativeBlockState state) {
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.generation.block;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
|
||||
/**
|
||||
* Where a plant can stand. A platform that can ask the server's own placement rules binds them here; without one,
|
||||
* each block state answers from Iris's block table.
|
||||
*/
|
||||
public final class PlantPlacement {
|
||||
private static final String DEAD_BUSH = "minecraft:dead_bush";
|
||||
private static final String GRASS_BLOCK = "minecraft:grass_block";
|
||||
private static volatile ServerRule serverRule;
|
||||
|
||||
private PlantPlacement() {
|
||||
}
|
||||
|
||||
public interface ServerRule {
|
||||
boolean canPlaceOnto(NativeBlockState plant, NativeBlockState ground);
|
||||
}
|
||||
|
||||
public static synchronized ServerRule bindServerRule(ServerRule rule) {
|
||||
ServerRule previous = serverRule;
|
||||
serverRule = rule;
|
||||
return previous;
|
||||
}
|
||||
|
||||
public static synchronized void restoreServerRule(ServerRule previous) {
|
||||
serverRule = previous;
|
||||
}
|
||||
|
||||
static boolean canPlaceOnto(NativeBlockState plant, NativeBlockState ground) {
|
||||
ServerRule rule = serverRule;
|
||||
if (rule == null) {
|
||||
return plant.canPlaceOnto(ground);
|
||||
}
|
||||
if (ground.isAir() || isDeadBushOnGrass(plant, ground)) {
|
||||
return false;
|
||||
}
|
||||
return rule.canPlaceOnto(plant, ground);
|
||||
}
|
||||
|
||||
// Vanilla allows this, but packs mix dead bushes with other plants for their sandy patches, and blacklisting grass
|
||||
// on such a decorator would take the other plants off the grass too.
|
||||
private static boolean isDeadBushOnGrass(NativeBlockState plant, NativeBlockState ground) {
|
||||
return DEAD_BUSH.equals(plant.materialKey()) && GRASS_BLOCK.equals(ground.materialKey());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.generation.block.B;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
@@ -34,13 +35,13 @@ final class IrisSugarCane {
|
||||
int baseY = y - 1;
|
||||
NativeBlockState support = data.get(x, baseY, z);
|
||||
NativeBlockState target = data.get(x, y, z);
|
||||
if (support == null || !block.canPlaceOnto(support) || target != null && !target.isAir()) {
|
||||
if (support == null || !B.canPlaceOnto(block, support) || target != null && !target.isAir()) {
|
||||
return false;
|
||||
}
|
||||
while (isSugarCane(support) && baseY > 0) {
|
||||
support = data.get(x, --baseY, z);
|
||||
}
|
||||
if (support == null || isSugarCane(support) || !block.canPlaceOnto(support)) {
|
||||
if (support == null || isSugarCane(support) || !B.canPlaceOnto(block, support)) {
|
||||
return false;
|
||||
}
|
||||
for (int[] offset : NEIGHBORS) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import art.arcane.iris.integration.ExternalDataSVC;
|
||||
import art.arcane.iris.generation.cache.Cache;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.platform.bukkit.BukkitBlockResolution;
|
||||
import art.arcane.iris.platform.bukkit.nms.INMS;
|
||||
import art.arcane.iris.platform.bukkit.BukkitPlacementRules;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
import art.arcane.iris.generation.block.IrisCustomData;
|
||||
@@ -84,7 +84,7 @@ public class CraftEngineDataProvider extends ExternalDataProvider implements Lis
|
||||
|
||||
@EventHandler
|
||||
public void onReload(CraftEngineReloadEvent event) {
|
||||
forgetServerBlockRules();
|
||||
BukkitPlacementRules.forgetServerRules();
|
||||
if (!updateContent()) {
|
||||
return;
|
||||
}
|
||||
@@ -94,13 +94,6 @@ public class CraftEngineDataProvider extends ExternalDataProvider implements Lis
|
||||
}
|
||||
}
|
||||
|
||||
// Custom blocks carry their own placement rules, so answers about them can change with a reload.
|
||||
private static void forgetServerBlockRules() {
|
||||
if (INMS.isBound()) {
|
||||
INMS.get().forgetBlockRules();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<BlockProperty> getBlockProperties(@NotNull Identifier blockId) throws MissingResourceException {
|
||||
ImmutableBlockState blockState = findBlockState(blockId);
|
||||
|
||||
@@ -429,21 +429,7 @@ public final class BukkitBlockState implements NativeBlockState {
|
||||
|
||||
@Override
|
||||
public boolean canPlaceOnto(NativeBlockState onto) {
|
||||
BlockData ground = (BlockData) onto.nativeHandle();
|
||||
if (ground.getMaterial().isAir() || isDeadBushOnGrass(ground)) {
|
||||
return false;
|
||||
}
|
||||
return INMS.get().canSurviveOn(realBlockOf(data), realBlockOf(ground));
|
||||
}
|
||||
|
||||
// Vanilla allows this, but packs mix dead bushes with other plants for their sandy patches, and blacklisting grass
|
||||
// on such a decorator would take the other plants off the grass too.
|
||||
private boolean isDeadBushOnGrass(BlockData ground) {
|
||||
return data.getMaterial() == Material.DEAD_BUSH && ground.getMaterial() == Material.GRASS_BLOCK;
|
||||
}
|
||||
|
||||
private static BlockData realBlockOf(BlockData data) {
|
||||
return data instanceof IrisCustomData custom ? custom.getBase() : data;
|
||||
return BukkitBlockResolution.canPlaceOnto(data.getMaterial(), ((BlockData) onto.nativeHandle()).getMaterial());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.platform.bukkit;
|
||||
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/** Where a plant can stand on Bukkit: the server's own canSurvive rule, or Iris's block table when the server can't be asked. */
|
||||
public final class BukkitPlacementRules {
|
||||
private static final String CRAFT_BLOCK_DATA = "org.bukkit.craftbukkit.block.data.CraftBlockData";
|
||||
|
||||
private BukkitPlacementRules() {
|
||||
}
|
||||
|
||||
public static boolean canPlaceOnto(NativeBlockState plant, NativeBlockState ground) {
|
||||
ServerRules server = ServerConnection.RULES;
|
||||
if (server == null || !server.reaches(plant) || !server.reaches(ground)) {
|
||||
return plant.canPlaceOnto(ground);
|
||||
}
|
||||
return server.canPlaceOnto(plant, ground);
|
||||
}
|
||||
|
||||
/** Drops the remembered answers, which a resource or custom block reload may have changed. */
|
||||
public static void forgetServerRules() {
|
||||
ServerRules server = ServerConnection.RULES;
|
||||
if (server != null) {
|
||||
server.survival().forgetRules();
|
||||
}
|
||||
}
|
||||
|
||||
private record ServerRules(ServerGroundSurvival survival, Class<?> craftBlockData, Method serverState) {
|
||||
boolean reaches(NativeBlockState state) {
|
||||
return craftBlockData.isInstance(state.placementHandle());
|
||||
}
|
||||
|
||||
// Custom blocks are asked as the server block they place, so their own placement rules apply.
|
||||
boolean canPlaceOnto(NativeBlockState plant, NativeBlockState ground) {
|
||||
try {
|
||||
return survival.canSurviveOn(serverState.invoke(plant.placementHandle()), serverState.invoke(ground.placementHandle()));
|
||||
} catch (ReflectiveOperationException e) {
|
||||
return plant.canPlaceOnto(ground);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ServerConnection {
|
||||
static final ServerRules RULES = open();
|
||||
|
||||
private static ServerRules open() {
|
||||
ClassLoader loader = BukkitPlacementRules.class.getClassLoader();
|
||||
try {
|
||||
Class<?> craftBlockData = Class.forName(CRAFT_BLOCK_DATA, false, loader);
|
||||
return new ServerRules(ServerGroundSurvival.connect(loader), craftBlockData, craftBlockData.getMethod("getState"));
|
||||
} catch (ReflectiveOperationException | LinkageError e) {
|
||||
IrisLogging.debug("Placement uses Iris's block table, the server's rules are out of reach: " + e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.platform.bukkit;
|
||||
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Asks the server's own canSurvive rule whether a plant stands on a ground block, in a tiny level holding just the
|
||||
* two. Iris ships no server-mapped code for Bukkit, so the server's classes are reached by their runtime names.
|
||||
*/
|
||||
public final class ServerGroundSurvival {
|
||||
private static final int PLANT_Y = 64;
|
||||
private static final int MIN_BUILD_Y = -64;
|
||||
private static final int BUILD_HEIGHT = 384;
|
||||
// Crops need 8 or more and mushrooms less than 13. A chunk that is still generating has no light to ask for.
|
||||
private static final int LIGHT_EVERY_PLANT_ACCEPTS = 10;
|
||||
|
||||
private final ServerClasses server;
|
||||
private final Map<Object, Map<Object, Boolean>> survivesOn = new ConcurrentHashMap<>();
|
||||
private final Map<Object, Boolean> restsOnGround = new ConcurrentHashMap<>();
|
||||
|
||||
private ServerGroundSurvival(ServerClasses server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public static ServerGroundSurvival connect(ClassLoader loader) throws ReflectiveOperationException {
|
||||
return new ServerGroundSurvival(ServerClasses.load(loader));
|
||||
}
|
||||
|
||||
/** Whether the server lets the server block state {@code plant} stand on the server block state {@code ground}. */
|
||||
public boolean canSurviveOn(Object plant, Object ground) {
|
||||
return survivesOn.computeIfAbsent(plant, ignored -> new ConcurrentHashMap<>())
|
||||
.computeIfAbsent(ground, known -> decide(plant, known));
|
||||
}
|
||||
|
||||
public void forgetRules() {
|
||||
survivesOn.clear();
|
||||
restsOnGround.clear();
|
||||
}
|
||||
|
||||
private boolean decide(Object plant, Object ground) {
|
||||
try {
|
||||
return survives(plant, ground) || !restsOnGround(plant);
|
||||
} catch (ReflectiveOperationException | RuntimeException e) {
|
||||
IrisLogging.warn("Could not ask whether " + plant + " survives on " + ground + ", letting it stand: " + rootCause(e));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Wall and ceiling blocks fail on every ground, which says nothing about the ground they were decorated onto.
|
||||
private boolean restsOnGround(Object plant) throws ReflectiveOperationException {
|
||||
Boolean known = restsOnGround.get(plant);
|
||||
if (known != null) {
|
||||
return known;
|
||||
}
|
||||
boolean rests = survivesOnSomeGround(plant);
|
||||
restsOnGround.put(plant, rests);
|
||||
return rests;
|
||||
}
|
||||
|
||||
private boolean survivesOnSomeGround(Object plant) throws ReflectiveOperationException {
|
||||
for (Object block : server.blocks()) {
|
||||
if (survives(plant, server.defaultBlockState().invoke(block))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean survives(Object plant, Object ground) throws ReflectiveOperationException {
|
||||
return (boolean) server.canSurvive().invoke(plant, levelAround(plant, ground), server.plantPos());
|
||||
}
|
||||
|
||||
// A proxy, since LevelReader gains abstract methods with every release and Paper's chunk system adds its own.
|
||||
private Object levelAround(Object plant, Object ground) {
|
||||
InvocationHandler answers = (proxy, method, args) -> answer(proxy, method, args, plant, ground);
|
||||
return Proxy.newProxyInstance(server.levelReader().getClassLoader(), new Class<?>[]{server.levelReader()}, answers);
|
||||
}
|
||||
|
||||
private Object answer(Object proxy, Method method, Object[] args, Object plant, Object ground) throws Throwable {
|
||||
switch (method.getName()) {
|
||||
case "getBlockState", "getBlockStateIfLoaded" -> {
|
||||
return stateAt(args[0], plant, ground);
|
||||
}
|
||||
case "getFluidState", "getFluidIfLoaded" -> {
|
||||
return server.getFluidState().invoke(stateAt(args[0], plant, ground));
|
||||
}
|
||||
case "getRawBrightness", "getMaxLocalRawBrightness", "getBrightness" -> {
|
||||
return LIGHT_EVERY_PLANT_ACCEPTS;
|
||||
}
|
||||
case "getBlockEntity" -> {
|
||||
return null;
|
||||
}
|
||||
case "getMinY", "getMinBuildHeight" -> {
|
||||
return MIN_BUILD_Y;
|
||||
}
|
||||
case "getHeight" -> {
|
||||
if (args == null) {
|
||||
return BUILD_HEIGHT;
|
||||
}
|
||||
}
|
||||
case "isClientSide" -> {
|
||||
return false;
|
||||
}
|
||||
case "hashCode" -> {
|
||||
return System.identityHashCode(proxy);
|
||||
}
|
||||
case "equals" -> {
|
||||
return proxy == args[0];
|
||||
}
|
||||
case "toString" -> {
|
||||
return "ground survival level";
|
||||
}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
|
||||
if (method.isDefault()) {
|
||||
return InvocationHandler.invokeDefault(proxy, method, args);
|
||||
}
|
||||
throw new IllegalStateException("Ground survival level can't answer " + method.getName());
|
||||
}
|
||||
|
||||
// Water beside the ground for sugar cane and air beside the plant for cactus, so only the ground can refuse.
|
||||
private Object stateAt(Object pos, Object plant, Object ground) throws ReflectiveOperationException {
|
||||
if (pos.equals(server.plantPos())) {
|
||||
return plant;
|
||||
}
|
||||
if (pos.equals(server.groundPos())) {
|
||||
return ground;
|
||||
}
|
||||
return (int) server.getY().invoke(pos) == PLANT_Y - 1 ? server.water() : server.air();
|
||||
}
|
||||
|
||||
private static String rootCause(Throwable failure) {
|
||||
Throwable cause = failure instanceof InvocationTargetException invocation && invocation.getCause() != null
|
||||
? invocation.getCause() : failure;
|
||||
return cause.getClass().getSimpleName() + ": " + cause.getMessage();
|
||||
}
|
||||
|
||||
private record ServerClasses(Class<?> levelReader, Method canSurvive, Method getFluidState, Method getY,
|
||||
Method defaultBlockState, Object plantPos, Object groundPos, Object water, Object air,
|
||||
Iterable<?> blocks) {
|
||||
static ServerClasses load(ClassLoader loader) throws ReflectiveOperationException {
|
||||
Class<?> blockState = Class.forName("net.minecraft.world.level.block.state.BlockState", false, loader);
|
||||
Class<?> levelReader = Class.forName("net.minecraft.world.level.LevelReader", false, loader);
|
||||
Class<?> blockPos = Class.forName("net.minecraft.core.BlockPos", false, loader);
|
||||
Class<?> block = Class.forName("net.minecraft.world.level.block.Block", false, loader);
|
||||
Class<?> blocks = Class.forName("net.minecraft.world.level.block.Blocks", true, loader);
|
||||
Class<?> registries = Class.forName("net.minecraft.core.registries.BuiltInRegistries", true, loader);
|
||||
Method defaultBlockState = block.getMethod("defaultBlockState");
|
||||
Constructor<?> position = blockPos.getConstructor(int.class, int.class, int.class);
|
||||
return new ServerClasses(levelReader,
|
||||
blockState.getMethod("canSurvive", levelReader, blockPos),
|
||||
blockState.getMethod("getFluidState"),
|
||||
blockPos.getMethod("getY"),
|
||||
defaultBlockState,
|
||||
position.newInstance(0, PLANT_Y, 0),
|
||||
position.newInstance(0, PLANT_Y - 1, 0),
|
||||
defaultBlockState.invoke(blocks.getField("WATER").get(null)),
|
||||
defaultBlockState.invoke(blocks.getField("AIR").get(null)),
|
||||
(Iterable<?>) registries.getField("BLOCK").get(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import art.arcane.volmlib.nativelib.terrain.NativeSectionVolume;
|
||||
import art.arcane.volmlib.nativelib.terrain.BukkitTerrainBuffer;
|
||||
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import art.arcane.iris.platform.bukkit.BukkitBlockResolution;
|
||||
|
||||
import art.arcane.volmlib.util.nbt.mca.NBTWorldSupport;
|
||||
|
||||
@@ -323,15 +322,6 @@ public interface INMSBinding extends NativeTerrainAccess {
|
||||
|
||||
KMap<Material, List<BlockProperty>> getBlockProperties();
|
||||
|
||||
/** Whether the server lets {@code plant} stand on {@code ground}; without a native binding, Iris's own table of plants and grounds answers. */
|
||||
default boolean canSurviveOn(BlockData plant, BlockData ground) {
|
||||
return BukkitBlockResolution.canPlaceOnto(plant.getMaterial(), ground.getMaterial());
|
||||
}
|
||||
|
||||
/** Drops answers remembered from the server's block rules, which a resource reload may have changed. */
|
||||
default void forgetBlockRules() {
|
||||
}
|
||||
|
||||
private void validateDimensionTypes(WorldCreator c) {
|
||||
if (!(c.generator() instanceof PlatformChunkGenerator generator)) {
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package art.arcane.iris.generation.block;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class PlantPlacementTest {
|
||||
private final PlantPlacement.ServerRule previous = PlantPlacement.bindServerRule(null);
|
||||
|
||||
@After
|
||||
public void restoreRule() {
|
||||
PlantPlacement.restoreServerRule(previous);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withoutAServerRuleTheBlockTableAnswers() {
|
||||
NativeBlockState plant = block("minecraft:short_grass");
|
||||
NativeBlockState ground = block("iris:grass_block");
|
||||
when(plant.canPlaceOnto(ground)).thenReturn(true);
|
||||
|
||||
assertTrue(B.canPlaceOnto(plant, ground));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aBoundServerRuleOverridesTheBlockTable() {
|
||||
NativeBlockState plant = block("minecraft:short_grass");
|
||||
NativeBlockState ground = block("iris:grass_block");
|
||||
PlantPlacement.bindServerRule((p, g) -> p == plant && g == ground);
|
||||
|
||||
assertTrue(B.canPlaceOnto(plant, ground));
|
||||
assertFalse(B.canPlaceOnto(plant, block("minecraft:stone")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nothingStandsOnAirAndDeadBushesStayOffGrass() {
|
||||
PlantPlacement.bindServerRule((p, g) -> true);
|
||||
NativeBlockState air = block("minecraft:air");
|
||||
when(air.isAir()).thenReturn(true);
|
||||
|
||||
assertFalse(B.canPlaceOnto(block("minecraft:short_grass"), air));
|
||||
assertFalse(B.canPlaceOnto(block("minecraft:dead_bush"), block("minecraft:grass_block")));
|
||||
assertTrue(B.canPlaceOnto(block("minecraft:dead_bush"), block("minecraft:sand")));
|
||||
}
|
||||
|
||||
private static NativeBlockState block(String key) {
|
||||
NativeBlockState state = mock(NativeBlockState.class);
|
||||
when(state.materialKey()).thenReturn(key);
|
||||
return state;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user