调整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
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<SoundEvent> getReloadSound() {