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