Added a blocktag for movable tile entities with spatial IO. (#4448)

`#spatial/whitelist` needs to be explicitly enabled through a config
value.
`#spatial/blacklist` will always be consider on top of the normal
blacklist.
This commit is contained in:
yueh
2020-07-03 20:34:53 +02:00
committed by GitHub
parent bd1d9701a9
commit d4a1590b51
4 changed files with 53 additions and 14 deletions
+10
View File
@@ -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<Double> spatialPowerExponent;
public final ConfigValue<Double> spatialPowerMultiplier;
public final ConfigValue<Boolean> 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");
@@ -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<Block> 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<Class<? extends TileEntity>, IMovableHandler> Valid = new HashMap<>();
private final Set<Block> blacklisted = new HashSet<>();
private final Map<Class<? extends TileEntity>, IMovableHandler> valid = new IdentityHashMap<>();
private final List<Class<? extends TileEntity>> test = new ArrayList<>();
private final List<IMovableHandler> handlers = new ArrayList<>();
private final DefaultSpatialHandler dsh = new DefaultSpatialHandler();
private final IMovableHandler nullHandler = new DefaultSpatialHandler();
private final Tag<Block> blockTagWhiteList;
private final Tag<Block> 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<? extends TileEntity> 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<? extends TileEntity> 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<? extends TileEntity> 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<? extends TileEntity> 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);
}
}
@@ -0,0 +1,3 @@
{
"values": []
}
@@ -0,0 +1,3 @@
{
"values": []
}