重构perkData

This commit is contained in:
17146 2024-10-21 03:19:57 +08:00
parent f552437d24
commit 4d4f1c4169
6 changed files with 75 additions and 41 deletions

View file

@ -226,7 +226,7 @@ public class ClientEventHandler {
rpm = 600;
}
if (stack.getOrCreateTag().getInt("DesperadoTimePost") > 0) {
if (GunsTool.getPerkIntTag(stack, "DesperadoTimePost") > 0) {
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.DESPERADO.get(), stack);
rpm *= 1.25 + 0.05 * perkLevel;
}

View file

@ -14,6 +14,7 @@ import net.mcreator.superbwarfare.perk.AmmoPerk;
import net.mcreator.superbwarfare.perk.Perk;
import net.mcreator.superbwarfare.perk.PerkHelper;
import net.mcreator.superbwarfare.tools.DamageTypeTool;
import net.mcreator.superbwarfare.tools.GunsTool;
import net.mcreator.superbwarfare.tools.SoundTool;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
@ -465,17 +466,17 @@ public class LivingEventHandler {
private static void handleClipPerks(ItemStack stack) {
int healClipLevel = PerkHelper.getItemPerkLevel(ModPerks.HEAL_CLIP.get(), stack);
if (healClipLevel != 0) {
stack.getOrCreateTag().putInt("HealClipTime", 80 + healClipLevel * 20);
GunsTool.setPerkIntTag(stack, "HealClipTime", 80 + healClipLevel * 20);
}
int killClipLevel = PerkHelper.getItemPerkLevel(ModPerks.KILL_CLIP.get(), stack);
if (killClipLevel != 0) {
stack.getOrCreateTag().putInt("KillClipReloadTime", 80);
GunsTool.setPerkIntTag(stack, "KillClipReloadTime", 80);
}
}
private static void handleKillClipDamage(ItemStack stack, LivingHurtEvent event) {
if (stack.getOrCreateTag().getInt("KillClipTime") > 0) {
if (GunsTool.getPerkIntTag(stack, "KillClipTime") > 0) {
int level = PerkHelper.getItemPerkLevel(ModPerks.KILL_CLIP.get(), stack);
if (level == 0) {
return;
@ -500,7 +501,7 @@ public class LivingEventHandler {
return;
}
int killTally = stack.getOrCreateTag().getInt("KillingTally");
int killTally = GunsTool.getPerkIntTag(stack, "KillingTally");
if (killTally == 0) {
return;
}
@ -511,7 +512,7 @@ public class LivingEventHandler {
private static void handleKillingTallyAddCount(ItemStack stack) {
int level = PerkHelper.getItemPerkLevel(ModPerks.KILLING_TALLY.get(), stack);
if (level != 0) {
stack.getOrCreateTag().putInt("KillingTally", Math.min(3, stack.getOrCreateTag().getInt("KillingTally") + 1));
GunsTool.setPerkIntTag(stack, "KillingTally", Math.min(3, GunsTool.getPerkIntTag(stack, "KillingTally") + 1));
}
}
@ -521,14 +522,14 @@ public class LivingEventHandler {
return;
}
int fourthTimesCharmTick = stack.getOrCreateTag().getInt("FourthTimesCharmTick");
int fourthTimesCharmTick = GunsTool.getPerkIntTag(stack, "FourthTimesCharmTick");
if (fourthTimesCharmTick <= 0) {
stack.getOrCreateTag().putInt("FourthTimesCharmTick", 40 + 10 * level);
stack.getOrCreateTag().putInt("FourthTimesCharmCount", 1);
GunsTool.setPerkIntTag(stack, "FourthTimesCharmTick", 40 + 10 * level);
GunsTool.setPerkIntTag(stack, "FourthTimesCharmCount", 1);
} else {
int count = stack.getOrCreateTag().getInt("FourthTimesCharmCount");
int count = GunsTool.getPerkIntTag(stack, "FourthTimesCharmCount");
if (count < 4) {
stack.getOrCreateTag().putInt("FourthTimesCharmCount", Math.min(4, count + 1));
GunsTool.setPerkIntTag(stack, "FourthTimesCharmCount", Math.min(4, count + 1));
}
}
}
@ -579,7 +580,7 @@ public class LivingEventHandler {
return;
}
stack.getOrCreateTag().putInt("HeadSeeker", 11 + level * 2);
GunsTool.setPerkIntTag(stack, "HeadSeeker", 11 + level * 2);
}
private static void handleHeadSeekerDamage(ItemStack stack, LivingHurtEvent event) {
@ -588,7 +589,7 @@ public class LivingEventHandler {
return;
}
if (stack.getOrCreateTag().getInt("HeadSeeker") > 0) {
if (GunsTool.getPerkIntTag(stack, "HeadSeeker") > 0) {
event.setAmount(event.getAmount() * (1.095f + 0.0225f * level));
}
}
@ -599,7 +600,7 @@ public class LivingEventHandler {
return;
}
stack.getOrCreateTag().putInt("DesperadoTime", 90 + level * 10);
GunsTool.setPerkIntTag(stack, "DesperadoTime", 90 + level * 10);
}
/**

View file

@ -367,7 +367,6 @@ public class PlayerEventHandler {
}
}
@SubscribeEvent
public static void onAnvilUpdate(AnvilUpdateEvent event) {
ItemStack left = event.getLeft();

View file

@ -4,6 +4,7 @@ import net.mcreator.superbwarfare.event.modevent.ReloadEvent;
import net.mcreator.superbwarfare.init.ModPerks;
import net.mcreator.superbwarfare.init.ModTags;
import net.mcreator.superbwarfare.perk.PerkHelper;
import net.mcreator.superbwarfare.tools.GunsTool;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -50,17 +51,17 @@ public class ReloadEventHandler {
}
private static void handleHealClipPre(ItemStack stack) {
int time = stack.getOrCreateTag().getInt("HealClipTime");
int time = GunsTool.getPerkIntTag(stack, "HealClipTime");
if (time > 0) {
stack.getOrCreateTag().putInt("HealClipTime", 0);
stack.getOrCreateTag().putBoolean("HealClip", true);
GunsTool.setPerkIntTag(stack, "HealClipTime", 0);
GunsTool.setPerkBooleanTag(stack, "HealClip", true);
} else {
stack.getOrCreateTag().putBoolean("HealClip", false);
GunsTool.setPerkBooleanTag(stack, "HealClip", false);
}
}
private static void handleHealClipPost(Player player, ItemStack stack) {
if (!stack.getOrCreateTag().getBoolean("HealClip")) {
if (!GunsTool.getPerkBooleanTag(stack, "HealClip")) {
return;
}
@ -77,22 +78,22 @@ public class ReloadEventHandler {
}
private static void handleKillClipPre(ItemStack stack) {
int time = stack.getOrCreateTag().getInt("KillClipReloadTime");
int time = GunsTool.getPerkIntTag(stack, "KillClipReloadTime");
if (time > 0) {
stack.getOrCreateTag().putInt("KillClipReloadTime", 0);
stack.getOrCreateTag().putBoolean("KillClip", true);
GunsTool.setPerkIntTag(stack, "KillClipReloadTime", 0);
GunsTool.setPerkBooleanTag(stack, "KillClip", true);
} else {
stack.getOrCreateTag().putBoolean("KillClip", false);
GunsTool.setPerkBooleanTag(stack, "KillClip", false);
}
}
private static void handleKillClipPost(ItemStack stack) {
if (!stack.getOrCreateTag().getBoolean("KillClip")) {
if (!GunsTool.getPerkBooleanTag(stack, "KillClip")) {
return;
}
int level = PerkHelper.getItemPerkLevel(ModPerks.KILL_CLIP.get(), stack);
stack.getOrCreateTag().putInt("KillClipTime", 90 + 10 * level);
GunsTool.setPerkIntTag(stack, "KillClipTime", 90 + 10 * level);
}
private static void handleKillingTallyPre(ItemStack stack) {
@ -101,27 +102,25 @@ public class ReloadEventHandler {
return;
}
if (stack.getOrCreateTag().contains("KillingTally")) {
stack.getOrCreateTag().putInt("KillingTally", 0);
}
GunsTool.setPerkIntTag(stack, "KillingTally", 0);
}
private static void handleDesperadoPre(ItemStack stack) {
int time = stack.getOrCreateTag().getInt("DesperadoTime");
int time = GunsTool.getPerkIntTag(stack, "DesperadoTime");
if (time > 0) {
stack.getOrCreateTag().putInt("DesperadoTime", 0);
stack.getOrCreateTag().putBoolean("Desperado", true);
GunsTool.setPerkIntTag(stack, "DesperadoTime", 0);
GunsTool.setPerkBooleanTag(stack, "Desperado", true);
} else {
stack.getOrCreateTag().putBoolean("Desperado", false);
GunsTool.setPerkBooleanTag(stack, "Desperado", false);
}
}
private static void handleDesperadoPost(ItemStack stack) {
if (!stack.getOrCreateTag().getBoolean("Desperado")) {
if (!GunsTool.getPerkBooleanTag(stack, "Desperado")) {
return;
}
int level = PerkHelper.getItemPerkLevel(ModPerks.DESPERADO.get(), stack);
stack.getOrCreateTag().putInt("DesperadoTimePost", 110 + level * 10);
GunsTool.setPerkIntTag(stack, "DesperadoTimePost", 110 + level * 10);
}
}

View file

@ -164,14 +164,14 @@ public abstract class GunItem extends Item {
}
private void handleGunPerks(ItemStack stack) {
reduceTagTime(stack, "HealClipTime", "KillClipReloadTime", "KillClipTime", "FourthTimesCharmTick", "HeadSeeker",
reducePerkTagTime(stack, "HealClipTime", "KillClipReloadTime", "KillClipTime", "FourthTimesCharmTick", "HeadSeeker",
"DesperadoTime", "DesperadoTimePost");
if (PerkHelper.getItemPerkLevel(ModPerks.FOURTH_TIMES_CHARM.get(), stack) > 0) {
int count = stack.getOrCreateTag().getInt("FourthTimesCharmCount");
int count = GunsTool.getPerkIntTag(stack, "FourthTimesCharmCount");
if (count >= 4) {
stack.getOrCreateTag().putInt("FourthTimesCharmTick", 0);
stack.getOrCreateTag().putInt("FourthTimesCharmCount", 0);
GunsTool.setPerkIntTag(stack, "FourthTimesCharmTick", 0);
GunsTool.setPerkIntTag(stack, "FourthTimesCharmCount", 0);
int mag = stack.getOrCreateTag().getInt("mag") + stack.getOrCreateTag().getInt("customMag");
stack.getOrCreateTag().putInt("ammo", Math.min(mag, stack.getOrCreateTag().getInt("ammo") + 2));
@ -226,13 +226,15 @@ public abstract class GunItem extends Item {
return true;
}
private void reduceTagTime(ItemStack stack, String... tag) {
private void reducePerkTagTime(ItemStack stack, String... tag) {
if (!stack.hasTag() || stack.getTag() == null) {
return;
}
var compound = stack.getOrCreateTag().getCompound("PerkData");
for (String t : tag) {
if (!stack.getTag().contains(t)) {
if (!compound.contains(t)) {
continue;
}

View file

@ -122,6 +122,39 @@ public class GunsTool {
tag.putBoolean("is_empty_reloading", false);
}
public static void setPerkIntTag(ItemStack stack, String name, int num) {
CompoundTag tag = stack.getOrCreateTag().getCompound("PerkData");
tag.putInt(name, num);
stack.addTagElement("PerkData", tag);
}
public static int getPerkIntTag(ItemStack stack, String name) {
CompoundTag tag = stack.getOrCreateTag().getCompound("PerkData");
return tag.getInt(name);
}
public static void setPerkDoubleTag(ItemStack stack, String name, double num) {
CompoundTag tag = stack.getOrCreateTag().getCompound("PerkData");
tag.putDouble(name, num);
stack.addTagElement("PerkData", tag);
}
public static double getPerkDoubleTag(ItemStack stack, String name) {
CompoundTag tag = stack.getOrCreateTag().getCompound("PerkData");
return tag.getDouble(name);
}
public static void setPerkBooleanTag(ItemStack stack, String name, boolean flag) {
CompoundTag tag = stack.getOrCreateTag().getCompound("PerkData");
tag.putBoolean(name, flag);
stack.addTagElement("PerkData", tag);
}
public static boolean getPerkBooleanTag(ItemStack stack, String name) {
CompoundTag tag = stack.getOrCreateTag().getCompound("PerkData");
return tag.getBoolean(name);
}
public static int getAttachmentType(ItemStack stack, AttachmentType type) {
CompoundTag tag = stack.getOrCreateTag().getCompound("Attachments");
return tag.getInt(type.getName());