diff --git a/src/main/java/appeng/core/AEConfig.java b/src/main/java/appeng/core/AEConfig.java index 22288bf67..444f7410e 100644 --- a/src/main/java/appeng/core/AEConfig.java +++ b/src/main/java/appeng/core/AEConfig.java @@ -106,6 +106,7 @@ public final class AEConfig { // Spatial IO/Dimension private double spatialPowerExponent; private double spatialPowerMultiplier; + private boolean spatialBlockTags; // Grindstone private float oreDoublePercentage; @@ -208,6 +209,7 @@ public final class AEConfig { this.spatialPowerMultiplier = COMMON.spatialPowerMultiplier.get(); this.spatialPowerExponent = COMMON.spatialPowerExponent.get(); + this.spatialBlockTags = COMMON.spatialBlockTags.get(); this.craftingCalculationTimePerTick = COMMON.craftingCalculationTimePerTick.get(); @@ -335,6 +337,10 @@ public final class AEConfig { return this.spatialPowerMultiplier; } + public boolean getSpatialBlockTags() { + return this.spatialBlockTags; + } + public float getOreDoublePercentage() { return this.oreDoublePercentage; } @@ -457,6 +463,7 @@ public final class AEConfig { // Spatial IO/Dimension public final ConfigValue spatialPowerExponent; public final ConfigValue spatialPowerMultiplier; + public final ConfigValue spatialBlockTags; // Grindstone public final DoubleValue oreDoublePercentage; @@ -544,6 +551,9 @@ public final class AEConfig { builder.push("spatialio"); this.spatialPowerMultiplier = builder.define("spatialPowerMultiplier", 1250.0); this.spatialPowerExponent = builder.define("spatialPowerExponent", 1.35); + this.spatialBlockTags = builder + .comment("BE CAREFUL, CAN CORRUPT YOUR WORLD! Will use #spatial/whitelist as whitelist.") + .define("spatialBlockTags", false); builder.pop(); builder.push("GrindStone"); diff --git a/src/main/java/appeng/core/features/registries/MovableTileRegistry.java b/src/main/java/appeng/core/features/registries/MovableTileRegistry.java index 579ace8c8..cce747112 100644 --- a/src/main/java/appeng/core/features/registries/MovableTileRegistry.java +++ b/src/main/java/appeng/core/features/registries/MovableTileRegistry.java @@ -19,29 +19,45 @@ package appeng.core.features.registries; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; +import java.util.IdentityHashMap; import java.util.List; +import java.util.Map; +import java.util.Set; import net.minecraft.block.Block; +import net.minecraft.tags.BlockTags; +import net.minecraft.tags.Tag; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; import appeng.api.exceptions.AppEngException; import appeng.api.movable.IMovableHandler; import appeng.api.movable.IMovableRegistry; import appeng.api.movable.IMovableTile; +import appeng.core.AEConfig; +import appeng.core.AppEng; import appeng.spatial.DefaultSpatialHandler; public class MovableTileRegistry implements IMovableRegistry { - private final HashSet blacklisted = new HashSet<>(); + private static final ResourceLocation TAG_WHITELIST = new ResourceLocation(AppEng.MOD_ID, "spatial/whitelist"); + private static final ResourceLocation TAG_BLACKLIST = new ResourceLocation(AppEng.MOD_ID, "spatial/blacklist"); - private final HashMap, IMovableHandler> Valid = new HashMap<>(); + private final Set blacklisted = new HashSet<>(); + + private final Map, IMovableHandler> valid = new IdentityHashMap<>(); private final List> test = new ArrayList<>(); private final List handlers = new ArrayList<>(); private final DefaultSpatialHandler dsh = new DefaultSpatialHandler(); - private final IMovableHandler nullHandler = new DefaultSpatialHandler(); + private final Tag blockTagWhiteList; + private final Tag blockTagBlackList; + + public MovableTileRegistry() { + this.blockTagWhiteList = BlockTags.getCollection().getOrCreate(TAG_WHITELIST); + this.blockTagBlackList = BlockTags.getCollection().getOrCreate(TAG_BLACKLIST); + } @Override public void blacklistBlock(final Block blk) { @@ -60,8 +76,8 @@ public class MovableTileRegistry implements IMovableRegistry { @Override public boolean askToMove(final TileEntity te) { - final Class myClass = te.getClass(); - IMovableHandler canMove = this.Valid.get(myClass); + final Class myClass = te.getClass(); + IMovableHandler canMove = this.valid.get(myClass); if (canMove == null) { canMove = this.testClass(myClass, te); @@ -79,7 +95,7 @@ public class MovableTileRegistry implements IMovableRegistry { return false; } - private IMovableHandler testClass(final Class myClass, final TileEntity te) { + private IMovableHandler testClass(final Class myClass, final TileEntity te) { IMovableHandler handler = null; // ask handlers... @@ -92,25 +108,32 @@ public class MovableTileRegistry implements IMovableRegistry { // if you have a handler your opted in if (handler != null) { - this.Valid.put(myClass, handler); + this.valid.put(myClass, handler); return handler; } // if your movable our opted in if (te instanceof IMovableTile) { - this.Valid.put(myClass, this.dsh); + this.valid.put(myClass, this.dsh); + return this.dsh; + } + + // if the block itself is via block tags + if (AEConfig.instance().getSpatialBlockTags() + && this.blockTagWhiteList.contains(te.getBlockState().getBlock())) { + this.valid.put(myClass, this.dsh); return this.dsh; } // if you are on the white list your opted in. for (final Class testClass : this.test) { if (testClass.isAssignableFrom(myClass)) { - this.Valid.put(myClass, this.dsh); + this.valid.put(myClass, this.dsh); return this.dsh; } } - this.Valid.put(myClass, this.nullHandler); + this.valid.put(myClass, this.nullHandler); return this.nullHandler; } @@ -129,8 +152,8 @@ public class MovableTileRegistry implements IMovableRegistry { @Override public IMovableHandler getHandler(final TileEntity te) { - final Class myClass = te.getClass(); - final IMovableHandler h = this.Valid.get(myClass); + final Class myClass = te.getClass(); + final IMovableHandler h = this.valid.get(myClass); return h == null ? this.dsh : h; } @@ -141,6 +164,6 @@ public class MovableTileRegistry implements IMovableRegistry { @Override public boolean isBlacklisted(final Block blk) { - return this.blacklisted.contains(blk); + return this.blacklisted.contains(blk) || this.blockTagBlackList.contains(blk); } } diff --git a/src/main/resources/data/appliedenergistics2/tags/blocks/spatial/blacklist.json b/src/main/resources/data/appliedenergistics2/tags/blocks/spatial/blacklist.json new file mode 100644 index 000000000..86dde3df2 --- /dev/null +++ b/src/main/resources/data/appliedenergistics2/tags/blocks/spatial/blacklist.json @@ -0,0 +1,3 @@ +{ + "values": [] +} diff --git a/src/main/resources/data/appliedenergistics2/tags/blocks/spatial/whitelist.json b/src/main/resources/data/appliedenergistics2/tags/blocks/spatial/whitelist.json new file mode 100644 index 000000000..86dde3df2 --- /dev/null +++ b/src/main/resources/data/appliedenergistics2/tags/blocks/spatial/whitelist.json @@ -0,0 +1,3 @@ +{ + "values": [] +}