调整GunItem类

This commit is contained in:
17146 2024-07-05 23:23:19 +08:00
parent 950dfc230e
commit b1cd7046dc

View file

@ -38,59 +38,64 @@ public abstract class GunItem extends Item {
@Override @Override
public void inventoryTick(ItemStack itemstack, Level level, Entity entity, int slot, boolean selected) { public void inventoryTick(ItemStack itemstack, Level level, Entity entity, int slot, boolean selected) {
super.inventoryTick(itemstack, level, entity, slot, selected); if (entity instanceof LivingEntity living) {
Item mainHandItem = (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getItem(); ItemStack mainHandItem = living.getMainHandItem();
CompoundTag tag = itemstack.getOrCreateTag(); if (!itemstack.is(TargetModTags.Items.GUN)) {
return;
}
if (!ItemNBTTool.getBoolean(itemstack, "init", false)) { CompoundTag tag = itemstack.getOrCreateTag();
GunsTool.initGun(level, itemstack, this.getDescriptionId().substring(this.getDescriptionId().lastIndexOf('.') + 1));
GunsTool.genUUID(itemstack);
ItemNBTTool.setBoolean(itemstack, "init", true);
}
GunsTool.pvpModeCheck(itemstack, level);
if (tag.getBoolean("draw")) { if (!ItemNBTTool.getBoolean(itemstack, "init", false)) {
tag.putBoolean("draw", false); GunsTool.initGun(level, itemstack, this.getDescriptionId().substring(this.getDescriptionId().lastIndexOf('.') + 1));
tag.putInt("draw_time", 0); GunsTool.genUUID(itemstack);
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { ItemNBTTool.setBoolean(itemstack, "init", true);
capability.zooming = false; }
capability.syncPlayerVariables(entity); GunsTool.pvpModeCheck(itemstack, level);
});
if (entity instanceof Player player) { if (tag.getBoolean("draw")) {
double weight = tag.getDouble("weight"); 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) { if (entity instanceof Player player) {
player.getCooldowns().addCooldown(itemstack.getItem(), 12); double weight = tag.getDouble("weight");
} else if (weight == 1) {
player.getCooldowns().addCooldown(itemstack.getItem(), 17); if (weight == 0) {
} else if (weight == 2) { player.getCooldowns().addCooldown(itemstack.getItem(), 12);
player.getCooldowns().addCooldown(itemstack.getItem(), 30); } 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) { if (mainHandItem.getItem() == itemstack.getItem()) {
tag.putDouble("empty", 1); 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) { if (tag.getInt("fire_animation") > 0) {
tag.putDouble("HoldOpen", 1); tag.putInt("fire_animation", (tag.getInt("fire_animation") - 1));
} }
if (itemstack.getItem() == TargetModItems.M_60.get() && tag.getInt("ammo") <= 5) { if (tag.getDouble("flash_time") > 0) {
tag.putDouble("empty", 1); 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<SoundEvent> getReloadSound() { public Set<SoundEvent> getReloadSound() {