mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Let the server's placement rules reset on reload and stop post from removing foliage
The remembered "plant survives on ground" answers went stale when the server or CraftEngine reloaded resources, so they are now cleared on both events. The post-stage foliage removal second-guessed the server rule and deleted foliage that is not a decoration, so it is gone. Pins: none moved; the only changed test is SurfaceSmoothingTest, which now expects the fern to stay. v3: af333cc93
This commit is contained in:
1 parent
0b5aa54df7
commit
23bed57728
8 files changed
+69
-16
No files matched your search
+4
@@ -34,6 +34,10 @@ final class GroundSurvival {
|
||||
}
|
||||
}
|
||||
|
||||
void forgetRules() {
|
||||
restsOnGround.clear();
|
||||
}
|
||||
|
||||
// Wall and ceiling blocks fail on every ground, which says nothing about the ground they were decorated onto.
|
||||
private boolean restsOnGround(BlockState plant) {
|
||||
return restsOnGround.computeIfAbsent(plant, this::survivesOnSomeGround);
|
||||
|
||||
+5
@@ -1665,6 +1665,11 @@ public class NMSBinding implements INMSBinding {
|
||||
return groundSurvival.canSurviveOn(((CraftBlockData) plant).getState(), ((CraftBlockData) ground).getState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forgetBlockRules() {
|
||||
groundSurvival.forgetRules();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KMap<Material, List<BlockProperty>> getBlockProperties() {
|
||||
KMap<Material, List<BlockProperty>> states = new KMap<>();
|
||||
|
||||
@@ -58,6 +58,7 @@ import art.arcane.iris.core.nms.INMS;
|
||||
import art.arcane.iris.core.gui.BukkitGuiHost;
|
||||
import art.arcane.iris.core.gui.GuiHost;
|
||||
import art.arcane.iris.core.gui.PregeneratorJob;
|
||||
import art.arcane.iris.core.service.BlockRulesSVC;
|
||||
import art.arcane.iris.core.service.BoardSVC;
|
||||
import art.arcane.iris.core.service.CommandSVC;
|
||||
import art.arcane.iris.core.service.DatapackStructureScopeSVC;
|
||||
@@ -635,7 +636,7 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
// Explicit, ordered service list: the previous reflective jar scan gave hash-ordered
|
||||
// enable/disable and paid a full-jar class sweep at boot. Infrastructure first,
|
||||
// engine/world services next, commands last.
|
||||
List<IrisService> orderedServices = List.of(
|
||||
List<IrisService> orderedServices = new ArrayList<>(List.of(
|
||||
new PreservationSVC(),
|
||||
new GlobalCacheSVC(),
|
||||
new LogFilterSVC(),
|
||||
@@ -658,7 +659,11 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
new IrisProtocolService(),
|
||||
new IrisApiEventSVC(),
|
||||
new CommandSVC()
|
||||
);
|
||||
));
|
||||
if (BlockRulesSVC.isSupported()) {
|
||||
int commandServiceIndex = orderedServices.size() - 1;
|
||||
orderedServices.add(commandServiceIndex, new BlockRulesSVC());
|
||||
}
|
||||
for (IrisService i : orderedServices) {
|
||||
Class<? extends IrisService> serviceType = i.getClass().asSubclass(IrisService.class);
|
||||
services.put(serviceType, i);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package art.arcane.iris.core.service;
|
||||
|
||||
import art.arcane.iris.core.nms.INMS;
|
||||
import art.arcane.iris.util.common.plugin.IrisService;
|
||||
import io.papermc.paper.event.server.ServerResourcesReloadedEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
public class BlockRulesSVC implements IrisService {
|
||||
private static final String RELOAD_EVENT_CLASS = "io.papermc.paper.event.server.ServerResourcesReloadedEvent";
|
||||
|
||||
public static boolean isSupported() {
|
||||
try {
|
||||
Class.forName(RELOAD_EVENT_CLASS, false, BlockRulesSVC.class.getClassLoader());
|
||||
return true;
|
||||
} catch (ClassNotFoundException | LinkageError unavailable) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onResourcesReloaded(ServerResourcesReloadedEvent event) {
|
||||
INMS.get().forgetBlockRules();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import art.arcane.iris.platform.bukkit.BukkitBlockResolution;
|
||||
|
||||
import art.arcane.iris.core.link.ExternalDataProvider;
|
||||
import art.arcane.iris.core.link.Identifier;
|
||||
import art.arcane.iris.core.nms.INMS;
|
||||
import art.arcane.iris.core.nms.container.BlockProperty;
|
||||
import art.arcane.iris.core.service.ExternalDataSVC;
|
||||
import art.arcane.volmlib.util.cache.CacheKey;
|
||||
@@ -15,6 +16,7 @@ import art.arcane.volmlib.util.math.RNG;
|
||||
import net.momirealms.craftengine.bukkit.api.CraftEngineBlocks;
|
||||
import net.momirealms.craftengine.bukkit.api.CraftEngineFurniture;
|
||||
import net.momirealms.craftengine.bukkit.api.CraftEngineItems;
|
||||
import net.momirealms.craftengine.bukkit.api.event.CraftEngineReloadEvent;
|
||||
import net.momirealms.craftengine.bukkit.item.BukkitItemDefinition;
|
||||
import net.momirealms.craftengine.core.block.BlockDefinition;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
@@ -27,6 +29,8 @@ import org.bukkit.Location;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -39,7 +43,7 @@ import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CraftEngineDataProvider extends ExternalDataProvider {
|
||||
public class CraftEngineDataProvider extends ExternalDataProvider implements Listener {
|
||||
private static final String PERSISTENT_PROPERTY = "persistent";
|
||||
private static final BlockProperty[] FURNITURE_PROPERTIES = new BlockProperty[]{
|
||||
BlockProperty.ofBoolean("randomYaw", false),
|
||||
@@ -90,6 +94,11 @@ public class CraftEngineDataProvider extends ExternalDataProvider {
|
||||
return item.buildBukkitItem();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onReload(CraftEngineReloadEvent event) {
|
||||
INMS.get().forgetBlockRules();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BlockData getBlockData(@NotNull Identifier blockId, @NotNull KMap<String, String> state) throws MissingResourceException {
|
||||
Key key = Key.of(blockId.namespace(), blockId.key());
|
||||
|
||||
@@ -290,6 +290,10 @@ public interface INMSBinding {
|
||||
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;
|
||||
|
||||
@@ -113,14 +113,15 @@ public class SurfaceSmoothingTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void foliageThatLostItsGroundGoesButDecorationsStay() {
|
||||
public void foliageStaysEvenWhereTheServerSaysItsGroundRejectsIt() {
|
||||
BlockState fern = block("minecraft:fern");
|
||||
BlockState poppy = block("minecraft:poppy");
|
||||
ApiChunk chunk = ground((x, z) -> GROUND).set(X, GROUND + 1, Z, block("minecraft:fern")).set(X + 2, GROUND + 1, Z, poppy);
|
||||
ApiChunk chunk = ground((x, z) -> GROUND).set(X, GROUND + 1, Z, fern).set(X + 2, GROUND + 1, Z, poppy);
|
||||
|
||||
chunk.generate(new PostModule());
|
||||
|
||||
assertEquals("stone holds no fern", AIR, chunk.get(X, GROUND + 1, Z));
|
||||
assertEquals("perfection, not post, removes decorations", poppy, chunk.get(X + 2, GROUND + 1, Z));
|
||||
assertEquals("post no longer removes foliage", fern, chunk.get(X, GROUND + 1, Z));
|
||||
assertEquals(poppy, chunk.get(X + 2, GROUND + 1, Z));
|
||||
}
|
||||
|
||||
/** A chunk of stone up to {@code heights}, the terrain's surface. */
|
||||
|
||||
@@ -49,7 +49,6 @@ final class SurfaceSmoothing {
|
||||
private static final ResourceId CAVE_AIR_ID = ResourceId.parse("minecraft:cave_air");
|
||||
private static final ResourceId WATER_ID = ResourceId.parse("minecraft:water");
|
||||
private static final ResourceId SNOW_ID = ResourceId.parse("minecraft:snow");
|
||||
private static final ResourceId DEAD_BUSH_ID = ResourceId.parse("minecraft:dead_bush");
|
||||
private static final String SLAB_SUFFIX = "_slab";
|
||||
private static final String WATERLOGGED = "waterlogged";
|
||||
private static final String TRUE = "true";
|
||||
@@ -168,7 +167,7 @@ final class SurfaceSmoothing {
|
||||
h = placeSlab(x, z, h, ha, hb, hc, hd);
|
||||
}
|
||||
settleWaterlogging(x, z, h);
|
||||
settleFoliage(x, z, h);
|
||||
settleVine(x, z, h);
|
||||
}
|
||||
|
||||
private int removeFloatingNib(int x, int z, int h, int ha, int hb, int hc, int hd) {
|
||||
@@ -273,17 +272,11 @@ final class SurfaceSmoothing {
|
||||
}
|
||||
}
|
||||
|
||||
private void settleFoliage(int x, int z, int h) {
|
||||
private void settleVine(int x, int z, int h) {
|
||||
BlockState block = get(x, h + 1, z);
|
||||
if (has(block, BlockTrait.VINE)) {
|
||||
connectVine(x, h + 1, z, block);
|
||||
}
|
||||
if (!has(block, BlockTrait.FOLIAGE) && !block.material().equals(DEAD_BUSH_ID)) {
|
||||
return;
|
||||
}
|
||||
if (!registry.canPlaceOn(block, get(x, h, z)) && !has(block, BlockTrait.DECORATION)) {
|
||||
set(x, h + 1, z, AIR);
|
||||
}
|
||||
}
|
||||
|
||||
/** A vine faces each neighbour it can cling to, a block that is neither air nor another vine. */
|
||||
|
||||
Reference in new issue
Block a user