mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-06 15:52:03 +00:00
feat(BushBlockBehavior): max-height
This commit is contained in:
@@ -26,13 +26,13 @@ public class BushBlockBehavior extends AbstractCanSurviveBlockBehavior {
|
||||
protected final Set<String> customBlocksCansSurviveOn;
|
||||
protected final boolean blacklistMode;
|
||||
protected final boolean stackable;
|
||||
protected final int stackableAmount;
|
||||
protected final int maxHeight;
|
||||
|
||||
public BushBlockBehavior(CustomBlock block, int delay, boolean blacklist, boolean stackable, int stackableAmount, List<Object> tagsCanSurviveOn, Set<Object> blockStatesCanSurviveOn, Set<String> customBlocksCansSurviveOn) {
|
||||
public BushBlockBehavior(CustomBlock block, int delay, boolean blacklist, boolean stackable, int maxHeight, List<Object> tagsCanSurviveOn, Set<Object> blockStatesCanSurviveOn, Set<String> customBlocksCansSurviveOn) {
|
||||
super(block, delay);
|
||||
this.blacklistMode = blacklist;
|
||||
this.stackable = stackable;
|
||||
this.stackableAmount = stackableAmount;
|
||||
this.maxHeight = maxHeight;
|
||||
this.tagsCanSurviveOn = tagsCanSurviveOn;
|
||||
this.blockStatesCanSurviveOn = blockStatesCanSurviveOn;
|
||||
this.customBlocksCansSurviveOn = customBlocksCansSurviveOn;
|
||||
@@ -44,10 +44,10 @@ public class BushBlockBehavior extends AbstractCanSurviveBlockBehavior {
|
||||
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
|
||||
Tuple<List<Object>, Set<Object>, Set<String>> tuple = readTagsAndState(arguments, false);
|
||||
boolean stackable = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("stackable", false), "stackable");
|
||||
int stackableAmount = ResourceConfigUtils.getAsInt(arguments.getOrDefault("stackable-amount", 0), "stackable-amount");
|
||||
int maxHeight = ResourceConfigUtils.getAsInt(arguments.getOrDefault("max-height", 0), "max-height");
|
||||
int delay = ResourceConfigUtils.getAsInt(arguments.getOrDefault("delay", 0), "delay");
|
||||
boolean blacklistMode = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("blacklist", false), "blacklist");
|
||||
return new BushBlockBehavior(block, delay, blacklistMode, stackable, stackableAmount,tuple.left(), tuple.mid(), tuple.right());
|
||||
return new BushBlockBehavior(block, delay, blacklistMode, stackable, maxHeight,tuple.left(), tuple.mid(), tuple.right());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,8 +99,8 @@ public class BushBlockBehavior extends AbstractCanSurviveBlockBehavior {
|
||||
} else {
|
||||
ImmutableBlockState belowCustomState = optionalCustomState.get();
|
||||
if (belowCustomState.owner().value() == super.customBlock) {
|
||||
if (!stackable) return false;
|
||||
if (this.stackableAmount > 0) {
|
||||
if (!this.stackable || this.maxHeight == 1) return false;
|
||||
if (this.maxHeight > 1) {
|
||||
return mayStackOn(world, belowPos);
|
||||
}
|
||||
return true;
|
||||
@@ -116,10 +116,10 @@ public class BushBlockBehavior extends AbstractCanSurviveBlockBehavior {
|
||||
}
|
||||
|
||||
protected boolean mayStackOn(Object world, Object belowPos) {
|
||||
int count = 0;
|
||||
Object cursorPos = belowPos;
|
||||
int count = 1;
|
||||
Object cursorPos = LocationUtils.below(belowPos);
|
||||
|
||||
while (count <= this.stackableAmount) {
|
||||
while (count < this.maxHeight) {
|
||||
Object belowState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(world, cursorPos);
|
||||
Optional<ImmutableBlockState> belowCustomState = BlockStateUtils.getOptionalCustomBlockState(belowState);
|
||||
if (belowCustomState.isPresent() && belowCustomState.get().owner().value() == super.customBlock) {
|
||||
@@ -129,6 +129,6 @@ public class BushBlockBehavior extends AbstractCanSurviveBlockBehavior {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return count <= this.stackableAmount;
|
||||
return count < this.maxHeight;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user