diff --git a/src/main/java/net/mcreator/superbwarfare/client/ItemModelHelper.java b/src/main/java/net/mcreator/superbwarfare/client/ItemModelHelper.java index af1a5c598..d4637e684 100644 --- a/src/main/java/net/mcreator/superbwarfare/client/ItemModelHelper.java +++ b/src/main/java/net/mcreator/superbwarfare/client/ItemModelHelper.java @@ -9,36 +9,19 @@ public class ItemModelHelper { public static void handleGunAttachments(GeoBone bone, ItemStack stack, String name) { CompoundTag tag = stack.getOrCreateTag().getCompound("Attachments"); + splitBoneName(bone, name, "Scope", tag); + splitBoneName(bone, name, "Magazine", tag); + splitBoneName(bone, name, "Barrel", tag); + splitBoneName(bone, name, "Stock", tag); + } + + private static void splitBoneName(GeoBone bone, String boneName, String tagName, CompoundTag tag) { try { - if (name.startsWith("Scope")) { - String[] parts = name.split("(?<=\\D)(?=\\d)"); + if (boneName.startsWith(tagName)) { + String[] parts = boneName.split("(?<=\\D)(?=\\d)"); if (parts.length == 2) { int index = Integer.parseInt(parts[1]); - bone.setHidden(tag.getInt("Scope") != index); - } - } - - if (name.startsWith("Magazine")) { - String[] parts = name.split("(?<=\\D)(?=\\d)"); - if (parts.length == 2) { - int index = Integer.parseInt(parts[1]); - bone.setHidden(tag.getInt("Magazine") != index); - } - } - - if (name.startsWith("Barrel")) { - String[] parts = name.split("(?<=\\D)(?=\\d)"); - if (parts.length == 2) { - int index = Integer.parseInt(parts[1]); - bone.setHidden(tag.getInt("Barrel") != index); - } - } - - if (name.startsWith("Stock")) { - String[] parts = name.split("(?<=\\D)(?=\\d)"); - if (parts.length == 2) { - int index = Integer.parseInt(parts[1]); - bone.setHidden(tag.getInt("Stock") != index); + bone.setHidden(tag.getInt(tagName) != index); } } } catch (NumberFormatException ignored) { diff --git a/src/main/java/net/mcreator/superbwarfare/event/ClientEventHandler.java b/src/main/java/net/mcreator/superbwarfare/event/ClientEventHandler.java index 11ed3eb87..a4c422f4c 100644 --- a/src/main/java/net/mcreator/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/net/mcreator/superbwarfare/event/ClientEventHandler.java @@ -192,7 +192,7 @@ public class ClientEventHandler { } // 开火部分 - double weight = stack.getOrCreateTag().getDouble("weight") + stack.getOrCreateTag().getDouble("custom_weight"); + double weight = stack.getOrCreateTag().getDouble("weight") + stack.getOrCreateTag().getDouble("CustomWeight"); double speed = 1 - (0.04 * weight); @@ -483,7 +483,7 @@ public class ClientEventHandler { ItemStack stack = player.getMainHandItem(); float times = 5 * Minecraft.getInstance().getDeltaFrameTime(); - double weight = stack.getOrCreateTag().getDouble("weight") + stack.getOrCreateTag().getDouble("custom_weight"); + double weight = stack.getOrCreateTag().getDouble("weight") + stack.getOrCreateTag().getDouble("CustomWeight"); double speed = 1.5 - (0.07 * weight); if (GLFW.glfwGetMouseButton(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_RIGHT) == GLFW.GLFW_PRESS @@ -850,7 +850,7 @@ public class ClientEventHandler { private static void handleWeaponDraw(LivingEntity entity) { float times = Minecraft.getInstance().getDeltaFrameTime(); ItemStack stack = entity.getMainHandItem(); - double weight = stack.getOrCreateTag().getDouble("weight") + stack.getOrCreateTag().getDouble("custom_weight"); + double weight = stack.getOrCreateTag().getDouble("weight") + stack.getOrCreateTag().getDouble("CustomWeight"); double speed = 3.2 - (0.13 * weight); diff --git a/src/main/java/net/mcreator/superbwarfare/event/PlayerEventHandler.java b/src/main/java/net/mcreator/superbwarfare/event/PlayerEventHandler.java index 865f1ea88..d70987251 100644 --- a/src/main/java/net/mcreator/superbwarfare/event/PlayerEventHandler.java +++ b/src/main/java/net/mcreator/superbwarfare/event/PlayerEventHandler.java @@ -131,7 +131,7 @@ public class PlayerEventHandler { int sprintCost; if (stack.is(ModTags.Items.GUN)) { - double weight = stack.getOrCreateTag().getDouble("weight") + stack.getOrCreateTag().getDouble("custom_weight"); + double weight = stack.getOrCreateTag().getDouble("weight") + stack.getOrCreateTag().getDouble("CustomWeight"); sprintCost = (int) (2 + 0.2 * weight); } else { sprintCost = 2; diff --git a/src/main/java/net/mcreator/superbwarfare/item/gun/GunItem.java b/src/main/java/net/mcreator/superbwarfare/item/gun/GunItem.java index bff81f112..3207f500b 100644 --- a/src/main/java/net/mcreator/superbwarfare/item/gun/GunItem.java +++ b/src/main/java/net/mcreator/superbwarfare/item/gun/GunItem.java @@ -13,6 +13,7 @@ import net.mcreator.superbwarfare.tools.GunsTool; import net.mcreator.superbwarfare.tools.ItemNBTTool; import net.mcreator.superbwarfare.tools.TooltipTool; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; @@ -126,7 +127,9 @@ public abstract class GunItem extends Item { if (slot == EquipmentSlot.MAINHAND) { map = HashMultimap.create(map); map.put(Attributes.MOVEMENT_SPEED, - new AttributeModifier(uuid, ModUtils.ATTRIBUTE_MODIFIER, -0.01f - 0.005f * (stack.getOrCreateTag().getDouble("weight") + stack.getOrCreateTag().getDouble("custom_weight")), AttributeModifier.Operation.MULTIPLY_BASE)); + new AttributeModifier(uuid, ModUtils.ATTRIBUTE_MODIFIER, + -0.01f - 0.005f * (stack.getOrCreateTag().getDouble("weight") + stack.getOrCreateTag().getDouble("CustomWeight")), + AttributeModifier.Operation.MULTIPLY_BASE)); } return map; } @@ -197,45 +200,37 @@ public abstract class GunItem extends Item { } private void handleGunAttachment(ItemStack stack) { + CompoundTag tag = stack.getOrCreateTag().getCompound("Attachments"); - int scopeType = stack.getOrCreateTag().getInt("scope_type"); - int barrelType = stack.getOrCreateTag().getInt("barrel_type"); - int magType = stack.getOrCreateTag().getInt("magazine_type"); - int stockType = stack.getOrCreateTag().getInt("stock_type"); + double scopeWeight = switch (tag.getInt("Scope")) { + case 1 -> 0.5; + case 2 -> 1; + case 3 -> 2; + default -> 0; + }; - double ScopeWeight = 0; - double BarrelWeight = 0; - double MagWeight = 0; - double StockWeight = 0; + double barrelWeight = switch (tag.getInt("Barrel")) { + case 1 -> 1; + case 2 -> 2; + default -> 0; + }; - if (scopeType == 1) { - ScopeWeight = 0.5; - } else if (scopeType == 2) { - ScopeWeight = 1; - } else if (scopeType == 3) { - ScopeWeight = 2; - } + double magazineWeight = switch (tag.getInt("Magazine")) { + case 1 -> 1.5; + case 2 -> 3; + default -> 0; + }; - if (barrelType == 1) { - BarrelWeight = 1; - } else if (magType == 2) { - BarrelWeight = 2; - } + double stockWeight = switch (tag.getInt("Stock")) { + case 1 -> -2; + case 2 -> 2; + default -> 0; + }; - if (magType == 1) { - MagWeight = 1.5; - } else if (magType == 2) { - MagWeight = 3; - } + double soundRadius = tag.getInt("Barrel") == 2 ? 0.25 : 1; - if (stockType == 1) { - StockWeight = -2; - } else if (stockType == 2) { - ScopeWeight = 2; - } - - stack.getOrCreateTag().putDouble("custom_weight", ScopeWeight + BarrelWeight + MagWeight + StockWeight); - stack.getOrCreateTag().putDouble("CustomSoundRadius", barrelType == 2 ? 0.25 : 1); + stack.getOrCreateTag().putDouble("CustomWeight", scopeWeight + barrelWeight + magazineWeight + stockWeight); + stack.getOrCreateTag().putDouble("CustomSoundRadius", soundRadius); } public boolean canApplyPerk(Perk perk) {