添加自定义瞄准镜缩放,添加后托和重量对武器的影响,编辑模式加入音效

This commit is contained in:
Atsuihsio 2024-10-21 05:01:00 +08:00
parent 3cee01f240
commit 0ee40fc10c
12 changed files with 69 additions and 30 deletions

View file

@ -269,13 +269,24 @@ public class ClientEventHandler {
pose = 1;
}
int stockType = GunsTool.getAttachmentType(player.getMainHandItem(), GunsTool.AttachmentType.STOCK);
double sway = switch (stockType) {
case 1 -> 1;
case 2 -> 0.55;
default -> 0.8;
};
double cusWeight = player.getMainHandItem().getOrCreateTag().getDouble("CustomWeight");
if (!player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).breath &&
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).zoom) {
float newPitch = (float) (player.getXRot() - 0.01f * Mth.sin((float) (0.03 * player.tickCount)) * pose * Mth.nextDouble(RandomSource.create(), 0.1, 1) * times);
float newPitch = (float) (player.getXRot() - 0.01f * Mth.sin((float) (0.03 * player.tickCount)) * pose * Mth.nextDouble(RandomSource.create(), 0.1, 1) * times * sway * (1 - 0.03 * cusWeight));
player.setXRot(newPitch);
player.xRotO = player.getXRot();
float newYaw = (float) (player.getYRot() - 0.005f * Mth.cos((float) (0.025 * (player.tickCount + 2 * Math.PI))) * pose * Mth.nextDouble(RandomSource.create(), 0.05, 1.25) * times);
float newYaw = (float) (player.getYRot() - 0.005f * Mth.cos((float) (0.025 * (player.tickCount + 2 * Math.PI))) * pose * Mth.nextDouble(RandomSource.create(), 0.05, 1.25) * times * sway * (1 - 0.03 * cusWeight));
player.setYRot(newYaw);
player.yRotO = player.getYRot();
}
@ -384,6 +395,7 @@ public class ClientEventHandler {
} else {
pose = 1;
}
swayTime += 0.05 * times;
swayX = pose * -0.008 * Math.sin(swayTime) * (1 - 0.95 * zoomTime);
@ -618,10 +630,11 @@ public class ClientEventHandler {
double recoil = switch (barrelType) {
case 1 -> 0.7;
case 2 -> 1;
case 2 -> 1.3;
default -> 1.8;
};
double cusWeight = player.getMainHandItem().getOrCreateTag().getDouble("CustomWeight");
float gunRecoilX = (float) tag.getDouble("recoil_x") * 60;
@ -645,14 +658,14 @@ public class ClientEventHandler {
}
}
float newYaw = player.getYRot() - (float) (0.6 * recoilHorizon * pose * times * (0.5 + fireSpread) * recoil);
float newYaw = player.getYRot() - (float) (0.6 * recoilHorizon * pose * times * (0.5 + fireSpread) * recoil * (1 - 0.06 * cusWeight));
player.setYRot(newYaw);
player.yRotO = player.getYRot();
double sinRes = 0;
if (0 < recoilTime && recoilTime < 0.5) {
float newPitch = (float) (player.getXRot() - 0.02f * gunRecoilX * times * recoil);
float newPitch = (float) (player.getXRot() - 0.02f * gunRecoilX * times * recoil * (1 - 0.06 * cusWeight));
player.setXRot(newPitch);
player.xRotO = player.getXRot();
}
@ -668,7 +681,7 @@ public class ClientEventHandler {
}
if (0 < recoilTime && recoilTime < 2.5) {
float newPitch = player.getXRot() - (float) (1.5 * pose * gunRecoilX * (sinRes + Mth.clamp(0.5 - recoilTime, 0, 0.5)) * times * (0.5 + fireSpread) * recoil);
float newPitch = player.getXRot() - (float) (1.5 * pose * gunRecoilX * (sinRes + Mth.clamp(0.5 - recoilTime, 0, 0.5)) * times * (0.5 + fireSpread) * recoil * (1 - 0.06 * cusWeight));
player.setXRot(newPitch);
player.xRotO = player.getXRot();
}
@ -796,7 +809,7 @@ public class ClientEventHandler {
p = zoomPos;
}
double zoom = stack.getOrCreateTag().getDouble("zoom") + stack.getOrCreateTag().getDouble("custom_zoom");
double zoom = 1.25 + stack.getOrCreateTag().getDouble("CustomZoom");
if (mc.options.getCameraType().isFirstPerson()) {
event.setFOV(event.getFOV() / (1.0 + p * (zoom - 1)) * (1 - 0.4 * breathTime));

View file

@ -293,4 +293,7 @@ public class ModSounds {
public static final RegistryObject<SoundEvent> DRONE_SOUND = REGISTRY.register("drone_sound", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "drone_sound")));
public static final RegistryObject<SoundEvent> GRENADE_PULL = REGISTRY.register("grenade_pull", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "grenade_pull")));
public static final RegistryObject<SoundEvent> GRENADE_THROW = REGISTRY.register("grenade_throw", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "grenade_throw")));
public static final RegistryObject<SoundEvent> EDIT_MODE = REGISTRY.register("edit_mode", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "edit_mode")));
public static final RegistryObject<SoundEvent> EDIT = REGISTRY.register("edit", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "edit")));
}

View file

