Fixed decay not working.

This commit is contained in:
Waterpicker 2021-10-03 10:36:26 -05:00
parent 809c686618
commit f59114ba3f
12 changed files with 203 additions and 245 deletions

View file

@ -53,6 +53,7 @@ import static net.minecraft.block.Blocks.SPRUCE_PLANKS;
import static net.minecraft.block.Blocks.SPRUCE_WOOD;
import static net.minecraft.block.Blocks.STONE;
import static net.minecraft.block.Blocks.STONE_BRICKS;
import static org.dimdev.dimdoors.block.ModBlocks.UNRAVELLED_BLOCK;
import static org.dimdev.dimdoors.block.ModBlocks.UNRAVELLED_FABRIC;
import com.google.gson.Gson;
@ -60,10 +61,12 @@ import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.block.ModBlocks;
import org.dimdev.dimdoors.world.decay.DecayPattern;
import org.dimdev.dimdoors.world.decay.DecayPredicate;
import org.dimdev.dimdoors.world.decay.DecayProcessor;
import org.dimdev.dimdoors.world.decay.predicates.SimpleDecayPredicate;
import org.dimdev.dimdoors.world.decay.processors.SelfDecayProcessor;
import org.dimdev.dimdoors.world.decay.processors.SimpleDecayProcesor;
import net.minecraft.block.Block;
@ -106,7 +109,7 @@ public class LimboDecayProvider implements DataProvider {
createSimplePattern(new Identifier("dimdoors:stone"), STONE, COBBLESTONE).run(consumer);
createSimplePattern(new Identifier("dimdoors:cobblestone"), COBBLESTONE, END_STONE).run(consumer);
createSimplePattern(new Identifier("dimdoors:gravel"), GRAVEL, SAND).run(consumer);
createSimplePattern(new Identifier("dimdoors:sand"), SAND, UNRAVELLED_FABRIC).run(consumer);
turnIntoSelf(new Identifier("dimdoors:sand"), SAND).run(consumer);
createSimplePattern(new Identifier("dimdoors:glass"), GLASS, SAND).run(consumer);
createSimplePattern(new Identifier("dimdoors:grass_block"), GRASS_BLOCK, DIRT).run(consumer);
createSimplePattern(new Identifier("dimdoors:dirt"), DIRT, SAND).run(consumer);
@ -152,6 +155,10 @@ public class LimboDecayProvider implements DataProvider {
createSimplePattern(new Identifier("dimdoors:dark_oak_wood"), DARK_OAK_WOOD, DARK_OAK_LOG).run(consumer);
}
private DecayPatternData turnIntoSelf(Identifier identifier, Block before) {
return new DecayPatternData(identifier, SimpleDecayPredicate.builder().block(before).create(), SelfDecayProcessor.instance());
}
@Override
public String getName() {

View file

@ -41,12 +41,12 @@ import org.dimdev.dimdoors.pockets.virtual.ImplementedVirtualPocket;
import org.dimdev.dimdoors.rift.targets.Targets;
import org.dimdev.dimdoors.rift.targets.VirtualTarget;
import org.dimdev.dimdoors.sound.ModSoundEvents;
import org.dimdev.dimdoors.world.decay.DecayLoader;
import org.dimdev.dimdoors.world.ModBiomes;
import org.dimdev.dimdoors.world.ModDimensions;
import org.dimdev.dimdoors.world.decay.DecayPredicate;
import org.dimdev.dimdoors.world.decay.DecayProcessor;
import org.dimdev.dimdoors.world.feature.ModFeatures;
import org.dimdev.dimdoors.world.decay.LimboDecay;
import org.dimdev.dimdoors.world.pocket.type.AbstractPocket;
import org.dimdev.dimdoors.world.pocket.type.addon.PocketAddon;
import org.jetbrains.annotations.NotNull;
@ -139,7 +139,7 @@ public class DimensionalDoorsInitializer implements ModInitializer {
dimensionalDoorBlockRegistrar = new DimensionalDoorBlockRegistrar(Registry.BLOCK, dimensionalDoorItemRegistrar);
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(PocketLoader.getInstance());
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(DecayLoader.getInstance());
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(LimboDecay.DecayLoader.getInstance());
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier("dimdoors", "default"), dimDoorsMod, CONFIG_MANAGER.get().getPocketsConfig().defaultPocketsResourcePackActivationType.asResourcePackActivationType());
ResourceManagerHelper.registerBuiltinResourcePack(new Identifier("dimdoors", "classic"), dimDoorsMod, CONFIG_MANAGER.get().getPocketsConfig().classicPocketsResourcePackActivationType.asResourcePackActivationType());

View file

@ -1,77 +0,0 @@
package org.dimdev.dimdoors.world.decay;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.api.util.Path;
import org.dimdev.dimdoors.api.util.SimpleTree;
import org.jetbrains.annotations.NotNull;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
public class DecayLoader implements SimpleSynchronousResourceReloadListener {
private static final Logger LOGGER = LogManager.getLogger();
private static final Gson GSON = new GsonBuilder().setLenient().setPrettyPrinting().create();
private static final DecayLoader INSTANCE = new DecayLoader();
private SimpleTree<String, DecayPattern> patterns = new SimpleTree<>(String.class);
private DecayLoader() {
}
public static DecayLoader getInstance() {
return INSTANCE;
}
@Override
public void reload(ResourceManager manager) {
patterns.clear();
CompletableFuture<SimpleTree<String, DecayPattern>> futurePatternMap = loadResourcePathFromJsonToTree(manager, "decay_patterns", this::loadPattern);
patterns = futurePatternMap.join();
}
private DecayPattern loadPattern(JsonObject object) {
return DecayPattern.deserialize(object);
}
private <T> CompletableFuture<SimpleTree<String, T>> loadResourcePathFromJsonToTree(ResourceManager manager, String startingPath, Function<JsonObject, T> reader) {
int sub = startingPath.endsWith("/") ? 0 : 1;
Collection<Identifier> ids = manager.findResources(startingPath, str -> str.endsWith(".json"));
return CompletableFuture.supplyAsync(() -> {
SimpleTree<String, T> tree = new SimpleTree<>(String.class);
tree.putAll(ids.parallelStream().unordered().collect(Collectors.toConcurrentMap(
id -> Path.stringPath(id.getNamespace() + ":" + id.getPath().substring(0, id.getPath().lastIndexOf(".")).substring(startingPath.length() + sub)),
id -> {
try {
JsonElement json = GSON.fromJson(new InputStreamReader(manager.getResource(id).getInputStream()), JsonElement.class);
return reader.apply(json.getAsJsonObject());
} catch (IOException e) {
throw new RuntimeException("Error loading resource: " + id);
}
})));
return tree;
});
}
public @NotNull Collection<DecayPattern> getPatterns() {
return patterns.values();
}
@Override
public Identifier getFabricId() {
return new Identifier("dimdoors", "decay_pattern");
}
}

View file

@ -1,9 +1,8 @@
package org.dimdev.dimdoors.world.decay;
import com.google.gson.JsonObject;
import org.dimdev.dimdoors.world.decay.predicates.SimpleDecayPredicate;
import net.minecraft.util.Identifier;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -31,9 +30,9 @@ public class DecayPattern {
return DecayPattern.builder().predicate(predicate).processor(processor).create();
}
public boolean run(World world, BlockPos pos) {
if(predicate.test(world, pos)) {
ENTROPY_EVENT.invoker().entropy(world, pos, processor.process(world, pos));
public boolean run(World world, BlockPos pos, BlockState origin, BlockState target) {
if(predicate.test(world, pos, origin, target)) {
ENTROPY_EVENT.invoker().entropy(world, pos, processor.process(world, pos, origin, target));
return true;
}

View file

@ -8,6 +8,7 @@ import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.world.decay.predicates.SimpleDecayPredicate;
import org.dimdev.dimdoors.world.decay.processors.SimpleDecayProcesor;
import net.minecraft.block.BlockState;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
@ -39,7 +40,7 @@ public interface DecayPredicate {
}
@Override
public boolean test(World world, BlockPos pos) {
public boolean test(World world, BlockPos pos, BlockState origin, BlockState target) {
return false;
}
};
@ -64,7 +65,7 @@ public interface DecayPredicate {
String getKey();
boolean test(World world, BlockPos pos);
boolean test(World world, BlockPos pos, BlockState origin, BlockState target);
interface DecayPredicateType<T extends DecayPredicate> {
DecayPredicateType<DecayPredicate> NONE_PREDICATE_TYPE = register(new Identifier("dimdoors", "none"), () -> DUMMY);

View file

@ -5,20 +5,10 @@ import java.util.function.Supplier;
import com.google.gson.JsonObject;
import com.mojang.serialization.Lifecycle;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.ModConfig;
import org.dimdev.dimdoors.pockets.PocketGenerationContext;
import org.dimdev.dimdoors.pockets.modifier.AbsoluteRiftBlockEntityModifier;
import org.dimdev.dimdoors.pockets.modifier.DimensionalDoorModifier;
import org.dimdev.dimdoors.pockets.modifier.OffsetModifier;
import org.dimdev.dimdoors.pockets.modifier.PocketEntranceModifier;
import org.dimdev.dimdoors.pockets.modifier.RelativeReferenceModifier;
import org.dimdev.dimdoors.pockets.modifier.RiftDataModifier;
import org.dimdev.dimdoors.pockets.modifier.RiftManager;
import org.dimdev.dimdoors.pockets.modifier.ShellModifier;
import org.dimdev.dimdoors.world.decay.processors.SelfDecayProcessor;
import org.dimdev.dimdoors.world.decay.processors.SimpleDecayProcesor;
import org.dimdev.dimdoors.world.pocket.type.Pocket;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.block.BlockState;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
@ -48,7 +38,7 @@ public interface DecayProcessor {
}
@Override
public int process(World world, BlockPos pos) {
public int process(World world, BlockPos pos, BlockState origin, BlockState target) {
return 0;
}
@ -75,11 +65,12 @@ public interface DecayProcessor {
String getKey();
int process(World world, BlockPos pos);
int process(World world, BlockPos pos, BlockState origin, BlockState target);
interface DecayProcessorType<T extends DecayProcessor> {
DecayProcessorType<SimpleDecayProcesor> SIMPLE_PROCESSOR_TYPE = register(new Identifier("dimdoors", SimpleDecayProcesor.KEY), SimpleDecayProcesor::new);
DecayProcessorType<DecayProcessor> NONE_PROCESSOR_TYPE = register(new Identifier("dimdoors", "none"), () -> DUMMY);
DecayProcessorType<SelfDecayProcessor> SELF = register(new Identifier("dimdoors", SelfDecayProcessor.KEY), SelfDecayProcessor::instance);
DecayProcessor fromJson(JsonObject nbt);

View file

@ -0,0 +1,136 @@
package org.dimdev.dimdoors.world.decay;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.block.BlockState;
import net.minecraft.resource.ResourceManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.api.util.Path;
import org.dimdev.dimdoors.api.util.SimpleTree;
import org.dimdev.dimdoors.world.decay.DecayPattern;
import org.jetbrains.annotations.NotNull;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
* Provides methods for applying Limbo decay. Limbo decay refers to the effect that most blocks placed in Limbo
* naturally change into stone, then cobble, then gravel, and finally Unraveled Fabric as time passes.
*/
public final class LimboDecay {
private static final Logger LOGGER = LogManager.getLogger();
private static final Random RANDOM = new Random();
/**
* Checks the blocks orthogonally around a given location (presumably the location of an Unraveled Fabric block)
* and applies Limbo decay to them. This gives the impression that decay spreads outward from Unraveled Fabric.
*/
public static void applySpreadDecay(World world, BlockPos pos) {
//Check if we randomly apply decay spread or not. This can be used to moderate the frequency of
//full spread decay checks, which can also shift its performance impact on the game.
if (RANDOM.nextDouble() < DimensionalDoorsInitializer.getConfig().getLimboConfig().decaySpreadChance) {
BlockState origin = world.getBlockState(pos);
//Apply decay to the blocks above, below, and on all four sides.
//World.getBlockId() implements bounds checking, so we don't have to worry about reaching out of the world/*
/*boolean flag = */decayBlock(world, pos.up(), origin);
/*flag = flag && */decayBlock(world, pos.down(), origin);
/*flag = flag && */decayBlock(world, pos.north(), origin);
/*flag = flag && */decayBlock(world, pos.south(), origin);
/*flag = flag && */decayBlock(world, pos.west(), origin);
/*flag = flag && */decayBlock(world, pos.east(), origin);
// if (flag) {
// LOGGER.debug("Applied limbo decay to block at all six sides at position {} in dimension {}", pos, world.getRegistryKey().getValue());
// }
}
}
/**
* Checks if a block can be decayed and, if so, changes it to the next block ID along the decay sequence.
*/
private static boolean decayBlock(World world, BlockPos pos, BlockState origin) {
@NotNull Collection<DecayPattern> patterns = DecayLoader.getInstance().getPatterns();
if(patterns.isEmpty()) return false;
BlockState target = world.getBlockState(pos);
for (DecayPattern pattern : DecayLoader.getInstance().getPatterns()) {
if(pattern.run(world, pos, origin, target)) return true;
}
return false;
}
public static class DecayLoader implements SimpleSynchronousResourceReloadListener {
private static final Logger LOGGER = LogManager.getLogger();
private static final Gson GSON = new GsonBuilder().setLenient().setPrettyPrinting().create();
private static final DecayLoader INSTANCE = new DecayLoader();
private SimpleTree<String, DecayPattern> patterns = new SimpleTree<>(String.class);
private DecayLoader() {
}
public static DecayLoader getInstance() {
return INSTANCE;
}
@Override
public void reload(ResourceManager manager) {
patterns.clear();
CompletableFuture<SimpleTree<String, DecayPattern>> futurePatternMap = loadResourcePathFromJsonToTree(manager, "decay_patterns", this::loadPattern);
patterns = futurePatternMap.join();
}
private DecayPattern loadPattern(JsonObject object) {
return DecayPattern.deserialize(object);
}
private <T> CompletableFuture<SimpleTree<String, T>> loadResourcePathFromJsonToTree(ResourceManager manager, String startingPath, Function<JsonObject, T> reader) {
int sub = startingPath.endsWith("/") ? 0 : 1;
Collection<Identifier> ids = manager.findResources(startingPath, str -> str.endsWith(".json"));
return CompletableFuture.supplyAsync(() -> {
SimpleTree<String, T> tree = new SimpleTree<>(String.class);
tree.putAll(ids.parallelStream().unordered().collect(Collectors.toConcurrentMap(
id -> Path.stringPath(id.getNamespace() + ":" + id.getPath().substring(0, id.getPath().lastIndexOf(".")).substring(startingPath.length() + sub)),
id -> {
try {
JsonElement json = GSON.fromJson(new InputStreamReader(manager.getResource(id).getInputStream()), JsonElement.class);
return reader.apply(json.getAsJsonObject());
} catch (IOException e) {
throw new RuntimeException("Error loading resource: " + id);
}
})));
return tree;
});
}
public @NotNull Collection<DecayPattern> getPatterns() {
return patterns.values();
}
@Override
public Identifier getFabricId() {
return new Identifier("dimdoors", "decay_pattern");
}
}
}

View file

@ -46,7 +46,7 @@ public class SimpleDecayPredicate implements DecayPredicate {
}
@Override
public boolean test(World world, BlockPos pos) {
public boolean test(World world, BlockPos pos, BlockState origin, BlockState target) {
BlockState state = world.getBlockState(pos);
return state.getBlock() == block;

View file

@ -0,0 +1,41 @@
package org.dimdev.dimdoors.world.decay.processors;
import static org.dimdev.dimdoors.world.decay.DecayProcessor.DecayProcessorType.SELF;
import com.google.gson.JsonObject;
import org.dimdev.dimdoors.world.decay.DecayProcessor;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class SelfDecayProcessor implements DecayProcessor {
public static final String KEY = "self";
private static final SelfDecayProcessor instance = new SelfDecayProcessor();
public static SelfDecayProcessor instance() {
return instance;
}
@Override
public DecayProcessor fromJson(JsonObject json) {
return this;
}
@Override
public DecayProcessorType<? extends DecayProcessor> getType() {
return SELF;
}
@Override
public String getKey() {
return KEY;
}
@Override
public int process(World world, BlockPos pos, BlockState origin, BlockState target) {
world.setBlockState(pos, origin);
return 0;
}
}

View file

@ -2,9 +2,9 @@ package org.dimdev.dimdoors.world.decay.processors;
import com.google.gson.JsonObject;
import org.dimdev.dimdoors.world.decay.DecayProcessor;
import org.dimdev.dimdoors.world.decay.predicates.SimpleDecayPredicate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
@ -51,7 +51,7 @@ public class SimpleDecayProcesor implements DecayProcessor {
}
@Override
public int process(World world, BlockPos pos) {
public int process(World world, BlockPos pos, BlockState origin, BlockState target) {
world.setBlockState(pos, block.getDefaultState());
return entropy;
}

View file

@ -1,138 +0,0 @@
package org.dimdev.dimdoors.world.limbo;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.mojang.serialization.Codec;
import com.mojang.serialization.JsonOps;
import com.mojang.serialization.codecs.UnboundedMapCodec;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.resource.ResourceManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.world.decay.DecayLoader;
import org.dimdev.dimdoors.world.decay.DecayPattern;
import org.jetbrains.annotations.NotNull;
import net.minecraft.block.Block;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import static net.minecraft.block.Blocks.ACACIA_LOG;
import static net.minecraft.block.Blocks.ACACIA_PLANKS;
import static net.minecraft.block.Blocks.ACACIA_WOOD;
import static net.minecraft.block.Blocks.ANDESITE;
import static net.minecraft.block.Blocks.BIRCH_LOG;
import static net.minecraft.block.Blocks.BIRCH_PLANKS;
import static net.minecraft.block.Blocks.BIRCH_WOOD;
import static net.minecraft.block.Blocks.BLACKSTONE;
import static net.minecraft.block.Blocks.COAL_BLOCK;
import static net.minecraft.block.Blocks.COAL_ORE;
import static net.minecraft.block.Blocks.COBBLESTONE;
import static net.minecraft.block.Blocks.CRACKED_STONE_BRICKS;
import static net.minecraft.block.Blocks.DARK_OAK_LOG;
import static net.minecraft.block.Blocks.DARK_OAK_PLANKS;
import static net.minecraft.block.Blocks.DARK_OAK_WOOD;
import static net.minecraft.block.Blocks.DIORITE;
import static net.minecraft.block.Blocks.DIRT;
import static net.minecraft.block.Blocks.DIRT_PATH;
import static net.minecraft.block.Blocks.EMERALD_BLOCK;
import static net.minecraft.block.Blocks.EMERALD_ORE;
import static net.minecraft.block.Blocks.END_STONE;
import static net.minecraft.block.Blocks.END_STONE_BRICKS;
import static net.minecraft.block.Blocks.FARMLAND;
import static net.minecraft.block.Blocks.GLASS;
import static net.minecraft.block.Blocks.GOLD_BLOCK;
import static net.minecraft.block.Blocks.GOLD_ORE;
import static net.minecraft.block.Blocks.GRANITE;
import static net.minecraft.block.Blocks.GRASS_BLOCK;
import static net.minecraft.block.Blocks.GRAVEL;
import static net.minecraft.block.Blocks.IRON_BLOCK;
import static net.minecraft.block.Blocks.IRON_ORE;
import static net.minecraft.block.Blocks.JUNGLE_LOG;
import static net.minecraft.block.Blocks.JUNGLE_PLANKS;
import static net.minecraft.block.Blocks.JUNGLE_WOOD;
import static net.minecraft.block.Blocks.LAPIS_BLOCK;
import static net.minecraft.block.Blocks.LAPIS_ORE;
import static net.minecraft.block.Blocks.OAK_LOG;
import static net.minecraft.block.Blocks.OAK_PLANKS;
import static net.minecraft.block.Blocks.OAK_WOOD;
import static net.minecraft.block.Blocks.PODZOL;
import static net.minecraft.block.Blocks.POLISHED_ANDESITE;
import static net.minecraft.block.Blocks.POLISHED_BLACKSTONE;
import static net.minecraft.block.Blocks.POLISHED_DIORITE;
import static net.minecraft.block.Blocks.POLISHED_GRANITE;
import static net.minecraft.block.Blocks.REDSTONE_BLOCK;
import static net.minecraft.block.Blocks.REDSTONE_ORE;
import static net.minecraft.block.Blocks.SAND;
import static net.minecraft.block.Blocks.SANDSTONE;
import static net.minecraft.block.Blocks.SPRUCE_LOG;
import static net.minecraft.block.Blocks.SPRUCE_PLANKS;
import static net.minecraft.block.Blocks.SPRUCE_WOOD;
import static net.minecraft.block.Blocks.STONE;
import static net.minecraft.block.Blocks.STONE_BRICKS;
import static org.dimdev.dimdoors.block.ModBlocks.UNRAVELLED_FABRIC;
/**
* Provides methods for applying Limbo decay. Limbo decay refers to the effect that most blocks placed in Limbo
* naturally change into stone, then cobble, then gravel, and finally Unraveled Fabric as time passes.
*/
public final class LimboDecay {
private static final Logger LOGGER = LogManager.getLogger();
private static final Random RANDOM = new Random();
/**
* Checks the blocks orthogonally around a given location (presumably the location of an Unraveled Fabric block)
* and applies Limbo decay to them. This gives the impression that decay spreads outward from Unraveled Fabric.
*/
public static void applySpreadDecay(World world, BlockPos pos) {
//Check if we randomly apply decay spread or not. This can be used to moderate the frequency of
//full spread decay checks, which can also shift its performance impact on the game.
if (RANDOM.nextDouble() < DimensionalDoorsInitializer.getConfig().getLimboConfig().decaySpreadChance) {
//Apply decay to the blocks above, below, and on all four sides.
//World.getBlockId() implements bounds checking, so we don't have to worry about reaching out of the world
boolean flag = decayBlock(world, pos.up());
flag = flag && decayBlock(world, pos.down());
flag = flag && decayBlock(world, pos.north());
flag = flag && decayBlock(world, pos.south());
flag = flag && decayBlock(world, pos.west());
flag = flag && decayBlock(world, pos.east());
if (flag) {
LOGGER.debug("Applied limbo decay to block at all six sides at position {} in dimension {}", pos, world.getRegistryKey().getValue());
}
}
}
/**
* Checks if a block can be decayed and, if so, changes it to the next block ID along the decay sequence.
*/
private static boolean decayBlock(World world, BlockPos pos) {
@NotNull Collection<DecayPattern> patterns = DecayLoader.getInstance().getPatterns();
if(patterns.isEmpty()) return false;
for (DecayPattern pattern : DecayLoader.getInstance().getPatterns()) {
if(pattern.run(world, pos)) return true;
}
return false;
}
}

View file

@ -4,8 +4,6 @@
"block": "minecraft:sand"
},
"processor": {
"type": "dimdoors:simple",
"block": "dimdoors:unravelled_fabric",
"entropy": 1
"type": "dimdoors:self"
}
}