mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 09:15:27 +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
+11
-28
@@ -1,23 +1,22 @@
|
||||
package art.arcane.iris.probe;
|
||||
|
||||
import art.arcane.volmlib.nativelib.common.block.GroundSurvival;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.ModdedBlockState;
|
||||
import art.arcane.iris.modded.ModdedGroundSurvival;
|
||||
import art.arcane.iris.platform.bukkit.ServerGroundSurvival;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/** Both platforms ask the server's own canSurvive rule where a plant may stand, against the real block tags. */
|
||||
public final class HeadlessGroundSurvivalTest {
|
||||
private static ServerGroundSurvival bukkit;
|
||||
|
||||
@BeforeClass
|
||||
public static void bootstrap() {
|
||||
public static void bootstrap() throws ReflectiveOperationException {
|
||||
HeadlessNativeBootstrap.initialize();
|
||||
bukkit = ServerGroundSurvival.connect(HeadlessGroundSurvivalTest.class.getClassLoader());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -45,7 +44,7 @@ public final class HeadlessGroundSurvivalTest {
|
||||
assertPlacement(true, Blocks.SUGAR_CANE, ground);
|
||||
}
|
||||
for (Block ground : new Block[]{Blocks.STONE, Blocks.GRAVEL, Blocks.CLAY, Blocks.DIRT_PATH,
|
||||
Blocks.FARMLAND, Blocks.AIR, Blocks.WATER}) {
|
||||
Blocks.FARMLAND, Blocks.WATER}) {
|
||||
assertPlacement(false, Blocks.SUGAR_CANE, ground);
|
||||
}
|
||||
}
|
||||
@@ -56,7 +55,7 @@ public final class HeadlessGroundSurvivalTest {
|
||||
for (Block ground : new Block[]{Blocks.CRIMSON_NYLIUM, Blocks.WARPED_NYLIUM, Blocks.SOUL_SOIL}) {
|
||||
assertPlacement(true, plant, ground);
|
||||
}
|
||||
for (Block ground : new Block[]{Blocks.NETHERRACK, Blocks.STONE, Blocks.GRAVEL, Blocks.AIR}) {
|
||||
for (Block ground : new Block[]{Blocks.NETHERRACK, Blocks.STONE, Blocks.GRAVEL}) {
|
||||
assertPlacement(false, plant, ground);
|
||||
}
|
||||
}
|
||||
@@ -68,26 +67,10 @@ public final class HeadlessGroundSurvivalTest {
|
||||
assertPlacement(true, Blocks.VINE, Blocks.SAND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deadBushStaysOffGrassAsPacksExpect() {
|
||||
assertTrue(moddedPlacement(Blocks.DEAD_BUSH, Blocks.SAND));
|
||||
assertFalse(moddedPlacement(Blocks.DEAD_BUSH, Blocks.GRASS_BLOCK));
|
||||
}
|
||||
|
||||
private static void assertPlacement(boolean expected, Block plant, Block ground) {
|
||||
String pair = plant + " on " + ground;
|
||||
assertEquals("modded " + pair, expected, moddedPlacement(plant, ground));
|
||||
if (!ground.defaultBlockState().isAir()) {
|
||||
assertEquals("bukkit native " + pair, expected,
|
||||
new GroundSurvival().canSurviveOn(plant.defaultBlockState(), ground.defaultBlockState()));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean moddedPlacement(Block plant, Block ground) {
|
||||
return wrap(plant).canPlaceOnto(wrap(ground));
|
||||
}
|
||||
|
||||
private static ModdedBlockState wrap(Block block) {
|
||||
return ModdedBlockState.deferred(block.defaultBlockState(), Map.of(), "iris:test");
|
||||
assertEquals("modded " + pair, expected,
|
||||
new ModdedGroundSurvival().canSurviveOn(plant.defaultBlockState(), ground.defaultBlockState()));
|
||||
assertEquals("bukkit " + pair, expected, bukkit.canSurviveOn(plant.defaultBlockState(), ground.defaultBlockState()));
|
||||
}
|
||||
}
|
||||
+7
-5
@@ -1,24 +1,26 @@
|
||||
package art.arcane.iris.platform.bukkit;
|
||||
|
||||
import art.arcane.iris.platform.bukkit.nms.INMS;
|
||||
import art.arcane.iris.generation.block.PlantPlacement;
|
||||
import art.arcane.iris.platform.bukkit.plugin.IrisService;
|
||||
import io.papermc.paper.event.server.ServerResourcesReloadedEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
/** Lets the server's placement rules apply again after a resource reload, which may have changed the block tags they read. */
|
||||
/** Lets the server's own rules decide where plants can stand, and asks them again after a resource reload. */
|
||||
public class BlockRulesSVC implements IrisService {
|
||||
private PlantPlacement.ServerRule previousRule;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
previousRule = PlantPlacement.bindServerRule(BukkitPlacementRules::canPlaceOnto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
PlantPlacement.restoreServerRule(previousRule);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onResourcesReloaded(ServerResourcesReloadedEvent event) {
|
||||
if (INMS.isBound()) {
|
||||
INMS.get().forgetBlockRules();
|
||||
}
|
||||
BukkitPlacementRules.forgetServerRules();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user