调整GunItem类

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

View file

@ -38,8 +38,12 @@ 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();
if (entity instanceof LivingEntity living) {
ItemStack mainHandItem = living.getMainHandItem();
if (!itemstack.is(TargetModTags.Items.GUN)) {
return;
}
CompoundTag tag = itemstack.getOrCreateTag();
if (!ItemNBTTool.getBoolean(itemstack, "init", false)) {
@ -80,7 +84,7 @@ public abstract class GunItem extends Item {
}
}
if (mainHandItem == itemstack.getItem()) {
if (mainHandItem.getItem() == itemstack.getItem()) {
if (tag.getInt("draw_time") < 50) {
tag.putInt("draw_time", (tag.getInt("draw_time") + 1));
}
@ -92,6 +96,7 @@ public abstract class GunItem extends Item {
tag.putDouble("flash_time", (tag.getDouble("flash_time") - 1));
}
}
}
public Set<SoundEvent> getReloadSound() {
return Set.of();