From b1cd7046dc28a778ac126550fa85014d96126b7f Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Fri, 5 Jul 2024 23:23:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4GunItem=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/mcreator/target/item/gun/GunItem.java | 89 ++++++++++--------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/src/main/java/net/mcreator/target/item/gun/GunItem.java b/src/main/java/net/mcreator/target/item/gun/GunItem.java index 90fc4ba73..adffe7ad4 100644 --- a/src/main/java/net/mcreator/target/item/gun/GunItem.java +++ b/src/main/java/net/mcreator/target/item/gun/GunItem.java @@ -38,59 +38,64 @@ public abstract class GunItem extends Item { @Override public void inventoryTick(ItemStack itemstack, Level level, Entity entity, int slot, boolean selected) { - super.inventoryTick(itemstack, level, entity, slot, selected); - Item mainHandItem = (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem(); - CompoundTag tag = itemstack.getOrCreateTag(); + if (entity instanceof LivingEntity living) { + ItemStack mainHandItem = living.getMainHandItem(); + if (!itemstack.is(TargetModTags.Items.GUN)) { + return; + } - if (!ItemNBTTool.getBoolean(itemstack, "init", false)) { - GunsTool.initGun(level, itemstack, this.getDescriptionId().substring(this.getDescriptionId().lastIndexOf('.') + 1)); - GunsTool.genUUID(itemstack); - ItemNBTTool.setBoolean(itemstack, "init", true); - } - GunsTool.pvpModeCheck(itemstack, level); + CompoundTag tag = itemstack.getOrCreateTag(); - if (tag.getBoolean("draw")) { - tag.putBoolean("draw", false); - tag.putInt("draw_time", 0); - entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { - capability.zooming = false; - capability.syncPlayerVariables(entity); - }); + if (!ItemNBTTool.getBoolean(itemstack, "init", false)) { + GunsTool.initGun(level, itemstack, this.getDescriptionId().substring(this.getDescriptionId().lastIndexOf('.') + 1)); + GunsTool.genUUID(itemstack); + ItemNBTTool.setBoolean(itemstack, "init", true); + } + GunsTool.pvpModeCheck(itemstack, level); - if (entity instanceof Player player) { - double weight = tag.getDouble("weight"); + if (tag.getBoolean("draw")) { + tag.putBoolean("draw", false); + tag.putInt("draw_time", 0); + entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { + capability.zooming = false; + capability.syncPlayerVariables(entity); + }); - if (weight == 0) { - player.getCooldowns().addCooldown(itemstack.getItem(), 12); - } else if (weight == 1) { - player.getCooldowns().addCooldown(itemstack.getItem(), 17); - } else if (weight == 2) { - player.getCooldowns().addCooldown(itemstack.getItem(), 30); + if (entity instanceof Player player) { + double weight = tag.getDouble("weight"); + + if (weight == 0) { + player.getCooldowns().addCooldown(itemstack.getItem(), 12); + } else if (weight == 1) { + player.getCooldowns().addCooldown(itemstack.getItem(), 17); + } else if (weight == 2) { + player.getCooldowns().addCooldown(itemstack.getItem(), 30); + } + } + + if (itemstack.getItem() == TargetModItems.RPG.get() && tag.getInt("ammo") == 0) { + tag.putDouble("empty", 1); + } + if (itemstack.getItem() == TargetModItems.SKS.get() && tag.getInt("ammo") == 0) { + tag.putDouble("HoldOpen", 1); + } + if (itemstack.getItem() == TargetModItems.M_60.get() && tag.getInt("ammo") <= 5) { + tag.putDouble("empty", 1); } } - if (itemstack.getItem() == TargetModItems.RPG.get() && tag.getInt("ammo") == 0) { - tag.putDouble("empty", 1); + if (mainHandItem.getItem() == itemstack.getItem()) { + if (tag.getInt("draw_time") < 50) { + tag.putInt("draw_time", (tag.getInt("draw_time") + 1)); + } } - if (itemstack.getItem() == TargetModItems.SKS.get() && tag.getInt("ammo") == 0) { - tag.putDouble("HoldOpen", 1); + if (tag.getInt("fire_animation") > 0) { + tag.putInt("fire_animation", (tag.getInt("fire_animation") - 1)); } - if (itemstack.getItem() == TargetModItems.M_60.get() && tag.getInt("ammo") <= 5) { - tag.putDouble("empty", 1); + if (tag.getDouble("flash_time") > 0) { + tag.putDouble("flash_time", (tag.getDouble("flash_time") - 1)); } } - - if (mainHandItem == itemstack.getItem()) { - if (tag.getInt("draw_time") < 50) { - tag.putInt("draw_time", (tag.getInt("draw_time") + 1)); - } - } - if (tag.getInt("fire_animation") > 0) { - tag.putInt("fire_animation", (tag.getInt("fire_animation") - 1)); - } - if (tag.getDouble("flash_time") > 0) { - tag.putDouble("flash_time", (tag.getDouble("flash_time") - 1)); - } } public Set getReloadSound() {