mirror of
https://github.com/GTNewHorizons/StructureLib.git
synced 2026-11-18 11:19:29 +00:00
Add error hint when block is invalid (#31)
Co-authored-by: kstvr32 <[email protected]> Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
10 files changed
+315
-16
No files matched your search
@@ -155,6 +155,11 @@ public class StructureUtility {
|
||||
return world.isAirBlock(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(Object t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(Object o, World world, int x, int y, int z, ItemStack trigger) {
|
||||
StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), 13);
|
||||
@@ -186,6 +191,11 @@ public class StructureUtility {
|
||||
return !world.isAirBlock(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(Object t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(Object o, World world, int x, int y, int z, ItemStack trigger) {
|
||||
StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), 14);
|
||||
@@ -225,6 +235,11 @@ public class StructureUtility {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(Object t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(Object o, World world, int x, int y, int z, ItemStack trigger) {
|
||||
StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), 15);
|
||||
@@ -479,6 +494,11 @@ public class StructureUtility {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
StructureLibAPI.hintParticle(world, x, y, z, StructureLibAPI.getBlockHint(), meta);
|
||||
@@ -499,6 +519,11 @@ public class StructureUtility {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
StructureLibAPI.hintParticle(world, x, y, z, icons.get());
|
||||
@@ -519,6 +544,11 @@ public class StructureUtility {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
StructureLibAPI.hintParticleTinted(world, x, y, z, icons.get(), RGBa);
|
||||
@@ -667,9 +697,23 @@ public class StructureUtility {
|
||||
}
|
||||
|
||||
private Pair<Block, Integer> getHint(ItemStack trigger) {
|
||||
if (hints.isEmpty()) return null;
|
||||
return hints.get(Math.min(Math.max(trigger.stackSize, 1), hints.size()) - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
Pair<Block, Integer> hint = getHint(trigger);
|
||||
if (hint == null) return true;
|
||||
TIER hintTier = tierExtractor.convert(hint.getKey(), hint.getValue());
|
||||
Block block = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
TIER worldTier = tierExtractor.convert(block, meta);
|
||||
|
||||
// if the block is in the same tier as the hint block, this could be valid
|
||||
return Objects.equals(hintTier, worldTier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
Pair<Block, Integer> hint = getHint(trigger);
|
||||
@@ -767,6 +811,11 @@ public class StructureUtility {
|
||||
return world.getBlock(x, y, z) == getBlock() && (wildcard || world.getBlockMetadata(x, y, z) == meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
if (getBlock() == null) return error().spawnHint(t, world, x, y, z, trigger);
|
||||
@@ -841,10 +890,16 @@ public class StructureUtility {
|
||||
|
||||
@Override
|
||||
public boolean check(T t, World world, int x, int y, int z) {
|
||||
if (init()) return world.getBlock(x, y, z) != block && world.getBlockMetadata(x, y, z) == meta;
|
||||
if (init()) return world.getBlock(x, y, z) == block && world.getBlockMetadata(x, y, z) == meta;
|
||||
else return fallback.check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
if (init()) return world.getBlock(x, y, z) == block && world.getBlockMetadata(x, y, z) == meta;
|
||||
else return fallback.couldBeValid(t, world, x, y, z, trigger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
if (init()) {
|
||||
@@ -921,6 +976,11 @@ public class StructureUtility {
|
||||
return blocsMap.getOrDefault(worldBlock, MIN_VALUE) == worldBlock.getDamageValue(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta);
|
||||
@@ -958,6 +1018,11 @@ public class StructureUtility {
|
||||
.contains(worldBlock.getDamageValue(world, x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta);
|
||||
@@ -982,6 +1047,11 @@ public class StructureUtility {
|
||||
return block == worldBlock && meta == worldBlock.getDamageValue(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta);
|
||||
@@ -1016,6 +1086,13 @@ public class StructureUtility {
|
||||
return iBlockAdder.apply(t, worldBlock, worldBlock.getDamageValue(world, x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
// calling iBlockAdder can potentially modify external state
|
||||
// therefore we assume this can always be valid.
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta);
|
||||
@@ -1049,6 +1126,11 @@ public class StructureUtility {
|
||||
return blocsMap.getOrDefault(worldBlock, MIN_VALUE) == worldBlock.getDamageValue(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
((ICustomBlockSetting) defaultBlock).setBlock(world, x, y, z, defaultMeta);
|
||||
@@ -1093,6 +1175,11 @@ public class StructureUtility {
|
||||
return blocsMap.getOrDefault(worldBlock, MIN_VALUE) == worldBlock.getDamageValue(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
world.setBlock(x, y, z, defaultBlock, defaultMeta, 2);
|
||||
@@ -1158,6 +1245,11 @@ public class StructureUtility {
|
||||
.contains(worldBlock.getDamageValue(world, x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
((ICustomBlockSetting) defaultBlock).setBlock(world, x, y, z, defaultMeta);
|
||||
@@ -1203,6 +1295,11 @@ public class StructureUtility {
|
||||
.contains(worldBlock.getDamageValue(world, x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
world.setBlock(x, y, z, defaultBlock, defaultMeta, 2);
|
||||
@@ -1260,6 +1357,11 @@ public class StructureUtility {
|
||||
return block == worldBlock && meta == worldBlock.getDamageValue(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
((ICustomBlockSetting) defaultBlock).setBlock(world, x, y, z, defaultMeta);
|
||||
@@ -1287,6 +1389,11 @@ public class StructureUtility {
|
||||
return block == worldBlock && meta == worldBlock.getDamageValue(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
world.setBlock(x, y, z, defaultBlock, defaultMeta, 2);
|
||||
@@ -1323,6 +1430,11 @@ public class StructureUtility {
|
||||
return block == world.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
((ICustomBlockSetting) defaultBlock).setBlock(world, x, y, z, defaultMeta);
|
||||
@@ -1350,6 +1462,11 @@ public class StructureUtility {
|
||||
return block == world.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
world.setBlock(x, y, z, defaultBlock, defaultMeta, 2);
|
||||
@@ -1416,6 +1533,13 @@ public class StructureUtility {
|
||||
return iBlockAdder.apply(t, worldBlock, worldBlock.getDamageValue(world, x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
// calling iBlockAdder can potentially modify external state
|
||||
// therefore we assume this can always be valid.
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
((ICustomBlockSetting) defaultBlock).setBlock(world, x, y, z, defaultMeta);
|
||||
@@ -1455,6 +1579,13 @@ public class StructureUtility {
|
||||
return iBlockAdder.apply(t, worldBlock, worldBlock.getDamageValue(world, x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
// calling iBlockAdder can potentially modify external state
|
||||
// therefore we assume this can always be valid.
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
world.setBlock(x, y, z, defaultBlock, defaultMeta, 2);
|
||||
@@ -1510,6 +1641,13 @@ public class StructureUtility {
|
||||
return iTileAdder.apply(t, tileEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
// calling iTileAdder can potentially modify external state
|
||||
// therefore we assume this can always be valid.
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta);
|
||||
@@ -1536,6 +1674,13 @@ public class StructureUtility {
|
||||
return tileClass.isInstance(tileEntity) && iTileAdder.test(t, tileClass.cast(tileEntity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
// calling iTileAdder can potentially modify external state
|
||||
// therefore we assume this can always be valid.
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
StructureLibAPI.hintParticle(world, x, y, z, hintBlock, hintMeta);
|
||||
@@ -1569,6 +1714,11 @@ public class StructureUtility {
|
||||
return check;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return element.couldBeValid(t, world, x, y, z, trigger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return element.placeBlock(t, world, x, y, z, trigger);
|
||||
@@ -1620,6 +1770,11 @@ public class StructureUtility {
|
||||
return check;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return element.couldBeValid(t, world, x, y, z, trigger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return element.placeBlock(t, world, x, y, z, trigger);
|
||||
@@ -1678,6 +1833,13 @@ public class StructureUtility {
|
||||
return predicate.test(t) && downstream.check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
// this COULD potentially impact external state
|
||||
// but predicate really should not have side effects
|
||||
return predicate.test(t) && downstream.couldBeValid(t, world, x, y, z, trigger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return predicate.test(t) && downstream.spawnHint(t, world, x, y, z, trigger);
|
||||
@@ -1774,6 +1936,11 @@ public class StructureUtility {
|
||||
return elem.check(t.getCurrentContext(), world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return elem.couldBeValid(t.getCurrentContext(), world, x, y, z, trigger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return elem.spawnHint(t.getCurrentContext(), world, x, y, z, trigger);
|
||||
@@ -1861,6 +2028,11 @@ public class StructureUtility {
|
||||
return to.get().check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return to.get().couldBeValid(t, world, x, y, z, trigger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return to.get().placeBlock(t, world, x, y, z, trigger);
|
||||
@@ -1914,6 +2086,11 @@ public class StructureUtility {
|
||||
return to.apply(t).check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return to.apply(t).couldBeValid(t, world, x, y, z, trigger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return to.apply(t).placeBlock(t, world, x, y, z, trigger);
|
||||
@@ -2126,6 +2303,11 @@ public class StructureUtility {
|
||||
return to.apply(t, null).check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return to.apply(t, trigger).couldBeValid(t, world, x, y, z, trigger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return to.apply(t, trigger).placeBlock(t, world, x, y, z, trigger);
|
||||
@@ -2318,6 +2500,11 @@ public class StructureUtility {
|
||||
return toCheck.apply(t).check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return to.apply(t, trigger).couldBeValid(t, world, x, y, z, trigger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
return to.apply(t, trigger).placeBlock(t, world, x, y, z, trigger);
|
||||
@@ -2562,6 +2749,11 @@ public class StructureUtility {
|
||||
return backing.check(t, world, x, y, z);
|
||||
}
|
||||
|
||||
public boolean couldBeValid(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
ItemStack newTrigger = ChannelDataAccessor.withChannel(trigger, channel);
|
||||
return backing.couldBeValid(t, world, x, y, z, newTrigger);
|
||||
}
|
||||
|
||||
public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
|
||||
ItemStack newTrigger = ChannelDataAccessor.withChannel(trigger, channel);
|
||||
// We know spawnHint will only be called on client side, so the lack of player isn't quite an issue
|
||||
|
||||
Reference in new issue
Block a user