Compare commits

...
4 Commits
Author SHA1 Message Date
Glease c19ac860d4 fix too lenient should skip check in ofBlocksTiered 2022-08-12 21:13:32 +08:00
Glease d33cdd79c4 apply spotless 2022-08-12 12:31:46 +08:00
Glease ed24f15033 migrate iterate to iterateV2 2022-08-12 12:25:03 +08:00
Glease 15c34061bc suppress even more logging 2022-08-12 12:07:30 +08:00
5 changed files with 98 additions and 127 deletions

No files matched your search

@@ -76,11 +76,9 @@ public class ConstructableUtility {
} else if (constructable instanceof ISurvivalConstructable) {
int built = ((ISurvivalConstructable) constructable)
.survivalConstruct(aStack, BUDGET, IItemSource.fromPlayer(playerMP), playerMP);
if (built > 0)
// TODO somehow notify extensions that their inventory might have been modified and need to be
// synced to client or saved
playerMP.inventory.markDirty();
else if (built == -1) {
if (built > 0) {
playerMP.addChatMessage(new ChatComponentTranslation("structurelib.autoplace.built_stat", built));
} else if (built == -1) {
playerMP.addChatMessage(new ChatComponentTranslation("structurelib.autoplace.complete"));
}
setLastUseTickToStackTag(aStack);
@@ -1,10 +1,11 @@
package com.gtnewhorizon.structurelib.structure;
import static com.gtnewhorizon.structurelib.StructureLib.DEBUG_MODE;
import static com.gtnewhorizon.structurelib.structure.IStructureWalker.ignoreBlockUnloaded;
import static com.gtnewhorizon.structurelib.structure.IStructureWalker.skipBlockUnloaded;
import com.gtnewhorizon.structurelib.StructureLib;
import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing;
import java.util.Arrays;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
@@ -196,135 +197,67 @@ public interface IStructureDefinition<T> {
return false;
}
// change base position to base offset
basePositionA = -basePositionA;
basePositionB = -basePositionB;
basePositionC = -basePositionC;
int[] abc = new int[] {basePositionA, basePositionB, basePositionC};
int[] xyz = new int[3];
if (checkBlocksIfNotNullForceCheckAllIfTrue != null) {
boolean success;
if (checkBlocksIfNotNullForceCheckAllIfTrue) {
for (IStructureElement<T> element : elements) {
if (element.isNavigating()) {
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC();
} else {
extendedFacing.getWorldOffset(abc, xyz);
xyz[0] += basePositionX;
xyz[1] += basePositionY;
xyz[2] += basePositionZ;
StructureLib.LOGGER.info(
"Multi [{}, {}, {}] step @ {} {}",
basePositionX,
basePositionY,
basePositionZ,
Arrays.toString(xyz),
Arrays.toString(abc));
if (world.blockExists(xyz[0], xyz[1], xyz[2])) {
if (!element.check(object, world, xyz[0], xyz[1], xyz[2])) {
if (DEBUG_MODE) {
StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", "
+ basePositionZ + "] failed @ " + Arrays.toString(xyz) + " "
+ Arrays.toString(abc));
}
return false;
}
} else {
if (DEBUG_MODE) {
StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", "
+ basePositionZ + "] !blockExists @ " + Arrays.toString(xyz) + " "
+ Arrays.toString(abc));
}
return false;
}
abc[0] += 1;
}
}
success = StructureUtility.iterateV2(
elements,
world,
extendedFacing,
basePositionX,
basePositionY,
basePositionZ,
basePositionA,
basePositionB,
basePositionC,
(e, w, x, y, z) -> e.check(object, w, x, y, z),
"check");
} else {
for (IStructureElement<T> element : elements) {
if (element.isNavigating()) {
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC();
} else {
extendedFacing.getWorldOffset(abc, xyz);
xyz[0] += basePositionX;
xyz[1] += basePositionY;
xyz[2] += basePositionZ;
StructureLib.LOGGER.info(
"Multi [{}, {}, {}] step @ {} {}",
basePositionX,
basePositionY,
basePositionZ,
Arrays.toString(xyz),
Arrays.toString(abc));
if (world.blockExists(xyz[0], xyz[1], xyz[2])) {
if (!element.check(object, world, xyz[0], xyz[1], xyz[2])) {
if (DEBUG_MODE) {
StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", "
+ basePositionZ + "] failed @ " + Arrays.toString(xyz) + " "
+ Arrays.toString(abc));
}
return false;
}
} else {
if (DEBUG_MODE) {
StructureLib.LOGGER.info("Multi [" + basePositionX + ", " + basePositionY + ", "
+ basePositionZ + "] !blockExists @ " + Arrays.toString(xyz) + " "
+ Arrays.toString(abc));
}
}
abc[0] += 1;
}
}
success = StructureUtility.iterateV2(
elements,
world,
extendedFacing,
basePositionX,
basePositionY,
basePositionZ,
basePositionA,
basePositionB,
basePositionC,
skipBlockUnloaded((e, w, x, y, z) -> e.check(object, w, x, y, z)),
"check force");
}
if (DEBUG_MODE) {
if (DEBUG_MODE && success) {
StructureLib.LOGGER.info(
"Multi [" + basePositionX + ", " + basePositionY + ", " + basePositionZ + "] pass");
}
return success;
} else {
if (hintsOnly) {
for (IStructureElement<T> element : elements) {
if (element.isNavigating()) {
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC();
} else {
extendedFacing.getWorldOffset(abc, xyz);
xyz[0] += basePositionX;
xyz[1] += basePositionY;
xyz[2] += basePositionZ;
element.spawnHint(object, world, xyz[0], xyz[1], xyz[2], trigger);
abc[0] += 1;
}
}
StructureUtility.iterateV2(
elements,
world,
extendedFacing,
basePositionX,
basePositionY,
basePositionZ,
basePositionA,
basePositionB,
basePositionC,
ignoreBlockUnloaded((e, w, x, y, z) -> e.spawnHint(object, world, x, y, z, trigger)),
"spawnHint");
} else {
for (IStructureElement<T> element : elements) {
if (element.isNavigating()) {
abc[0] = (element.resetA() ? basePositionA : abc[0]) + element.getStepA();
abc[1] = (element.resetB() ? basePositionB : abc[1]) + element.getStepB();
abc[2] = (element.resetC() ? basePositionC : abc[2]) + element.getStepC();
} else {
extendedFacing.getWorldOffset(abc, xyz);
xyz[0] += basePositionX;
xyz[1] += basePositionY;
xyz[2] += basePositionZ;
if (world.blockExists(xyz[0], xyz[1], xyz[2])) {
element.placeBlock(object, world, xyz[0], xyz[1], xyz[2], trigger);
}
abc[0] += 1;
}
}
StructureUtility.iterateV2(
elements,
world,
extendedFacing,
basePositionX,
basePositionY,
basePositionZ,
basePositionA,
basePositionB,
basePositionC,
ignoreBlockUnloaded((e, w, x, y, z) -> e.placeBlock(object, world, x, y, z, trigger)),
"placeBlock");
}
}
return true;
@@ -4,4 +4,36 @@ import net.minecraft.world.World;
public interface IStructureWalker<T> {
boolean visit(IStructureElement<T> element, World world, int x, int y, int z);
default boolean blockNotLoaded(IStructureElement<T> element, World world, int x, int y, int z) {
return false;
}
static <T> IStructureWalker<T> ignoreBlockUnloaded(IStructureWalker<T> walker) {
return new IStructureWalker<T>() {
@Override
public boolean visit(IStructureElement<T> element, World world, int x, int y, int z) {
return walker.visit(element, world, x, y, z);
}
@Override
public boolean blockNotLoaded(IStructureElement<T> element, World world, int x, int y, int z) {
return walker.visit(element, world, x, y, z);
}
};
}
static <T> IStructureWalker<T> skipBlockUnloaded(IStructureWalker<T> walker) {
return new IStructureWalker<T>() {
@Override
public boolean visit(IStructureElement<T> element, World world, int x, int y, int z) {
return walker.visit(element, world, x, y, z);
}
@Override
public boolean blockNotLoaded(IStructureElement<T> element, World world, int x, int y, int z) {
return true;
}
};
}
}
@@ -427,9 +427,16 @@ public class StructureUtility {
IItemSource s,
EntityPlayerMP actor,
Consumer<IChatComponent> chatter) {
if (check(t, world, x, y, z)) return PlaceResult.SKIP;
Pair<Block, Integer> hint = getHint(trigger);
if (hint == null) return PlaceResult.REJECT; // TODO or SKIP?
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
TIER tier = tierExtractor.convert(block, meta);
if (!Objects.equals(tier, notSet)) {
return Objects.equals(tier, tierExtractor.convert(hint.getKey(), hint.getValue()))
? PlaceResult.SKIP
: PlaceResult.REJECT;
}
return StructureUtility.survivalPlaceBlock(
hint.getKey(), hint.getValue(), world, x, y, z, s, actor, chatter);
}
@@ -2244,7 +2251,7 @@ public class StructureUtility {
Arrays.toString(xyz),
Arrays.toString(abc));
}
return false;
if (!predicate.blockNotLoaded(element, world, xyz[0], xyz[1], xyz[2])) return false;
}
abc[0] += 1;
}
@@ -28,6 +28,7 @@ item.structurelib.constructableTrigger.desc.3=(Sneak use on controller to build)
item.structurelib.constructableTrigger.desc.4=Quantity of schematics in item stack affects tier/mode/type
item.structurelib.constructableTrigger.too_fast=Please wait %d ticks before another autoplace...
structurelib.autoplace.built_stat=Built %s blocks
structurelib.autoplace.complete=§aThis multiblock has completed!
structurelib.autoplace.error.not_enabled=§cThis multiblock does not support autoplace in survival!
structurelib.autoplace.error.no_simple_block=§cSuggested to place §r%s§c but none was found