修改控制器的逻辑
This commit is contained in:
parent
a3f437ba39
commit
5a9e9349a3
3 changed files with 225 additions and 208 deletions
|
@ -50,12 +50,12 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.BOOLEAN);
|
||||
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.STRING);
|
||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||
|
||||
private boolean swinging;
|
||||
private boolean lastloop;
|
||||
private boolean linked = false;
|
||||
private long lastSwing;
|
||||
|
||||
|
||||
public String animationprocedure = "empty";
|
||||
|
||||
public DroneEntity(PlayMessages.SpawnEntity packet, Level world) {
|
||||
|
@ -94,7 +94,7 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
|
||||
@Override
|
||||
public MobType getMobType() {
|
||||
return MobType.UNDEFINED;
|
||||
return super.getMobType();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -124,43 +124,44 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult mobInteract(Player sourceentity, InteractionHand hand) {
|
||||
super.mobInteract(sourceentity, hand);
|
||||
public InteractionResult mobInteract(Player player, InteractionHand hand) {
|
||||
super.mobInteract(player, hand);
|
||||
|
||||
ItemStack stack = sourceentity.getMainHandItem();
|
||||
ItemStack stack = player.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);
|
||||
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());
|
||||
}
|
||||
|
||||
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) {
|
||||
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 {
|
||||
sourceentity.displayClientMessage(Component.translatable("des.target.monitor.already_linked").withStyle(ChatFormatting.RED), true);
|
||||
player.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);
|
||||
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());
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,30 +2,34 @@ package net.mcreator.target.item;
|
|||
|
||||
import net.mcreator.target.tools.ItemNBTTool;
|
||||
import net.mcreator.target.tools.TooltipTool;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Monitor extends Item {
|
||||
public static final String LINKED = "Linked";
|
||||
public static final String LINKED_DRONE = "LinkedDrone";
|
||||
|
||||
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, Boolean link) {
|
||||
ItemNBTTool.setBoolean(itemstack, LINKED, link);
|
||||
public static void link(ItemStack itemstack, int id) {
|
||||
ItemNBTTool.setBoolean(itemstack, LINKED, true);
|
||||
ItemNBTTool.setInt(itemstack, LINKED_DRONE, id);
|
||||
}
|
||||
|
||||
public static void disLink(ItemStack itemstack) {
|
||||
ItemNBTTool.setBoolean(itemstack, LINKED, false);
|
||||
ItemNBTTool.setInt(itemstack, LINKED_DRONE, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, Level world, List<Component> list, TooltipFlag flag) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
TooltipTool.addMonitorTips(list, stack, player);
|
||||
TooltipTool.addMonitorTips(list, ItemNBTTool.getInt(stack, LINKED_DRONE, -1));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package net.mcreator.target.tools;
|
||||
|
||||
import net.mcreator.target.entity.DroneEntity;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
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(player.position().distanceTo(e) + " M").withStyle(ChatFormatting.GRAY));
|
||||
tooltip.add(Component.literal(player.distanceTo(entity) + " M").withStyle(ChatFormatting.GRAY));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue