优化重量相关代码
This commit is contained in:
parent
28ed1fa12d
commit
e436675cea
4 changed files with 43 additions and 65 deletions
|
@ -9,36 +9,19 @@ public class ItemModelHelper {
|
||||||
public static void handleGunAttachments(GeoBone bone, ItemStack stack, String name) {
|
public static void handleGunAttachments(GeoBone bone, ItemStack stack, String name) {
|
||||||
CompoundTag tag = stack.getOrCreateTag().getCompound("Attachments");
|
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 {
|
try {
|
||||||
if (name.startsWith("Scope")) {
|
if (boneName.startsWith(tagName)) {
|
||||||
String[] parts = name.split("(?<=\\D)(?=\\d)");
|
String[] parts = boneName.split("(?<=\\D)(?=\\d)");
|
||||||
if (parts.length == 2) {
|
if (parts.length == 2) {
|
||||||
int index = Integer.parseInt(parts[1]);
|
int index = Integer.parseInt(parts[1]);
|
||||||
bone.setHidden(tag.getInt("Scope") != index);
|
bone.setHidden(tag.getInt(tagName) != 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
|
|
|
@ -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);
|
double speed = 1 - (0.04 * weight);
|
||||||
|
|
||||||
|
@ -483,7 +483,7 @@ public class ClientEventHandler {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
float times = 5 * Minecraft.getInstance().getDeltaFrameTime();
|
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);
|
double speed = 1.5 - (0.07 * weight);
|
||||||
|
|
||||||
if (GLFW.glfwGetMouseButton(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_RIGHT) == GLFW.GLFW_PRESS
|
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) {
|
private static void handleWeaponDraw(LivingEntity entity) {
|
||||||
float times = Minecraft.getInstance().getDeltaFrameTime();
|
float times = Minecraft.getInstance().getDeltaFrameTime();
|
||||||
ItemStack stack = entity.getMainHandItem();
|
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);
|
double speed = 3.2 - (0.13 * weight);
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ public class PlayerEventHandler {
|
||||||
int sprintCost;
|
int sprintCost;
|
||||||
|
|
||||||
if (stack.is(ModTags.Items.GUN)) {
|
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);
|
sprintCost = (int) (2 + 0.2 * weight);
|
||||||
} else {
|
} else {
|
||||||
sprintCost = 2;
|
sprintCost = 2;
|
||||||
|
|
|
@ -13,6 +13,7 @@ import net.mcreator.superbwarfare.tools.GunsTool;
|
||||||
import net.mcreator.superbwarfare.tools.ItemNBTTool;
|
import net.mcreator.superbwarfare.tools.ItemNBTTool;
|
||||||
import net.mcreator.superbwarfare.tools.TooltipTool;
|
import net.mcreator.superbwarfare.tools.TooltipTool;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.sounds.SoundEvent;
|
import net.minecraft.sounds.SoundEvent;
|
||||||
|
@ -126,7 +127,9 @@ public abstract class GunItem extends Item {
|
||||||
if (slot == EquipmentSlot.MAINHAND) {
|
if (slot == EquipmentSlot.MAINHAND) {
|
||||||
map = HashMultimap.create(map);
|
map = HashMultimap.create(map);
|
||||||
map.put(Attributes.MOVEMENT_SPEED,
|
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;
|
return map;
|
||||||
}
|
}
|
||||||
|
@ -197,45 +200,37 @@ public abstract class GunItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleGunAttachment(ItemStack stack) {
|
private void handleGunAttachment(ItemStack stack) {
|
||||||
|
CompoundTag tag = stack.getOrCreateTag().getCompound("Attachments");
|
||||||
|
|
||||||
int scopeType = stack.getOrCreateTag().getInt("scope_type");
|
double scopeWeight = switch (tag.getInt("Scope")) {
|
||||||
int barrelType = stack.getOrCreateTag().getInt("barrel_type");
|
case 1 -> 0.5;
|
||||||
int magType = stack.getOrCreateTag().getInt("magazine_type");
|
case 2 -> 1;
|
||||||
int stockType = stack.getOrCreateTag().getInt("stock_type");
|
case 3 -> 2;
|
||||||
|
default -> 0;
|
||||||
|
};
|
||||||
|
|
||||||
double ScopeWeight = 0;
|
double barrelWeight = switch (tag.getInt("Barrel")) {
|
||||||
double BarrelWeight = 0;
|
case 1 -> 1;
|
||||||
double MagWeight = 0;
|
case 2 -> 2;
|
||||||
double StockWeight = 0;
|
default -> 0;
|
||||||
|
};
|
||||||
|
|
||||||
if (scopeType == 1) {
|
double magazineWeight = switch (tag.getInt("Magazine")) {
|
||||||
ScopeWeight = 0.5;
|
case 1 -> 1.5;
|
||||||
} else if (scopeType == 2) {
|
case 2 -> 3;
|
||||||
ScopeWeight = 1;
|
default -> 0;
|
||||||
} else if (scopeType == 3) {
|
};
|
||||||
ScopeWeight = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (barrelType == 1) {
|
double stockWeight = switch (tag.getInt("Stock")) {
|
||||||
BarrelWeight = 1;
|
case 1 -> -2;
|
||||||
} else if (magType == 2) {
|
case 2 -> 2;
|
||||||
BarrelWeight = 2;
|
default -> 0;
|
||||||
}
|
};
|
||||||
|
|
||||||
if (magType == 1) {
|
double soundRadius = tag.getInt("Barrel") == 2 ? 0.25 : 1;
|
||||||
MagWeight = 1.5;
|
|
||||||
} else if (magType == 2) {
|
|
||||||
MagWeight = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stockType == 1) {
|
stack.getOrCreateTag().putDouble("CustomWeight", scopeWeight + barrelWeight + magazineWeight + stockWeight);
|
||||||
StockWeight = -2;
|
stack.getOrCreateTag().putDouble("CustomSoundRadius", soundRadius);
|
||||||
} else if (stockType == 2) {
|
|
||||||
ScopeWeight = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
stack.getOrCreateTag().putDouble("custom_weight", ScopeWeight + BarrelWeight + MagWeight + StockWeight);
|
|
||||||
stack.getOrCreateTag().putDouble("CustomSoundRadius", barrelType == 2 ? 0.25 : 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canApplyPerk(Perk perk) {
|
public boolean canApplyPerk(Perk perk) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue