From a4ed82306e0d524931ba7139ed4e634573e653c5 Mon Sep 17 00:00:00 2001 From: Light_Quanta Date: Fri, 16 May 2025 20:37:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A0=87=E9=9D=B6=E4=BA=A4?= =?UTF-8?q?=E4=BA=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/DPSGeneratorEntity.java | 4 ++++ .../superbwarfare/entity/TargetEntity.java | 4 ++++ .../superbwarfare/item/TargetDeployer.java | 23 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/DPSGeneratorEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/DPSGeneratorEntity.java index aebc9f494..d95304054 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/DPSGeneratorEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/DPSGeneratorEntity.java @@ -171,6 +171,10 @@ public class DPSGeneratorEntity extends LivingEntity implements GeoEntity { player.addItem(new ItemStack(ModItems.DPS_GENERATOR_DEPLOYER.get())); } } else { + if (player.getMainHandItem() != ItemStack.EMPTY) { + return InteractionResult.PASS; + } + this.lookAt(EntityAnchorArgument.Anchor.EYES, new Vec3((player.getX()), this.getY(), (player.getZ()))); this.setXRot(0); this.xRotO = this.getXRot(); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/TargetEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/TargetEntity.java index b016a086b..c75cd92ec 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/TargetEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/TargetEntity.java @@ -144,6 +144,10 @@ public class TargetEntity extends LivingEntity implements GeoEntity { player.addItem(new ItemStack(ModItems.TARGET_DEPLOYER.get())); } } else { + if (player.getMainHandItem() != ItemStack.EMPTY) { + return InteractionResult.PASS; + } + this.lookAt(EntityAnchorArgument.Anchor.EYES, new Vec3((player.getX()), this.getY(), (player.getZ()))); this.setXRot(0); this.xRotO = this.getXRot(); diff --git a/src/main/java/com/atsuishio/superbwarfare/item/TargetDeployer.java b/src/main/java/com/atsuishio/superbwarfare/item/TargetDeployer.java index dd9667f3d..15eee9a02 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/TargetDeployer.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/TargetDeployer.java @@ -9,6 +9,7 @@ import net.minecraft.stats.Stats; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.MobSpawnType; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; @@ -24,12 +25,16 @@ import net.minecraft.world.phys.HitResult; import org.jetbrains.annotations.NotNull; import java.util.Objects; +import java.util.function.Predicate; public class TargetDeployer extends Item { public TargetDeployer() { super(new Properties()); } + + private static final Predicate IS_TARGET = e -> e instanceof TargetEntity; + @Override public @NotNull InteractionResult useOn(UseOnContext pContext) { Level level = pContext.getLevel(); @@ -47,6 +52,15 @@ public class TargetDeployer extends Item { pos = blockpos.relative(direction); } + // 禁止堆叠 + if (!level.getEntities( + (Entity) null, + ModEntities.TARGET.get().getSpawnAABB(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), + IS_TARGET + ).isEmpty()) { + return InteractionResult.FAIL; + } + if (ModEntities.TARGET.get().spawn((ServerLevel) level, itemstack, pContext.getPlayer(), pos, MobSpawnType.SPAWN_EGG, true, !Objects.equals(blockpos, pos) && direction == Direction.UP) != null) { itemstack.shrink(1); level.gameEvent(pContext.getPlayer(), GameEvent.ENTITY_PLACE, blockpos); @@ -69,6 +83,15 @@ public class TargetDeployer extends Item { if (!(pLevel.getBlockState(blockpos).getBlock() instanceof LiquidBlock)) { return InteractionResultHolder.pass(itemstack); } else if (pLevel.mayInteract(pPlayer, blockpos) && pPlayer.mayUseItemAt(blockpos, blockhitresult.getDirection(), itemstack)) { + // 禁止堆叠 + if (!pLevel.getEntities( + (Entity) null, + ModEntities.TARGET.get().getSpawnAABB(blockpos.getX() + 0.5, blockpos.getY() + 0.5, blockpos.getZ() + 0.5), + IS_TARGET + ).isEmpty()) { + return InteractionResultHolder.fail(itemstack); + } + TargetEntity entity = ModEntities.TARGET.get().spawn((ServerLevel) pLevel, itemstack, pPlayer, blockpos, MobSpawnType.SPAWN_EGG, false, false); if (entity == null) { return InteractionResultHolder.pass(itemstack);