@ -1,6 +1,7 @@
package net.mcreator.superbwarfare.item.gun.rifle;
import net.mcreator.superbwarfare.ModUtils;
import net.mcreator.superbwarfare.client.PoseTool;
import net.mcreator.superbwarfare.client.renderer.item.AK12ItemRenderer;
import net.mcreator.superbwarfare.event.ClientEventHandler;
import net.mcreator.superbwarfare.init.ModItems;
@ -12,7 +13,6 @@ import net.mcreator.superbwarfare.network.ModVariables;
import net.mcreator.superbwarfare.perk.Perk;
import net.mcreator.superbwarfare.perk.PerkHelper;
import net.mcreator.superbwarfare.tools.GunsTool;
import net.mcreator.superbwarfare.client.PoseTool;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.player.LocalPlayer;
@ -133,10 +133,10 @@ public class AK12Item extends GunItem implements GeoItem, AnimatedItem {
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
super.inventoryTick(stack, world, entity, slot, selected);
int scopeType = stack.getOrCreateTag().getInt("scope_type");
int barrelType = stack.getOrCreateTag().getInt("barrel_type");
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL);
int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE);
int stockType = stack.getOrCreateTag().getInt("stock_type");
int stockType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK);
int customMag = switch (magType) {
case 1 -> 15;
@ -144,20 +144,15 @@ public class AK12Item extends GunItem implements GeoItem, AnimatedItem {
default -> 0;
};
// if (scopeType == 1) {
//
// } else if (scopeType == 2) {
//
// } else if (scopeType == 3) {
//
// }
double customZoom = switch (scopeType) {
case 0, 1 -> 0;
case 2 -> 2.15;
default -> stack.getOrCreateTag().getDouble("CustomZoom");
};
// if (entity instanceof Player player) {
// player.displayClientMessage(Component.literal(new java.text.DecimalFormat("##.##").format(stack.getOrCreateTag().getInt("scope_type"))
// + " " + new java.text.DecimalFormat("##.#").format(barrelType)
// + " " + new java.text.DecimalFormat("##.#").format(magType)
// + " " + new java.text.DecimalFormat("##.#").format(stockType)), true);
// }
stack.getOrCreateTag().putBoolean("CanAdjustZoomFov", scopeType == 3);
stack.getOrCreateTag().putDouble("CustomZoom", customZoom);
stack.getOrCreateTag().putInt("customMag", customMag);
}

View file

@ -48,7 +48,7 @@ public class MouseHandlerMixin {
return original;
}
double zoom = stack.getOrCreateTag().getDouble("zoom") + stack.getOrCreateTag().getDouble("custom_zoom");
double zoom = 1.25 + stack.getOrCreateTag().getDouble("CustomZoom");
float customSens = (float) stack.getOrCreateTag().getInt("sensitivity");

View file

@ -39,10 +39,12 @@ public class AdjustZoomFovMessage {
}
var tag = stack.getOrCreateTag();
double min_zoom = tag.getDouble("min_zoom") - tag.getDouble("zoom");
double max_zoom = tag.getDouble("max_zoom") - tag.getDouble("zoom");
tag.putDouble("custom_zoom", Mth.clamp(tag.getDouble("custom_zoom") + 0.5 * message.scroll, min_zoom, max_zoom));
if (tag.getDouble("custom_zoom") > min_zoom && tag.getDouble("custom_zoom") < max_zoom) {
if (!tag.getBoolean("CanAdjustZoomFov")) return;
double min_zoom = tag.getDouble("MinZoom") - 1.25;
double max_zoom = tag.getDouble("MaxZoom") - 1.25;
tag.putDouble("CustomZoom", Mth.clamp(tag.getDouble("CustomZoom") + 0.5 * message.scroll, min_zoom, max_zoom));
if (tag.getDouble("CustomZoom") > min_zoom && tag.getDouble("CustomZoom") < max_zoom) {
SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f);
}
});

View file

@ -1,7 +1,9 @@
package net.mcreator.superbwarfare.network.message;
import net.mcreator.superbwarfare.init.ModSounds;
import net.mcreator.superbwarfare.init.ModTags;
import net.mcreator.superbwarfare.network.ModVariables;
import net.mcreator.superbwarfare.tools.SoundTool;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Player;
@ -67,6 +69,7 @@ public class EditMessage {
}
}
stack.addTagElement("Attachments", tag);
SoundTool.playLocalSound(player, ModSounds.EDIT.get(), 1f, 1f);
}
}
}

View file

@ -1,7 +1,9 @@
package net.mcreator.superbwarfare.network.message;
import net.mcreator.superbwarfare.init.ModSounds;
import net.mcreator.superbwarfare.init.ModTags;
import net.mcreator.superbwarfare.network.ModVariables;
import net.mcreator.superbwarfare.tools.SoundTool;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
@ -40,6 +42,10 @@ public class EditModeMessage {
var cap = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null);
if (mainHandItem.is(ModTags.Items.CAN_CUSTOM_GUN)) {
if (!player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).edit) {
SoundTool.playLocalSound(player, ModSounds.EDIT_MODE.get(), 1f, 1f);
}
cap.ifPresent(capability -> {
capability.edit = !cap.orElse(new ModVariables.PlayerVariables()).edit;
capability.syncPlayerVariables(player);

View file

@ -2077,5 +2077,21 @@
"stream": false
}
]
},
"edit_mode": {
"sounds": [
{
"name": "superbwarfare:edit_mode",
"stream": false
}
]
},
"edit": {
"sounds": [
{
"name": "superbwarfare:edit",
"stream": false
}
]
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

After

Width:  |  Height:  |  Size: 73 KiB

View file

@ -1,5 +1,6 @@
{
"zoom": 1.25,
"MinZoom": 1.25,
"MaxZoom": 6,
"spread": 3.5,
"recoil_x": 0.0015,
"recoil_y": 0.01,