mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-02 19:22:08 +00:00
Let the server decide where plants can stand
- BukkitBlockState.canPlaceOnto asks the native canSurvive rule, Iris's own table only answers without a native binding - Keep dead bushes off grass and nothing on air - Forget remembered answers on server resource reloads and CraftEngine reloads - Stop the post stage from removing foliage the decorator already placed - Test placement on Bukkit and modded against real 26.3 block tags - Needs VolmLib piexelated/conch
This commit is contained in:
1 parent
1e04f61957
commit
202d9bbbd4
9 files changed
+155
-47
No files matched your search
+93
@@ -0,0 +1,93 @@
|
|||||||
|
package art.arcane.iris.probe;
|
||||||
|
|
||||||
|
import art.arcane.volmlib.nativelib.common.block.GroundSurvival;
|
||||||
|
import art.arcane.volmlib.nativelib.minecraft26_2.modded.ModdedBlockState;
|
||||||
|
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 {
|
||||||
|
@BeforeClass
|
||||||
|
public static void bootstrap() {
|
||||||
|
HeadlessNativeBootstrap.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void grassStandsOnSoilButNotOnStone() {
|
||||||
|
assertPlacement(true, Blocks.SHORT_GRASS, Blocks.GRASS_BLOCK);
|
||||||
|
assertPlacement(true, Blocks.SHORT_GRASS, Blocks.PODZOL);
|
||||||
|
assertPlacement(false, Blocks.SHORT_GRASS, Blocks.STONE);
|
||||||
|
assertPlacement(false, Blocks.POPPY, Blocks.STONE);
|
||||||
|
assertPlacement(false, Blocks.FERN, Blocks.OAK_LEAVES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void cactusNeedsSandOrCactus() {
|
||||||
|
for (Block ground : new Block[]{Blocks.CACTUS, Blocks.SAND, Blocks.RED_SAND}) {
|
||||||
|
assertPlacement(true, Blocks.CACTUS, ground);
|
||||||
|
}
|
||||||
|
assertPlacement(false, Blocks.CACTUS, Blocks.STONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sugarCaneNeedsItsSubstrate() {
|
||||||
|
for (Block ground : new Block[]{Blocks.SUGAR_CANE, Blocks.GRASS_BLOCK, Blocks.DIRT, Blocks.COARSE_DIRT,
|
||||||
|
Blocks.PODZOL, Blocks.MYCELIUM, Blocks.ROOTED_DIRT, Blocks.MOSS_BLOCK, Blocks.PALE_MOSS_BLOCK,
|
||||||
|
Blocks.MUD, Blocks.MUDDY_MANGROVE_ROOTS, Blocks.SAND, Blocks.RED_SAND, Blocks.SUSPICIOUS_SAND}) {
|
||||||
|
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}) {
|
||||||
|
assertPlacement(false, Blocks.SUGAR_CANE, ground);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void netherGroundCoverAcceptsNyliumAndSoulSoilButRejectsBarrenBlocks() {
|
||||||
|
for (Block plant : new Block[]{Blocks.CRIMSON_ROOTS, Blocks.WARPED_ROOTS, Blocks.NETHER_SPROUTS}) {
|
||||||
|
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}) {
|
||||||
|
assertPlacement(false, plant, ground);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void blocksThatRestOnNoGroundStillFit() {
|
||||||
|
assertPlacement(true, Blocks.WALL_TORCH, Blocks.STONE);
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -58,6 +58,7 @@ import art.arcane.iris.platform.agent.AttachSignal;
|
|||||||
import art.arcane.iris.platform.bootstrap.Bindings;
|
import art.arcane.iris.platform.bootstrap.Bindings;
|
||||||
import art.arcane.iris.platform.bootstrap.ServerProperties;
|
import art.arcane.iris.platform.bootstrap.ServerProperties;
|
||||||
import art.arcane.iris.platform.bootstrap.SlimJar;
|
import art.arcane.iris.platform.bootstrap.SlimJar;
|
||||||
|
import art.arcane.iris.platform.bukkit.BlockRulesSVC;
|
||||||
import art.arcane.iris.platform.bukkit.BoardSVC;
|
import art.arcane.iris.platform.bukkit.BoardSVC;
|
||||||
import art.arcane.iris.platform.bukkit.BukkitPlatform;
|
import art.arcane.iris.platform.bukkit.BukkitPlatform;
|
||||||
import art.arcane.iris.platform.bukkit.api.IrisApiEventSVC;
|
import art.arcane.iris.platform.bukkit.api.IrisApiEventSVC;
|
||||||
@@ -681,6 +682,7 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
|||||||
new GlobalCacheSVC(),
|
new GlobalCacheSVC(),
|
||||||
new LogFilterSVC(),
|
new LogFilterSVC(),
|
||||||
new ExternalDataSVC(),
|
new ExternalDataSVC(),
|
||||||
|
new BlockRulesSVC(),
|
||||||
new EditSVC(),
|
new EditSVC(),
|
||||||
new ObjectSVC(),
|
new ObjectSVC(),
|
||||||
new ObjectStudioSaveService(),
|
new ObjectStudioSaveService(),
|
||||||
|
|||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package art.arcane.iris.platform.bukkit;
|
||||||
|
|
||||||
|
import art.arcane.iris.platform.bukkit.nms.INMS;
|
||||||
|
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. */
|
||||||
|
public class BlockRulesSVC implements IrisService {
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onResourcesReloaded(ServerResourcesReloadedEvent event) {
|
||||||
|
if (INMS.isBound()) {
|
||||||
|
INMS.get().forgetBlockRules();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-37
@@ -102,46 +102,10 @@ public class ModdedBlockResolutionContractTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cactusPlacementRequiresNativeCactusSupport() {
|
public void cactusIsADecorant() {
|
||||||
assertTrue(NativeBlockProperties.canPlaceOnto(Blocks.CACTUS, Blocks.CACTUS));
|
|
||||||
assertTrue(NativeBlockProperties.canPlaceOnto(Blocks.CACTUS, Blocks.SAND));
|
|
||||||
assertTrue(NativeBlockProperties.canPlaceOnto(Blocks.CACTUS, Blocks.RED_SAND));
|
|
||||||
assertFalse(NativeBlockProperties.canPlaceOnto(Blocks.CACTUS, Blocks.STONE));
|
|
||||||
assertTrue(NativeBlockProperties.isDecorant(Blocks.CACTUS.defaultBlockState()));
|
assertTrue(NativeBlockProperties.isDecorant(Blocks.CACTUS.defaultBlockState()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void sugarCanePlacementRequiresNativeSubstrate() {
|
|
||||||
for (Block block : new Block[]{Blocks.SUGAR_CANE, Blocks.GRASS_BLOCK, Blocks.DIRT, Blocks.COARSE_DIRT,
|
|
||||||
Blocks.PODZOL, Blocks.MYCELIUM, Blocks.ROOTED_DIRT, Blocks.MOSS_BLOCK, Blocks.PALE_MOSS_BLOCK,
|
|
||||||
Blocks.MUD, Blocks.MUDDY_MANGROVE_ROOTS, Blocks.SAND, Blocks.RED_SAND, Blocks.SUSPICIOUS_SAND}) {
|
|
||||||
assertTrue(block.toString(), NativeBlockProperties.canPlaceOnto(Blocks.SUGAR_CANE, block));
|
|
||||||
}
|
|
||||||
for (Block block : new Block[]{Blocks.STONE, Blocks.GRAVEL, Blocks.CLAY, Blocks.DIRT_PATH,
|
|
||||||
Blocks.FARMLAND, Blocks.AIR, Blocks.WATER}) {
|
|
||||||
assertFalse(block.toString(), NativeBlockProperties.canPlaceOnto(Blocks.SUGAR_CANE, block));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void netherGroundCoverAcceptsNyliumAndSoulSoilButRejectsBarrenBlocks() {
|
|
||||||
for (Block plant : new Block[]{Blocks.CRIMSON_ROOTS, Blocks.WARPED_ROOTS, Blocks.NETHER_SPROUTS}) {
|
|
||||||
for (Block substrate : new Block[]{Blocks.CRIMSON_NYLIUM, Blocks.WARPED_NYLIUM,
|
|
||||||
Blocks.SOUL_SOIL, Blocks.GRASS_BLOCK, Blocks.COARSE_DIRT, Blocks.PODZOL}) {
|
|
||||||
assertTrue(plant + " on " + substrate, NativeBlockProperties.canPlaceOnto(plant, substrate));
|
|
||||||
}
|
|
||||||
for (Block substrate : new Block[]{Blocks.NETHERRACK, Blocks.SOUL_SAND,
|
|
||||||
Blocks.STONE, Blocks.GRAVEL, Blocks.AIR, Blocks.WATER}) {
|
|
||||||
assertFalse(plant + " on " + substrate, NativeBlockProperties.canPlaceOnto(plant, substrate));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Block fungus : new Block[]{Blocks.CRIMSON_FUNGUS, Blocks.WARPED_FUNGUS}) {
|
|
||||||
for (Block substrate : new Block[]{Blocks.CRIMSON_NYLIUM, Blocks.WARPED_NYLIUM, Blocks.SOUL_SOIL}) {
|
|
||||||
assertTrue(fungus + " on " + substrate, NativeBlockProperties.canPlaceOnto(fungus, substrate));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sulfurAndDripstoneTipsReceivePostLoadUpdates() {
|
public void sulfurAndDripstoneTipsReceivePostLoadUpdates() {
|
||||||
for (Block block : new Block[]{Blocks.SULFUR_SPIKE, Blocks.POINTED_DRIPSTONE}) {
|
for (Block block : new Block[]{Blocks.SULFUR_SPIKE, Blocks.POINTED_DRIPSTONE}) {
|
||||||
|
|||||||
+1
-1
@@ -812,7 +812,7 @@ project(':adapters:bukkit:nms:v26_3_R1') {
|
|||||||
'com.github.VolmitSoftware.VolmLib:native-minecraft26_2-sources:master-SNAPSHOT')
|
'com.github.VolmitSoftware.VolmLib:native-minecraft26_2-sources:master-SNAPSHOT')
|
||||||
List<String> headlessNativeTypes = ['ModdedBlockState', 'ModdedBiome', 'NativeBlockProperties', 'NativeBlockResolver',
|
List<String> headlessNativeTypes = ['ModdedBlockState', 'ModdedBiome', 'NativeBlockProperties', 'NativeBlockResolver',
|
||||||
'NativeBlockFaces', 'NativeStateRotator', 'NativeStateMerger',
|
'NativeBlockFaces', 'NativeStateRotator', 'NativeStateMerger',
|
||||||
'NativeRegistryAccess', 'ModdedItem', 'ModdedEntityType', 'NativeTileReader', 'NativeTileData']
|
'NativeRegistryAccess', 'ModdedItem', 'ModdedEntityType', 'NativeTileReader', 'NativeTileData', 'GroundSurvival']
|
||||||
TaskProvider<Sync> unpackHeadlessNativeSources = tasks.register('unpackHeadlessNativeSources', Sync) {
|
TaskProvider<Sync> unpackHeadlessNativeSources = tasks.register('unpackHeadlessNativeSources', Sync) {
|
||||||
dependsOn(headlessNativeSources)
|
dependsOn(headlessNativeSources)
|
||||||
inputs.property('nativeTypes', headlessNativeTypes)
|
inputs.property('nativeTypes', headlessNativeTypes)
|
||||||
|
|||||||
@@ -300,14 +300,6 @@ public class IrisPostModifier extends EngineAssignedModifier<NativeBlockState> {
|
|||||||
setPostBlock(x, h + 1, z, result, originX, originZ, currentData);
|
setPostBlock(x, h + 1, z, result, originX, originZ, currentData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (B.isFoliage(b) || IrisProceduralBlocks.materialKey(b).equals("minecraft:dead_bush")) {
|
|
||||||
NativeBlockState onto = getPostBlock(x, h, z, originX, originZ, currentData);
|
|
||||||
|
|
||||||
if (!B.canPlaceOnto(b, onto) && !B.isDecorant(b)) {
|
|
||||||
setPostBlock(x, h + 1, z, AIR.get(), originX, originZ, currentData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAir(int x, int y, int z, int originX, int originZ, Hunk<NativeBlockState> currentData) {
|
public boolean isAir(int x, int y, int z, int originX, int originZ, Hunk<NativeBlockState> currentData) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import art.arcane.iris.integration.ExternalDataSVC;
|
|||||||
import art.arcane.iris.generation.cache.Cache;
|
import art.arcane.iris.generation.cache.Cache;
|
||||||
import art.arcane.iris.generation.runtime.Engine;
|
import art.arcane.iris.generation.runtime.Engine;
|
||||||
import art.arcane.iris.platform.bukkit.BukkitBlockResolution;
|
import art.arcane.iris.platform.bukkit.BukkitBlockResolution;
|
||||||
|
import art.arcane.iris.platform.bukkit.nms.INMS;
|
||||||
import art.arcane.iris.spi.IrisLogging;
|
import art.arcane.iris.spi.IrisLogging;
|
||||||
import art.arcane.iris.spi.IrisServices;
|
import art.arcane.iris.spi.IrisServices;
|
||||||
import art.arcane.iris.generation.block.IrisCustomData;
|
import art.arcane.iris.generation.block.IrisCustomData;
|
||||||
@@ -83,6 +84,7 @@ public class CraftEngineDataProvider extends ExternalDataProvider implements Lis
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onReload(CraftEngineReloadEvent event) {
|
public void onReload(CraftEngineReloadEvent event) {
|
||||||
|
forgetServerBlockRules();
|
||||||
if (!updateContent()) {
|
if (!updateContent()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -92,6 +94,13 @@ 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
|
@Override
|
||||||
public @NotNull List<BlockProperty> getBlockProperties(@NotNull Identifier blockId) throws MissingResourceException {
|
public @NotNull List<BlockProperty> getBlockProperties(@NotNull Identifier blockId) throws MissingResourceException {
|
||||||
ImmutableBlockState blockState = findBlockState(blockId);
|
ImmutableBlockState blockState = findBlockState(blockId);
|
||||||
|
|||||||
@@ -429,7 +429,21 @@ public final class BukkitBlockState implements NativeBlockState {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPlaceOnto(NativeBlockState onto) {
|
public boolean canPlaceOnto(NativeBlockState onto) {
|
||||||
return BukkitBlockResolution.canPlaceOnto(data.getMaterial(), ((BlockData) onto.nativeHandle()).getMaterial());
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import art.arcane.volmlib.nativelib.terrain.NativeSectionVolume;
|
|||||||
import art.arcane.volmlib.nativelib.terrain.BukkitTerrainBuffer;
|
import art.arcane.volmlib.nativelib.terrain.BukkitTerrainBuffer;
|
||||||
|
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import art.arcane.iris.platform.bukkit.BukkitBlockResolution;
|
||||||
|
|
||||||
import art.arcane.volmlib.util.nbt.mca.NBTWorldSupport;
|
import art.arcane.volmlib.util.nbt.mca.NBTWorldSupport;
|
||||||
|
|
||||||
@@ -322,6 +323,15 @@ public interface INMSBinding extends NativeTerrainAccess {
|
|||||||
|
|
||||||
KMap<Material, List<BlockProperty>> getBlockProperties();
|
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) {
|
private void validateDimensionTypes(WorldCreator c) {
|
||||||
if (!(c.generator() instanceof PlatformChunkGenerator generator)) {
|
if (!(c.generator() instanceof PlatformChunkGenerator generator)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in new issue
Block a user