9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-28 19:39:11 +00:00

refactor crops

This commit is contained in:
XiaoMoMi
2025-03-28 20:25:31 +08:00
parent 44c2316cd2
commit 736627ab8b
17 changed files with 270 additions and 143 deletions

View File

@@ -182,11 +182,6 @@ public final class CraftEngineBlocks {
builder.withParameter(LootParameters.PLAYER, serverPlayer);
builder.withOptionalParameter(LootParameters.TOOL, serverPlayer.getItemInHand(InteractionHand.MAIN_HAND));
}
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);
}

View File

@@ -139,11 +139,6 @@ 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 cropBlockBehavior) {
if (cropBlockBehavior.isMaxAge(state)) {
builder.withParameter(LootParameters.CROP_RIPE, true);
}
}
for (Item<Object> item : state.getDrops(builder, world)) {
world.dropItemNaturally(vec3d, item);
}
@@ -302,11 +297,6 @@ public class BlockEventListener implements Listener {
if (yield < 1f) {
builder.withParameter(LootParameters.EXPLOSION_RADIUS, 1.0f / yield);
}
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);
}

View File

@@ -71,11 +71,6 @@ 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 cropBlockBehavior) {
if (cropBlockBehavior.isMaxAge(state)) {
builder.withParameter(LootParameters.CROP_RIPE, true);
}
}
for (Item<Object> item : previousState.getDrops(builder, world)) {
world.dropItemNaturally(vec3d, item);
}

View File

@@ -1,6 +1,7 @@
package net.momirealms.craftengine.bukkit.block.behavior;
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
import net.momirealms.craftengine.bukkit.util.Reflections;
import net.momirealms.craftengine.core.block.CustomBlock;
@@ -37,6 +38,7 @@ 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;
}
@@ -48,6 +50,7 @@ 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);
}