mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-28 19:39:11 +00:00
fix(block): 修复作物成熟判断
This commit is contained in:
@@ -182,8 +182,10 @@ public final class CraftEngineBlocks {
|
||||
builder.withParameter(LootParameters.PLAYER, serverPlayer);
|
||||
builder.withOptionalParameter(LootParameters.TOOL, serverPlayer.getItemInHand(InteractionHand.MAIN_HAND));
|
||||
}
|
||||
if (state.behavior() instanceof CropBlockBehavior) {
|
||||
builder.withParameter(LootParameters.CROP_BLOCK, true);
|
||||
if (state.behavior() instanceof CropBlockBehavior cropBlockBehavior) {
|
||||
if (cropBlockBehavior.isMaxAge(state)) {
|
||||
builder.withParameter(LootParameters.CROP_RIPE, true);
|
||||
}
|
||||
}
|
||||
for (Item<?> item : state.getDrops(builder, world)) {
|
||||
world.dropItemNaturally(vec3d, item);
|
||||
|
||||
@@ -139,8 +139,10 @@ public class BlockEventListener implements Listener {
|
||||
builder.withParameter(LootParameters.LOCATION, vec3d);
|
||||
builder.withParameter(LootParameters.PLAYER, serverPlayer);
|
||||
builder.withOptionalParameter(LootParameters.TOOL, itemInHand);
|
||||
if (state.behavior() instanceof CropBlockBehavior) {
|
||||
builder.withParameter(LootParameters.CROP_BLOCK, true);
|
||||
if (state.behavior() instanceof CropBlockBehavior cropBlockBehavior) {
|
||||
if (cropBlockBehavior.isMaxAge(state)) {
|
||||
builder.withParameter(LootParameters.CROP_RIPE, true);
|
||||
}
|
||||
}
|
||||
for (Item<Object> item : state.getDrops(builder, world)) {
|
||||
world.dropItemNaturally(vec3d, item);
|
||||
@@ -300,8 +302,10 @@ public class BlockEventListener implements Listener {
|
||||
if (yield < 1f) {
|
||||
builder.withParameter(LootParameters.EXPLOSION_RADIUS, 1.0f / yield);
|
||||
}
|
||||
if (state.behavior() instanceof CropBlockBehavior) {
|
||||
builder.withParameter(LootParameters.CROP_BLOCK, true);
|
||||
if (state.behavior() instanceof CropBlockBehavior cropBlockBehavior) {
|
||||
if (cropBlockBehavior.isMaxAge(state)) {
|
||||
builder.withParameter(LootParameters.CROP_RIPE, true);
|
||||
}
|
||||
}
|
||||
for (Item<Object> item : state.getDrops(builder, world)) {
|
||||
world.dropItemNaturally(vec3d, item);
|
||||
|
||||
@@ -71,8 +71,10 @@ public class BushBlockBehavior extends AbstractBlockBehavior {
|
||||
net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level));
|
||||
builder.withParameter(LootParameters.LOCATION, vec3d);
|
||||
builder.withParameter(LootParameters.WORLD, world);
|
||||
if (this instanceof CropBlockBehavior) {
|
||||
builder.withParameter(LootParameters.CROP_BLOCK, true);
|
||||
if (this instanceof CropBlockBehavior cropBlockBehavior) {
|
||||
if (cropBlockBehavior.isMaxAge(state)) {
|
||||
builder.withParameter(LootParameters.CROP_RIPE, true);
|
||||
}
|
||||
}
|
||||
for (Item<Object> item : previousState.getDrops(builder, world)) {
|
||||
world.dropItemNaturally(vec3d, item);
|
||||
|
||||
@@ -37,6 +37,9 @@ public class CropBlockBehavior extends BushBlockBehavior {
|
||||
public final boolean isMaxAge(Object state) {
|
||||
return this.getAge(state) >= this.ageProperty.max;
|
||||
}
|
||||
public final boolean isMaxAge(ImmutableBlockState state) {
|
||||
return this.getAge(state) >= this.ageProperty.max;
|
||||
}
|
||||
|
||||
public static ImmutableBlockState getCEBlockState(Object nmsState) {
|
||||
return BukkitBlockManager.instance().getImmutableBlockState(BlockStateUtils.blockStateToId(nmsState));
|
||||
@@ -45,6 +48,9 @@ public class CropBlockBehavior extends BushBlockBehavior {
|
||||
public final int getAge(Object state) {
|
||||
return getCEBlockState(state).get(ageProperty);
|
||||
}
|
||||
public final int getAge(ImmutableBlockState state) {
|
||||
return state.get(ageProperty);
|
||||
}
|
||||
|
||||
public Object getStateForAge(Object state, int age) {
|
||||
ImmutableBlockState afterState = getCEBlockState(state).owner().value().defaultState().with(ageProperty, age);
|
||||
@@ -75,8 +81,10 @@ public class CropBlockBehavior extends BushBlockBehavior {
|
||||
Object pos = args[2];
|
||||
if (getRawBrightness(level, pos) >= minGrowLight) {
|
||||
int age = this.getAge(state);
|
||||
System.out.println("age: " + age);
|
||||
if (age < this.ageProperty.max && RandomUtils.generateRandomFloat(0, 1) >= this.growSpeed) {
|
||||
float randomFloat = RandomUtils.generateRandomFloat(0, 1);
|
||||
System.out.println("age: " + age + "ageProperty.max: " + this.ageProperty.max + " -> " + (age < this.ageProperty.max));
|
||||
System.out.println("randomFloat: " + randomFloat + "growSpeed: " + this.growSpeed + " -> " + (randomFloat < this.growSpeed));
|
||||
if (age < this.ageProperty.max && randomFloat >= this.growSpeed) {
|
||||
System.out.println("grow");
|
||||
Reflections.method$Level$setBlock.invoke(level, pos, getStateForAge(state, age + 1), UpdateOption.UPDATE_NONE.flags());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user