优化了冷却的实现方式
This commit is contained in:
parent
525b960e89
commit
0ba2ee83b3
2 changed files with 23 additions and 27 deletions
|
@ -144,17 +144,26 @@ public class LivingEventHandler {
|
||||||
ItemStack oldStack = event.getFrom();
|
ItemStack oldStack = event.getFrom();
|
||||||
ItemStack newStack = event.getTo();
|
ItemStack newStack = event.getTo();
|
||||||
|
|
||||||
|
|
||||||
if (player instanceof ServerPlayer serverPlayer) {
|
if (player instanceof ServerPlayer serverPlayer) {
|
||||||
|
|
||||||
if (newStack.getItem() != oldStack.getItem()
|
if (newStack.getItem() != oldStack.getItem()
|
||||||
|| newStack.getTag() == null || oldStack.getTag() == null
|
|| newStack.getTag() == null || oldStack.getTag() == null
|
||||||
|| !newStack.getTag().hasUUID("gun_uuid") || !oldStack.getTag().hasUUID("gun_uuid")
|
|| !newStack.getTag().hasUUID("gun_uuid") || !oldStack.getTag().hasUUID("gun_uuid")
|
||||||
|| !newStack.getTag().getUUID("gun_uuid").equals(oldStack.getTag().getUUID("gun_uuid"))
|
|| !newStack.getTag().getUUID("gun_uuid").equals(oldStack.getTag().getUUID("gun_uuid"))
|
||||||
) {
|
) {
|
||||||
|
if (oldStack.getItem() instanceof GunItem oldGun) {
|
||||||
|
stopGunReloadSound(serverPlayer, oldGun);
|
||||||
|
|
||||||
if (!newStack.is(TargetModTags.Items.GUN)) {
|
if (oldStack.getTag() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var oldTags = oldStack.getTag();
|
||||||
|
|
||||||
|
if (oldTags.getInt("bolt_action_time") > 0) {
|
||||||
|
oldTags.putInt("bolt_action_anim", 0);
|
||||||
|
}
|
||||||
|
oldTags.putBoolean("is_normal_reloading", false);
|
||||||
|
oldTags.putBoolean("is_empty_reloading", false);
|
||||||
|
oldTags.putInt("gun_reloading_time", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newStack.getItem() instanceof GunItem) {
|
if (newStack.getItem() instanceof GunItem) {
|
||||||
|
@ -162,19 +171,19 @@ public class LivingEventHandler {
|
||||||
if (newStack.getOrCreateTag().getInt("bolt_action_time") > 0) {
|
if (newStack.getOrCreateTag().getInt("bolt_action_time") > 0) {
|
||||||
newStack.getOrCreateTag().putInt("bolt_action_anim", 0);
|
newStack.getOrCreateTag().putInt("bolt_action_anim", 0);
|
||||||
}
|
}
|
||||||
newStack.getOrCreateTag().putBoolean("is_normal_reloading",false);
|
newStack.getOrCreateTag().putBoolean("is_normal_reloading", false);
|
||||||
newStack.getOrCreateTag().putBoolean("is_empty_reloading",false);
|
newStack.getOrCreateTag().putBoolean("is_empty_reloading", false);
|
||||||
newStack.getOrCreateTag().putInt("gun_reloading_time",0);
|
newStack.getOrCreateTag().putInt("gun_reloading_time", 0);
|
||||||
}
|
|
||||||
|
|
||||||
if (oldStack.getItem() instanceof GunItem oldGun) {
|
double weight = newStack.getOrCreateTag().getDouble("weight");
|
||||||
stopGunReloadSound(serverPlayer, oldGun);
|
|
||||||
if (oldStack.getOrCreateTag().getInt("bolt_action_time") > 0) {
|
if (weight == 0) {
|
||||||
oldStack.getOrCreateTag().putInt("bolt_action_anim", 0);
|
player.getCooldowns().addCooldown(newStack.getItem(), 12);
|
||||||
|
} else if (weight == 1) {
|
||||||
|
player.getCooldowns().addCooldown(newStack.getItem(), 17);
|
||||||
|
} else if (weight == 2) {
|
||||||
|
player.getCooldowns().addCooldown(newStack.getItem(), 30);
|
||||||
}
|
}
|
||||||
oldStack.getOrCreateTag().putBoolean("is_normal_reloading",false);
|
|
||||||
oldStack.getOrCreateTag().putBoolean("is_empty_reloading",false);
|
|
||||||
oldStack.getOrCreateTag().putInt("gun_reloading_time",0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import net.mcreator.target.tools.EnchantmentCategoryTool;
|
||||||
import net.mcreator.target.tools.GunsTool;
|
import net.mcreator.target.tools.GunsTool;
|
||||||
import net.mcreator.target.tools.ItemNBTTool;
|
import net.mcreator.target.tools.ItemNBTTool;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundEvent;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
|
@ -59,18 +58,6 @@ public abstract class GunItem extends Item {
|
||||||
capability.syncPlayerVariables(entity);
|
capability.syncPlayerVariables(entity);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (entity instanceof Player player) {
|
|
||||||
double weight = itemstack.getOrCreateTag().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() && itemstack.getOrCreateTag().getInt("ammo") == 0) {
|
if (itemstack.getItem() == TargetModItems.RPG.get() && itemstack.getOrCreateTag().getInt("ammo") == 0) {
|
||||||
itemstack.getOrCreateTag().putDouble("empty", 1);
|
itemstack.getOrCreateTag().putDouble("empty", 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue