修改控制器的逻辑
This commit is contained in:
parent
a3f437ba39
commit
5a9e9349a3
3 changed files with 225 additions and 208 deletions
|
@ -47,213 +47,214 @@ import net.mcreator.target.item.Monitor;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class DroneEntity extends PathfinderMob implements GeoEntity {
|
public class DroneEntity extends PathfinderMob implements GeoEntity {
|
||||||
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.BOOLEAN);
|
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.BOOLEAN);
|
||||||
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.STRING);
|
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.STRING);
|
||||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||||
private boolean swinging;
|
|
||||||
private boolean lastloop;
|
private boolean swinging;
|
||||||
private boolean linked = false;
|
private boolean lastloop;
|
||||||
private long lastSwing;
|
private boolean linked = false;
|
||||||
|
private long lastSwing;
|
||||||
|
|
||||||
|
public String animationprocedure = "empty";
|
||||||
|
|
||||||
|
public DroneEntity(PlayMessages.SpawnEntity packet, Level world) {
|
||||||
|
this(TargetModEntities.DRONE.get(), world);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DroneEntity(EntityType<DroneEntity> type, Level world) {
|
||||||
|
super(type, world);
|
||||||
|
xpReward = 0;
|
||||||
|
setNoAi(false);
|
||||||
|
setPersistenceRequired();
|
||||||
|
this.moveControl = new FlyingMoveControl(this, 10, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void defineSynchedData() {
|
||||||
|
super.defineSynchedData();
|
||||||
|
this.entityData.define(SHOOT, false);
|
||||||
|
this.entityData.define(ANIMATION, "undefined");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected float getStandingEyeHeight(Pose poseIn, EntityDimensions sizeIn) {
|
||||||
|
return 0.05F;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Packet<ClientGamePacketListener> getAddEntityPacket() {
|
||||||
|
return NetworkHooks.getEntitySpawningPacket(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PathNavigation createNavigation(Level world) {
|
||||||
|
return new FlyingPathNavigation(this, world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MobType getMobType() {
|
||||||
|
return super.getMobType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeWhenFarAway(double distanceToClosestPlayer) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean causeFallDamage(float l, float d, DamageSource source) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addAdditionalSaveData(CompoundTag compound) {
|
||||||
|
super.addAdditionalSaveData(compound);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readAdditionalSaveData(CompoundTag compound) {
|
||||||
|
super.readAdditionalSaveData(compound);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void baseTick() {
|
||||||
|
super.baseTick();
|
||||||
|
this.refreshDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InteractionResult mobInteract(Player player, InteractionHand hand) {
|
||||||
|
super.mobInteract(player, hand);
|
||||||
|
|
||||||
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
if (stack.getItem() == TargetModItems.MONITOR.get()) {
|
||||||
|
if (!player.isCrouching()) {
|
||||||
|
if (!this.linked) {
|
||||||
|
if (stack.getOrCreateTag().getBoolean("Linked")) {
|
||||||
|
player.displayClientMessage(Component.translatable("des.target.monitor.monitor_already_linked").withStyle(ChatFormatting.RED), true);
|
||||||
|
return InteractionResult.sidedSuccess(this.level().isClientSide());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getPersistentData().putString("controller", player.getStringUUID());
|
||||||
|
this.linked = true;
|
||||||
|
|
||||||
|
Monitor.link(stack, this.getId());
|
||||||
|
player.displayClientMessage(Component.translatable("des.target.monitor.linked").withStyle(ChatFormatting.GREEN), true);
|
||||||
|
|
||||||
|
if (player instanceof ServerPlayer serverPlayer) {
|
||||||
|
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), Objects.requireNonNull(ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.arrow.hit_player"))), SoundSource.PLAYERS, 0.5F, 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player.displayClientMessage(Component.translatable("des.target.monitor.already_linked").withStyle(ChatFormatting.RED), true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.linked) {
|
||||||
|
if (!stack.getOrCreateTag().getBoolean("Linked")) {
|
||||||
|
player.displayClientMessage(Component.translatable("des.target.monitor.already_linked").withStyle(ChatFormatting.RED), true);
|
||||||
|
return InteractionResult.sidedSuccess(this.level().isClientSide());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getPersistentData().putString("controller", "none");
|
||||||
|
|
||||||
|
this.linked = false;
|
||||||
|
Monitor.disLink(stack);
|
||||||
|
|
||||||
|
player.displayClientMessage(Component.translatable("des.target.monitor.unlinked").withStyle(ChatFormatting.RED), true);
|
||||||
|
if (player instanceof ServerPlayer serverPlayer) {
|
||||||
|
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), Objects.requireNonNull(ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.arrow.hit_player"))), SoundSource.PLAYERS, 0.5F, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return InteractionResult.sidedSuccess(this.level().isClientSide());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public String animationprocedure = "empty";
|
@Override
|
||||||
|
public EntityDimensions getDimensions(Pose p_33597_) {
|
||||||
|
return super.getDimensions(p_33597_).scale((float) 1);
|
||||||
|
}
|
||||||
|
|
||||||
public DroneEntity(PlayMessages.SpawnEntity packet, Level world) {
|
@Override
|
||||||
this(TargetModEntities.DRONE.get(), world);
|
protected void checkFallDamage(double y, boolean onGroundIn, BlockState state, BlockPos pos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public DroneEntity(EntityType<DroneEntity> type, Level world) {
|
@Override
|
||||||
super(type, world);
|
public void setNoGravity(boolean ignored) {
|
||||||
xpReward = 0;
|
super.setNoGravity(true);
|
||||||
setNoAi(false);
|
}
|
||||||
setPersistenceRequired();
|
|
||||||
this.moveControl = new FlyingMoveControl(this, 10, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void defineSynchedData() {
|
public void aiStep() {
|
||||||
super.defineSynchedData();
|
super.aiStep();
|
||||||
this.entityData.define(SHOOT, false);
|
this.updateSwingTime();
|
||||||
this.entityData.define(ANIMATION, "undefined");
|
this.setNoGravity(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static void init() {
|
||||||
protected float getStandingEyeHeight(Pose poseIn, EntityDimensions sizeIn) {
|
}
|
||||||
return 0.05F;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public static AttributeSupplier.Builder createAttributes() {
|
||||||
public Packet<ClientGamePacketListener> getAddEntityPacket() {
|
AttributeSupplier.Builder builder = Mob.createMobAttributes();
|
||||||
return NetworkHooks.getEntitySpawningPacket(this);
|
builder = builder.add(Attributes.MOVEMENT_SPEED, 0.1);
|
||||||
}
|
builder = builder.add(Attributes.MAX_HEALTH, 10);
|
||||||
|
builder = builder.add(Attributes.ARMOR, 0);
|
||||||
|
builder = builder.add(Attributes.ATTACK_DAMAGE, 0);
|
||||||
|
builder = builder.add(Attributes.FOLLOW_RANGE, 64);
|
||||||
|
builder = builder.add(Attributes.FLYING_SPEED, 0.1);
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
private PlayState movementPredicate(AnimationState event) {
|
||||||
protected PathNavigation createNavigation(Level world) {
|
if (this.animationprocedure.equals("empty")) {
|
||||||
return new FlyingPathNavigation(this, world);
|
if (linked) {
|
||||||
}
|
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.drone.fly"));
|
||||||
|
}
|
||||||
|
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.drone.idle"));
|
||||||
|
}
|
||||||
|
return PlayState.STOP;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
private PlayState procedurePredicate(AnimationState event) {
|
||||||
public MobType getMobType() {
|
if (!animationprocedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||||
return MobType.UNDEFINED;
|
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationprocedure));
|
||||||
}
|
if (event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
||||||
|
this.animationprocedure = "empty";
|
||||||
|
event.getController().forceAnimationReset();
|
||||||
|
}
|
||||||
|
} else if (animationprocedure.equals("empty")) {
|
||||||
|
return PlayState.STOP;
|
||||||
|
}
|
||||||
|
return PlayState.CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeWhenFarAway(double distanceToClosestPlayer) {
|
protected void tickDeath() {
|
||||||
return false;
|
++this.deathTime;
|
||||||
}
|
if (this.deathTime == 20) {
|
||||||
|
this.remove(DroneEntity.RemovalReason.KILLED);
|
||||||
|
this.dropExperience();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
public String getSyncedAnimation() {
|
||||||
public boolean causeFallDamage(float l, float d, DamageSource source) {
|
return this.entityData.get(ANIMATION);
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public void setAnimation(String animation) {
|
||||||
public void addAdditionalSaveData(CompoundTag compound) {
|
this.entityData.set(ANIMATION, animation);
|
||||||
super.addAdditionalSaveData(compound);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readAdditionalSaveData(CompoundTag compound) {
|
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
|
||||||
super.readAdditionalSaveData(compound);
|
data.add(new AnimationController<>(this, "movement", 1, this::movementPredicate));
|
||||||
}
|
data.add(new AnimationController<>(this, "procedure", 1, this::procedurePredicate));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void baseTick() {
|
public AnimatableInstanceCache getAnimatableInstanceCache() {
|
||||||
super.baseTick();
|
return this.cache;
|
||||||
this.refreshDimensions();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InteractionResult mobInteract(Player sourceentity, InteractionHand hand) {
|
|
||||||
super.mobInteract(sourceentity, hand);
|
|
||||||
|
|
||||||
ItemStack stack = sourceentity.getMainHandItem();
|
|
||||||
if (stack.getItem() == TargetModItems.MONITOR.get()) {
|
|
||||||
if (!sourceentity.isCrouching()) {
|
|
||||||
if (!linked) {
|
|
||||||
|
|
||||||
if (stack.getOrCreateTag().getBoolean("linked")) {
|
|
||||||
sourceentity.displayClientMessage(Component.translatable("des.target.monitor.monitor_already_linked").withStyle(ChatFormatting.RED), true);
|
|
||||||
return InteractionResult.sidedSuccess(this.level().isClientSide());
|
|
||||||
}
|
|
||||||
|
|
||||||
stack.getOrCreateTag().putString("link", this.getStringUUID());
|
|
||||||
this.getPersistentData().putString("controller", sourceentity.getStringUUID());
|
|
||||||
linked = true;
|
|
||||||
Monitor.link(stack,true);
|
|
||||||
sourceentity.displayClientMessage(Component.translatable("des.target.monitor.linked").withStyle(ChatFormatting.GREEN), true);
|
|
||||||
if (sourceentity instanceof ServerPlayer serverPlayer) {
|
|
||||||
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), Objects.requireNonNull(ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.arrow.hit_player"))), SoundSource.PLAYERS, 0.5F, 1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sourceentity.displayClientMessage(Component.translatable("des.target.monitor.already_linked").withStyle(ChatFormatting.RED), true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (linked) {
|
|
||||||
if (!stack.getOrCreateTag().getString("link").equals(this.getStringUUID())) {
|
|
||||||
sourceentity.displayClientMessage(Component.translatable("des.target.monitor.already_linked").withStyle(ChatFormatting.RED), true);
|
|
||||||
return InteractionResult.sidedSuccess(this.level().isClientSide());
|
|
||||||
}
|
|
||||||
|
|
||||||
stack.getOrCreateTag().putString("link", "none");
|
|
||||||
this.getPersistentData().putString("controller", "none");
|
|
||||||
linked = false;
|
|
||||||
Monitor.link(stack,false);
|
|
||||||
sourceentity.displayClientMessage(Component.translatable("des.target.monitor.unlinked").withStyle(ChatFormatting.RED), true);
|
|
||||||
if (sourceentity instanceof ServerPlayer serverPlayer) {
|
|
||||||
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), Objects.requireNonNull(ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.arrow.hit_player"))), SoundSource.PLAYERS, 0.5F, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return InteractionResult.sidedSuccess(this.level().isClientSide());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EntityDimensions getDimensions(Pose p_33597_) {
|
|
||||||
return super.getDimensions(p_33597_).scale((float) 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void checkFallDamage(double y, boolean onGroundIn, BlockState state, BlockPos pos) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setNoGravity(boolean ignored) {
|
|
||||||
super.setNoGravity(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void aiStep() {
|
|
||||||
super.aiStep();
|
|
||||||
this.updateSwingTime();
|
|
||||||
this.setNoGravity(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AttributeSupplier.Builder createAttributes() {
|
|
||||||
AttributeSupplier.Builder builder = Mob.createMobAttributes();
|
|
||||||
builder = builder.add(Attributes.MOVEMENT_SPEED, 0.1);
|
|
||||||
builder = builder.add(Attributes.MAX_HEALTH, 10);
|
|
||||||
builder = builder.add(Attributes.ARMOR, 0);
|
|
||||||
builder = builder.add(Attributes.ATTACK_DAMAGE, 0);
|
|
||||||
builder = builder.add(Attributes.FOLLOW_RANGE, 64);
|
|
||||||
builder = builder.add(Attributes.FLYING_SPEED, 0.1);
|
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
private PlayState movementPredicate(AnimationState event) {
|
|
||||||
if (this.animationprocedure.equals("empty")) {
|
|
||||||
if (linked) {
|
|
||||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.drone.fly"));
|
|
||||||
}
|
|
||||||
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.drone.idle"));
|
|
||||||
}
|
|
||||||
return PlayState.STOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
private PlayState procedurePredicate(AnimationState event) {
|
|
||||||
if (!animationprocedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
|
||||||
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationprocedure));
|
|
||||||
if (event.getController().getAnimationState() == AnimationController.State.STOPPED) {
|
|
||||||
this.animationprocedure = "empty";
|
|
||||||
event.getController().forceAnimationReset();
|
|
||||||
}
|
|
||||||
} else if (animationprocedure.equals("empty")) {
|
|
||||||
return PlayState.STOP;
|
|
||||||
}
|
|
||||||
return PlayState.CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void tickDeath() {
|
|
||||||
++this.deathTime;
|
|
||||||
if (this.deathTime == 20) {
|
|
||||||
this.remove(DroneEntity.RemovalReason.KILLED);
|
|
||||||
this.dropExperience();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSyncedAnimation() {
|
|
||||||
return this.entityData.get(ANIMATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAnimation(String animation) {
|
|
||||||
this.entityData.set(ANIMATION, animation);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
|
|
||||||
data.add(new AnimationController<>(this, "movement", 1, this::movementPredicate));
|
|
||||||
data.add(new AnimationController<>(this, "procedure", 1, this::procedurePredicate));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AnimatableInstanceCache getAnimatableInstanceCache() {
|
|
||||||
return this.cache;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,30 +2,34 @@ package net.mcreator.target.item;
|
||||||
|
|
||||||
import net.mcreator.target.tools.ItemNBTTool;
|
import net.mcreator.target.tools.ItemNBTTool;
|
||||||
import net.mcreator.target.tools.TooltipTool;
|
import net.mcreator.target.tools.TooltipTool;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.Rarity;
|
|
||||||
import net.minecraft.world.item.TooltipFlag;
|
import net.minecraft.world.item.TooltipFlag;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Monitor extends Item {
|
public class Monitor extends Item {
|
||||||
|
public static final String LINKED = "Linked";
|
||||||
|
public static final String LINKED_DRONE = "LinkedDrone";
|
||||||
|
|
||||||
public Monitor() {
|
public Monitor() {
|
||||||
super(new Properties().stacksTo(1).rarity(Rarity.COMMON));
|
super(new Properties().stacksTo(1));
|
||||||
}
|
}
|
||||||
public static final String LINKED = "linked";
|
|
||||||
|
|
||||||
|
public static void link(ItemStack itemstack, int id) {
|
||||||
public static void link(ItemStack itemstack, Boolean link) {
|
ItemNBTTool.setBoolean(itemstack, LINKED, true);
|
||||||
ItemNBTTool.setBoolean(itemstack, LINKED, link);
|
ItemNBTTool.setInt(itemstack, LINKED_DRONE, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void disLink(ItemStack itemstack) {
|
||||||
|
ItemNBTTool.setBoolean(itemstack, LINKED, false);
|
||||||
|
ItemNBTTool.setInt(itemstack, LINKED_DRONE, -1);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendHoverText(ItemStack stack, Level world, List<Component> list, TooltipFlag flag) {
|
public void appendHoverText(ItemStack stack, Level world, List<Component> list, TooltipFlag flag) {
|
||||||
Player player = Minecraft.getInstance().player;
|
TooltipTool.addMonitorTips(list, ItemNBTTool.getInt(stack, LINKED_DRONE, -1));
|
||||||
TooltipTool.addMonitorTips(list, stack, player);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package net.mcreator.target.tools;
|
package net.mcreator.target.tools;
|
||||||
|
|
||||||
|
import net.mcreator.target.entity.DroneEntity;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||||
|
@ -116,10 +119,19 @@ public class TooltipTool {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addMonitorTips(List<Component> tooltip, ItemStack stack, Player player) {
|
public static void addMonitorTips(List<Component> tooltip, int id) {
|
||||||
|
if (id == -1) return;
|
||||||
|
|
||||||
|
Player player = Minecraft.getInstance().player;
|
||||||
|
if (player == null) return;
|
||||||
|
|
||||||
|
Entity entity = player.level().getEntity(id);
|
||||||
|
if (entity == null) return;
|
||||||
|
|
||||||
|
if (!(entity instanceof DroneEntity)) return;
|
||||||
|
|
||||||
tooltip.add(Component.literal(""));
|
tooltip.add(Component.literal(""));
|
||||||
|
|
||||||
|
tooltip.add(Component.literal(player.distanceTo(entity) + " M").withStyle(ChatFormatting.GRAY));
|
||||||
tooltip.add(Component.literal(player.position().distanceTo(e) + " M").withStyle(ChatFormatting.GRAY));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue