优化标靶交互
This commit is contained in:
parent
cb74fc05c8
commit
a4ed82306e
3 changed files with 31 additions and 0 deletions
|
@ -171,6 +171,10 @@ public class DPSGeneratorEntity extends LivingEntity implements GeoEntity {
|
||||||
player.addItem(new ItemStack(ModItems.DPS_GENERATOR_DEPLOYER.get()));
|
player.addItem(new ItemStack(ModItems.DPS_GENERATOR_DEPLOYER.get()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (player.getMainHandItem() != ItemStack.EMPTY) {
|
||||||
|
return InteractionResult.PASS;
|
||||||
|
}
|
||||||
|
|
||||||
this.lookAt(EntityAnchorArgument.Anchor.EYES, new Vec3((player.getX()), this.getY(), (player.getZ())));
|
this.lookAt(EntityAnchorArgument.Anchor.EYES, new Vec3((player.getX()), this.getY(), (player.getZ())));
|
||||||
this.setXRot(0);
|
this.setXRot(0);
|
||||||
this.xRotO = this.getXRot();
|
this.xRotO = this.getXRot();
|
||||||
|
|
|
@ -144,6 +144,10 @@ public class TargetEntity extends LivingEntity implements GeoEntity {
|
||||||
player.addItem(new ItemStack(ModItems.TARGET_DEPLOYER.get()));
|
player.addItem(new ItemStack(ModItems.TARGET_DEPLOYER.get()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (player.getMainHandItem() != ItemStack.EMPTY) {
|
||||||
|
return InteractionResult.PASS;
|
||||||
|
}
|
||||||
|
|
||||||
this.lookAt(EntityAnchorArgument.Anchor.EYES, new Vec3((player.getX()), this.getY(), (player.getZ())));
|
this.lookAt(EntityAnchorArgument.Anchor.EYES, new Vec3((player.getX()), this.getY(), (player.getZ())));
|
||||||
this.setXRot(0);
|
this.setXRot(0);
|
||||||
this.xRotO = this.getXRot();
|
this.xRotO = this.getXRot();
|
||||||
|
|
|
@ -9,6 +9,7 @@ import net.minecraft.stats.Stats;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResult;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.world.InteractionResultHolder;
|
import net.minecraft.world.InteractionResultHolder;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.MobSpawnType;
|
import net.minecraft.world.entity.MobSpawnType;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
|
@ -24,12 +25,16 @@ import net.minecraft.world.phys.HitResult;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class TargetDeployer extends Item {
|
public class TargetDeployer extends Item {
|
||||||
public TargetDeployer() {
|
public TargetDeployer() {
|
||||||
super(new Properties());
|
super(new Properties());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static final Predicate<Entity> IS_TARGET = e -> e instanceof TargetEntity;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull InteractionResult useOn(UseOnContext pContext) {
|
public @NotNull InteractionResult useOn(UseOnContext pContext) {
|
||||||
Level level = pContext.getLevel();
|
Level level = pContext.getLevel();
|
||||||
|
@ -47,6 +52,15 @@ public class TargetDeployer extends Item {
|
||||||
pos = blockpos.relative(direction);
|
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) {
|
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);
|
itemstack.shrink(1);
|
||||||
level.gameEvent(pContext.getPlayer(), GameEvent.ENTITY_PLACE, blockpos);
|
level.gameEvent(pContext.getPlayer(), GameEvent.ENTITY_PLACE, blockpos);
|
||||||
|
@ -69,6 +83,15 @@ public class TargetDeployer extends Item {
|
||||||
if (!(pLevel.getBlockState(blockpos).getBlock() instanceof LiquidBlock)) {
|
if (!(pLevel.getBlockState(blockpos).getBlock() instanceof LiquidBlock)) {
|
||||||
return InteractionResultHolder.pass(itemstack);
|
return InteractionResultHolder.pass(itemstack);
|
||||||
} else if (pLevel.mayInteract(pPlayer, blockpos) && pPlayer.mayUseItemAt(blockpos, blockhitresult.getDirection(), 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);
|
TargetEntity entity = ModEntities.TARGET.get().spawn((ServerLevel) pLevel, itemstack, pPlayer, blockpos, MobSpawnType.SPAWN_EGG, false, false);
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
return InteractionResultHolder.pass(itemstack);
|
return InteractionResultHolder.pass(itemstack);
|
||||||
|
|
Loading…
Add table
Reference in a new issue