mirror of
https://github.com/GTNewHorizons/StructureLib.git
synced 2026-11-21 04:22:09 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
287e8317c9 |
No files matched your search
@@ -96,7 +96,7 @@ public interface IStructureElement<T> {
|
|||||||
"Default implementation of survivalPlaceBlock hit! Things aren't going to work well! IStructureElement class: {}",
|
"Default implementation of survivalPlaceBlock hit! Things aren't going to work well! IStructureElement class: {}",
|
||||||
getClass().getName());
|
getClass().getName());
|
||||||
if (!StructureLibAPI.isBlockTriviallyReplaceable(world, x, y, z, actor)) return PlaceResult.REJECT;
|
if (!StructureLibAPI.isBlockTriviallyReplaceable(world, x, y, z, actor)) return PlaceResult.REJECT;
|
||||||
return PlaceResult.SKIP;
|
return PlaceResult.REJECT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,7 +206,7 @@ public interface IStructureElement<T> {
|
|||||||
if (StructureLibAPI.isDebugEnabled()) LOGGER.info(
|
if (StructureLibAPI.isDebugEnabled()) LOGGER.info(
|
||||||
"Fallback shim code of survivalPlaceBlock hit! Things aren't going to work well! IStructureElement class: {}",
|
"Fallback shim code of survivalPlaceBlock hit! Things aren't going to work well! IStructureElement class: {}",
|
||||||
getClass().getName());
|
getClass().getName());
|
||||||
return PlaceResult.SKIP;
|
return PlaceResult.REJECT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -268,16 +268,21 @@ public interface IStructureElement<T> {
|
|||||||
|
|
||||||
enum PlaceResult {
|
enum PlaceResult {
|
||||||
/**
|
/**
|
||||||
* This element either exists already, or does not yet have an implementation for survivalPlaceBlock, or some
|
* The element's check passed, the position is already valid. No placement is needed. In the walker: continue
|
||||||
* other unforeseen situations. TODO this definition doesn't seem right. Should we separate SKIP from EXISTS, or
|
* iteration (no error, not counted as placed). In ofChain: short-circuits, remaining alternatives are skipped.
|
||||||
* SKIP from ERROR?
|
|
||||||
*/
|
*/
|
||||||
SKIP,
|
SKIP,
|
||||||
/**
|
/**
|
||||||
* This element's space is occupied by other stuff and require player attention, or player missing required
|
* The element cannot handle this position (occupied, missing resources, etc.). In the walker: stop iteration
|
||||||
* resource, or the block cannot be placed due to obscure mechanisms, or some other unforeseen situations.
|
* with error particles. In ofChain: try next alternative.
|
||||||
*/
|
*/
|
||||||
REJECT,
|
REJECT,
|
||||||
|
/**
|
||||||
|
* This element has no survivalPlaceBlock implementation (default fallback), or otherwise cannot place but is
|
||||||
|
* not an error condition. In the walker: continue iteration silently (like SKIP). In ofChain: try next
|
||||||
|
* alternative (like REJECT), so a better-suited element can handle it.
|
||||||
|
*/
|
||||||
|
REJECT_CONTINUE,
|
||||||
/**
|
/**
|
||||||
* Autoplace cannot proceed within this tick. To proceed further would require stopping the placement and wait
|
* Autoplace cannot proceed within this tick. To proceed further would require stopping the placement and wait
|
||||||
* for next round.
|
* for next round.
|
||||||
|
|||||||
@@ -97,47 +97,51 @@ public interface IStructureElementChain<T> extends IStructureElement<T> {
|
|||||||
@Override
|
@Override
|
||||||
default PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger, IItemSource s,
|
default PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger, IItemSource s,
|
||||||
EntityPlayerMP actor, Consumer<IChatComponent> chatter) {
|
EntityPlayerMP actor, Consumer<IChatComponent> chatter) {
|
||||||
boolean haveSkip = false;
|
boolean allContinue = true;
|
||||||
List<IChatComponent> bufferedNoise = new ArrayList<>();
|
List<IChatComponent> bufferedNoise = new ArrayList<>();
|
||||||
for (IStructureElement<T> fallback : fallbacks()) {
|
for (IStructureElement<T> fallback : fallbacks()) {
|
||||||
PlaceResult result = fallback.survivalPlaceBlock(t, world, x, y, z, trigger, s, actor, bufferedNoise::add);
|
PlaceResult result = fallback.survivalPlaceBlock(t, world, x, y, z, trigger, s, actor, bufferedNoise::add);
|
||||||
switch (result) {
|
switch (result) {
|
||||||
|
case REJECT_CONTINUE:
|
||||||
|
break;
|
||||||
case REJECT:
|
case REJECT:
|
||||||
|
allContinue = false;
|
||||||
break;
|
break;
|
||||||
case SKIP:
|
case SKIP:
|
||||||
haveSkip = true;
|
bufferedNoise.forEach(chatter);
|
||||||
break;
|
return PlaceResult.SKIP;
|
||||||
default:
|
default:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// dump all that noise back into upstream
|
// dump all that noise back into upstream
|
||||||
bufferedNoise.forEach(chatter);
|
bufferedNoise.forEach(chatter);
|
||||||
// TODO need reconsider to ensure this is the right course of action
|
return allContinue ? PlaceResult.REJECT_CONTINUE : PlaceResult.REJECT;
|
||||||
return haveSkip ? PlaceResult.SKIP : PlaceResult.REJECT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger,
|
default PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger,
|
||||||
AutoPlaceEnvironment env) {
|
AutoPlaceEnvironment env) {
|
||||||
boolean haveSkip = false;
|
boolean allContinue = true;
|
||||||
List<IChatComponent> bufferedNoise = new ArrayList<>();
|
List<IChatComponent> bufferedNoise = new ArrayList<>();
|
||||||
for (IStructureElement<T> fallback : fallbacks()) {
|
for (IStructureElement<T> fallback : fallbacks()) {
|
||||||
PlaceResult result = fallback
|
PlaceResult result = fallback
|
||||||
.survivalPlaceBlock(t, world, x, y, z, trigger, env.withChatter(bufferedNoise::add));
|
.survivalPlaceBlock(t, world, x, y, z, trigger, env.withChatter(bufferedNoise::add));
|
||||||
switch (result) {
|
switch (result) {
|
||||||
|
case REJECT_CONTINUE:
|
||||||
|
break;
|
||||||
case REJECT:
|
case REJECT:
|
||||||
|
allContinue = false;
|
||||||
break;
|
break;
|
||||||
case SKIP:
|
case SKIP:
|
||||||
haveSkip = true;
|
bufferedNoise.forEach(env.getChatter());
|
||||||
break;
|
return PlaceResult.SKIP;
|
||||||
default:
|
default:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// dump all that noise back into upstream
|
// dump all that noise back into upstream
|
||||||
bufferedNoise.forEach(env.getChatter());
|
bufferedNoise.forEach(env.getChatter());
|
||||||
// TODO need reconsider to ensure this is the right course of action
|
return allContinue ? PlaceResult.REJECT_CONTINUE : PlaceResult.REJECT;
|
||||||
return haveSkip ? PlaceResult.SKIP : PlaceResult.REJECT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -27,12 +27,12 @@ public interface IStructureElementCheckOnly<T> extends IStructureElement<T> {
|
|||||||
@Override
|
@Override
|
||||||
default PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger, IItemSource s,
|
default PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger, IItemSource s,
|
||||||
EntityPlayerMP actor, Consumer<IChatComponent> chatter) {
|
EntityPlayerMP actor, Consumer<IChatComponent> chatter) {
|
||||||
return PlaceResult.SKIP;
|
return PlaceResult.REJECT_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger,
|
default PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger,
|
||||||
AutoPlaceEnvironment env) {
|
AutoPlaceEnvironment env) {
|
||||||
return PlaceResult.SKIP;
|
return PlaceResult.REJECT_CONTINUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -791,7 +791,7 @@ public class StructureUtility {
|
|||||||
public PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger,
|
public PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger,
|
||||||
AutoPlaceEnvironment env) {
|
AutoPlaceEnvironment env) {
|
||||||
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;
|
||||||
Block block = world.getBlock(x, y, z);
|
Block block = world.getBlock(x, y, z);
|
||||||
int meta = world.getBlockMetadata(x, y, z);
|
int meta = world.getBlockMetadata(x, y, z);
|
||||||
TIER tier = tierExtractor.convert(block, meta);
|
TIER tier = tierExtractor.convert(block, meta);
|
||||||
@@ -2032,11 +2032,11 @@ public class StructureUtility {
|
|||||||
/**
|
/**
|
||||||
* Enable this structure element only if given predicate returns true.
|
* Enable this structure element only if given predicate returns true.
|
||||||
* <p>
|
* <p>
|
||||||
* Return SKIP when survival auto place if given predicate returns false.
|
* Return REJECT_CONTINUE when survival auto place if given predicate returns false.
|
||||||
*/
|
*/
|
||||||
public static <T> IStructureElement<T> onlyIf(Predicate<? super T> predicate,
|
public static <T> IStructureElement<T> onlyIf(Predicate<? super T> predicate,
|
||||||
IStructureElement<? super T> downstream) {
|
IStructureElement<? super T> downstream) {
|
||||||
return onlyIf(predicate, downstream, PlaceResult.SKIP);
|
return onlyIf(predicate, downstream, PlaceResult.REJECT_CONTINUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2111,10 +2111,10 @@ public class StructureUtility {
|
|||||||
* using {@link #isAir()}. It will not attempt to capture any errors though, so next one will not be tried if
|
* using {@link #isAir()}. It will not attempt to capture any errors though, so next one will not be tried if
|
||||||
* previous one would crash.
|
* previous one would crash.
|
||||||
* <p>
|
* <p>
|
||||||
* (*): For survival auto place, it will * REJECT, if all structure element REJECT * SKIP, if 1 or more structure
|
* (*): For survival auto place, it will: REJECT, if any structure element returns REJECT (and none returned ACCEPT,
|
||||||
* element SKIP and the rest structure element (0 or more) REJECT * any other result, **immediately** upon any
|
* STOP, ACCEPT_STOP, or SKIP); REJECT_CONTINUE, if all structure elements return REJECT_CONTINUE (none returned
|
||||||
* structure element returns these other results. This behavior is not 100% fixed and might change later on, but we
|
* REJECT); SKIP, as soon as any structure element returns SKIP; any other result, immediately upon any structure
|
||||||
* will send the notice on a best effort basis.
|
* element returning those.
|
||||||
* <p>
|
* <p>
|
||||||
* Take care while chaining, as it will try to call every structure element until it returns true. If none does it
|
* Take care while chaining, as it will try to call every structure element until it returns true. If none does it
|
||||||
* will finally return false.
|
* will finally return false.
|
||||||
|
|||||||
+2
-1
@@ -43,9 +43,10 @@ class SurvivalBuildStructureWalker<T> implements IStructureWalker<T> {
|
|||||||
env.offsetABC[2] = c;
|
env.offsetABC[2] = c;
|
||||||
env.setSource(params.getSource());
|
env.setSource(params.getSource());
|
||||||
PlaceResult placeResult = element.survivalPlaceBlock(object, world, x, y, z, trigger, env);
|
PlaceResult placeResult = element.survivalPlaceBlock(object, world, x, y, z, trigger, env);
|
||||||
if (placeResult != PlaceResult.SKIP && built == -1) built = 0;
|
if (placeResult != PlaceResult.SKIP && placeResult != PlaceResult.REJECT_CONTINUE && built == -1) built = 0;
|
||||||
switch (placeResult) {
|
switch (placeResult) {
|
||||||
case SKIP:
|
case SKIP:
|
||||||
|
case REJECT_CONTINUE:
|
||||||
return true;
|
return true;
|
||||||
case ACCEPT:
|
case ACCEPT:
|
||||||
if (check) element.check(object, world, x, y, z);
|
if (check) element.check(object, world, x, y, z);
|
||||||
|
|||||||
Reference in new issue
Block a user