优化部分代码
This commit is contained in:
parent
bc4d7539c9
commit
950dfc230e
7 changed files with 48 additions and 76 deletions
|
@ -3,34 +3,21 @@ package net.mcreator.target.client;
|
|||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import net.mcreator.target.TargetMod;
|
||||
import net.mcreator.target.entity.MortarEntity;
|
||||
import net.mcreator.target.entity.Target1Entity;
|
||||
import net.mcreator.target.entity.TargetEntity;
|
||||
import net.mcreator.target.init.TargetModKeyMappings;
|
||||
import net.mcreator.target.init.TargetModMobEffects;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.item.gun.GunItem;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.mcreator.target.network.message.*;
|
||||
import net.mcreator.target.network.message.AdjustMortarAngleMessage;
|
||||
import net.mcreator.target.network.message.AdjustZoomFovMessage;
|
||||
import net.mcreator.target.network.message.FireMessage;
|
||||
import net.mcreator.target.network.message.ZoomMessage;
|
||||
import net.mcreator.target.tools.TraceTool;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.InputEvent;
|
||||
import net.minecraftforge.client.settings.KeyConflictContext;
|
||||
import net.minecraftforge.client.settings.KeyModifier;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
@ -111,14 +98,16 @@ public class ClickHandler {
|
|||
@SubscribeEvent
|
||||
public static void onMouseScrolling(InputEvent.MouseScrollingEvent event) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var tag = stack.getOrCreateTag();
|
||||
double scroll = event.getScrollDelta();
|
||||
|
||||
if (notInGame()) return;
|
||||
if (player == null) return;
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
double scroll = event.getScrollDelta();
|
||||
|
||||
if (stack.is(TargetModTags.Items.GUN) && (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zoom) {
|
||||
var tag = stack.getOrCreateTag();
|
||||
if (tag.getDouble("min_zoom") != 0 && tag.getDouble("max_zoom") != 0) {
|
||||
TargetMod.PACKET_HANDLER.sendToServer(new AdjustZoomFovMessage(scroll));
|
||||
}
|
||||
|
@ -127,13 +116,13 @@ public class ClickHandler {
|
|||
|
||||
Entity looking = TraceTool.findLookingEntity(player, 6);
|
||||
if (looking == null) return;
|
||||
if (looking instanceof MortarEntity && player.isShiftKeyDown()){
|
||||
if (looking instanceof MortarEntity && player.isShiftKeyDown()) {
|
||||
TargetMod.PACKET_HANDLER.sendToServer(new AdjustMortarAngleMessage(scroll));
|
||||
event.setCanceled(true);
|
||||
}
|
||||
|
||||
|
||||
if (Minecraft.getInstance().player.hasEffect(TargetModMobEffects.SHOCK.get())) {
|
||||
if (player.hasEffect(TargetModMobEffects.SHOCK.get())) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,23 +31,20 @@ public class Aa12ItemModel extends GeoModel<Aa12Item> {
|
|||
public void setCustomAnimations(Aa12Item animatable, long instanceId, AnimationState animationState) {
|
||||
CoreGeoBone gun = getAnimationProcessor().getBone("bone");
|
||||
CoreGeoBone shen = getAnimationProcessor().getBone("shen");
|
||||
|
||||
Player player = Minecraft.getInstance().player;
|
||||
|
||||
assert player != null;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
|
||||
double p = 0;
|
||||
p = player.getPersistentData().getDouble("zoom_pos");
|
||||
|
||||
double zp = 0;
|
||||
zp = player.getPersistentData().getDouble("zoom_pos_z");
|
||||
double p = player.getPersistentData().getDouble("zoom_pos");
|
||||
double zp = player.getPersistentData().getDouble("zoom_pos_z");
|
||||
|
||||
gun.setPosX(3.48f * (float) p);
|
||||
|
||||
gun.setPosY(-0.92f * (float) p - (float) (0.2f * zp));
|
||||
|
||||
gun.setPosZ(0.1f * (float) p + (float) (0.3f * zp));
|
||||
|
||||
gun.setRotZ((float) (0.02f * zp));
|
||||
|
||||
gun.setScaleZ(1f - (0.4f * (float) p));
|
||||
|
||||
double fp = player.getPersistentData().getDouble("fire_pos");
|
||||
|
@ -64,7 +61,7 @@ public class Aa12ItemModel extends GeoModel<Aa12Item> {
|
|||
shen.setRotX(0.07f * (float) (0.18f * fp + fr));
|
||||
shen.setRotZ(-0.04f * (float) (fp + 1.3 * fr));
|
||||
}
|
||||
shen.setPosX(0.5f * (float)fr * (float)((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).recoilHorizon * fp));
|
||||
shen.setPosX(0.5f * (float) fr * (float) ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).recoilHorizon * fp));
|
||||
|
||||
CoreGeoBone flare = getAnimationProcessor().getBone("flare");
|
||||
|
||||
|
@ -80,54 +77,41 @@ public class Aa12ItemModel extends GeoModel<Aa12Item> {
|
|||
|
||||
CoreGeoBone root = getAnimationProcessor().getBone("root");
|
||||
|
||||
float PosX = (float)player.getPersistentData().getDouble("gun_move_posX");
|
||||
float PosY = (float)player.getPersistentData().getDouble("gun_move_posY");
|
||||
float PosX = (float) player.getPersistentData().getDouble("gun_move_posX");
|
||||
float PosY = (float) player.getPersistentData().getDouble("gun_move_posY");
|
||||
|
||||
double y = 0;
|
||||
double x = 0;
|
||||
y = player.getPersistentData().getDouble("y");
|
||||
x = player.getPersistentData().getDouble("x");
|
||||
double y = player.getPersistentData().getDouble("y");
|
||||
double x = player.getPersistentData().getDouble("x");
|
||||
|
||||
root.setPosX(PosX);
|
||||
|
||||
root.setPosY((float) y + PosY);
|
||||
|
||||
root.setRotX((float) x);
|
||||
|
||||
float RotZ = (float) player.getPersistentData().getDouble("gun_move_rotZ");
|
||||
|
||||
root.setRotY(0.2f * PosX);
|
||||
|
||||
root.setRotZ(0.2f * PosX + RotZ);
|
||||
|
||||
CoreGeoBone move = getAnimationProcessor().getBone("move");
|
||||
|
||||
double m = player.getPersistentData().getDouble("move");
|
||||
|
||||
double vy = player.getPersistentData().getDouble("vy");
|
||||
|
||||
move.setPosX(9.3f * (float) m);
|
||||
|
||||
move.setPosY(-2f * (float) vy);
|
||||
|
||||
double xRot = player.getPersistentData().getDouble("xRot");
|
||||
|
||||
double yRot = player.getPersistentData().getDouble("yRot");
|
||||
|
||||
double zRot = player.getPersistentData().getDouble("zRot");
|
||||
|
||||
move.setRotX(Mth.DEG_TO_RAD * (float) xRot - 0.15f * (float) vy);
|
||||
|
||||
move.setRotY(Mth.DEG_TO_RAD * (float) yRot);
|
||||
|
||||
move.setRotZ(2.7f * (float) m + Mth.DEG_TO_RAD * (float) zRot);
|
||||
|
||||
CoreGeoBone camera = getAnimationProcessor().getBone("camera");
|
||||
|
||||
player.getPersistentData().putDouble("camera_rot_x", Mth.RAD_TO_DEG * camera.getRotX());
|
||||
|
||||
player.getPersistentData().putDouble("camera_rot_y", Mth.RAD_TO_DEG * camera.getRotY());
|
||||
|
||||
player.getPersistentData().putDouble("camera_rot_z", Mth.RAD_TO_DEG * camera.getRotZ());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,12 +173,12 @@ public class GunEventHandler {
|
|||
*/
|
||||
private static void handleMiniGunFire(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var tag = stack.getOrCreateTag();
|
||||
|
||||
if (stack.getItem() != TargetModItems.MINIGUN.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var tag = stack.getOrCreateTag();
|
||||
|
||||
if ((player.getPersistentData().getBoolean("firing") || (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zoom) && !player.isSprinting()) {
|
||||
if (tag.getDouble("minigun_rotation") < 10) {
|
||||
tag.putDouble("minigun_rotation", (tag.getDouble("minigun_rotation") + 1));
|
||||
|
@ -309,7 +309,6 @@ public class GunEventHandler {
|
|||
public static void gunShoot(Player player) {
|
||||
ItemStack heldItem = player.getMainHandItem();
|
||||
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
|
||||
capability.recoilHorizon = 2 * Math.random() - 1;
|
||||
capability.recoil = 0.1;
|
||||
capability.firing = 1;
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package net.mcreator.target.event;
|
||||
|
||||
import net.mcreator.target.TargetMod;
|
||||
import net.mcreator.target.entity.ClaymoreEntity;
|
||||
import net.mcreator.target.entity.Target1Entity;
|
||||
import net.mcreator.target.init.*;
|
||||
import net.mcreator.target.init.TargetModDamageTypes;
|
||||
import net.mcreator.target.init.TargetModItems;
|
||||
import net.mcreator.target.init.TargetModSounds;
|
||||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.item.gun.GunItem;
|
||||
import net.mcreator.target.network.TargetModVariables;
|
||||
import net.mcreator.target.network.message.ClientIndicatorMessage;
|
||||
|
@ -23,7 +25,6 @@ import net.minecraft.world.entity.LivingEntity;
|
|||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
||||
|
@ -60,9 +61,11 @@ public class LivingEventHandler {
|
|||
|
||||
double damage = amount;
|
||||
ItemStack stack = sourceentity instanceof LivingEntity living ? living.getMainHandItem() : ItemStack.EMPTY;
|
||||
if (damagesource.is(TargetModDamageTypes.ARROW_IN_KNEE) || damagesource.is(TargetModDamageTypes.ARROW_IN_BRAIN)) {
|
||||
if ((damagesource.is(TargetModDamageTypes.ARROW_IN_KNEE) || damagesource.is(TargetModDamageTypes.ARROW_IN_BRAIN)
|
||||
&& stack.getItem() == TargetModItems.BOCEK.get())) {
|
||||
stack.getOrCreateTag().putDouble("damagetotal", stack.getOrCreateTag().getDouble("damagetotal") + damage);
|
||||
}
|
||||
|
||||
if ((damagesource.is(TargetModDamageTypes.PROJECTILE_BOOM) || damagesource.is(DamageTypes.ARROW))
|
||||
&& (stack.getItem() == TargetModItems.M_79.get() || stack.getItem() == TargetModItems.RPG.get())
|
||||
) {
|
||||
|
|
|
@ -30,33 +30,32 @@ public class MouseHandlerMixin {
|
|||
return original;
|
||||
}
|
||||
|
||||
if (player.hasEffect(TargetModMobEffects.SHOCK.get()) && !player.isSpectator()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ItemStack stack = mc.player.getMainHandItem();
|
||||
|
||||
boolean flag = false;
|
||||
boolean shock = false;
|
||||
float sens = 0.2f;
|
||||
float fov = (float) player.getPersistentData().getDouble("fov");
|
||||
float custom_sens = (float) stack.getOrCreateTag().getInt("sensitivity");
|
||||
|
||||
float original_fov = mc.options.fov().get();
|
||||
|
||||
if (!player.getMainHandItem().isEmpty() && mc.options.getCameraType() == CameraType.FIRST_PERSON) {
|
||||
if (stack.is(TargetModTags.Items.GUN)) {
|
||||
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zooming) {
|
||||
additionalAdsSensitivity = (float) Mth.clamp((1 + 0.1f * custom_sens) * (1.25F * fov / original_fov) * (1 + 0.2f * Math.pow((original_fov / fov), 1.25)), 0.125F, 2F);
|
||||
} else {
|
||||
additionalAdsSensitivity = Mth.clamp((1 + 0.1f * custom_sens) * 1.25F, 0.125F, 2F);
|
||||
}
|
||||
flag = true;
|
||||
} else {
|
||||
if (!stack.is(TargetModTags.Items.GUN)) {
|
||||
return original;
|
||||
}
|
||||
|
||||
boolean flag = false;
|
||||
float sens = 0.2f;
|
||||
float fov = (float) player.getPersistentData().getDouble("fov");
|
||||
float customSens = (float) stack.getOrCreateTag().getInt("sensitivity");
|
||||
|
||||
float originalFov = mc.options.fov().get();
|
||||
|
||||
if (!player.getMainHandItem().isEmpty() && mc.options.getCameraType() == CameraType.FIRST_PERSON) {
|
||||
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zooming) {
|
||||
additionalAdsSensitivity = (float) Mth.clamp((1 + 0.1f * customSens) * (1.25F * fov / originalFov) * (1 + 0.2f * Math.pow((originalFov / fov), 1.25)), 0.125F, 2F);
|
||||
} else {
|
||||
additionalAdsSensitivity = Mth.clamp((1 + 0.1f * customSens) * 1.25F, 0.125F, 2F);
|
||||
}
|
||||
flag = true;
|
||||
}
|
||||
|
||||
if (Minecraft.getInstance().player.hasEffect(TargetModMobEffects.SHOCK.get()) && !Minecraft.getInstance().player.isSpectator()) {
|
||||
shock = true;
|
||||
}
|
||||
|
||||
return original * additionalAdsSensitivity * (1.0 - sens * (flag ? 1 : 0)) * (shock ? 0 : 1);
|
||||
return original * additionalAdsSensitivity * (1.0 - sens * (flag ? 1 : 0));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import net.mcreator.target.init.TargetModSounds;
|
|||
import net.mcreator.target.init.TargetModTags;
|
||||
import net.mcreator.target.tools.SoundTool;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
@ -35,14 +34,14 @@ public class AdjustZoomFovMessage {
|
|||
}
|
||||
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
var tag = stack.getOrCreateTag();
|
||||
if (!stack.is(TargetModTags.Items.GUN)) {
|
||||
return;
|
||||
}
|
||||
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));
|
||||
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) {
|
||||
SoundTool.playLocalSound(player, TargetModSounds.ADJUST_FOV.get(), 1f, 0.7f);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class FireModeMessage {
|
|||
public static void pressAction(Player player, int type) {
|
||||
if (player == null) return;
|
||||
// security measure to prevent arbitrary chunk generation
|
||||
if (!player.level().hasChunkAt(player.blockPosition()))
|
||||
if (!player.level().isLoaded(player.blockPosition()))
|
||||
return;
|
||||
if (type == 0) {
|
||||
changeFireMode(player);
|
||||
|
@ -50,7 +50,6 @@ public class FireModeMessage {
|
|||
}
|
||||
|
||||
private static void setFireMode(Player player, CompoundTag tag) {
|
||||
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
serverPlayer.connection.send(new ClientboundSoundPacket(new Holder.Direct<>(TargetModSounds.FIRE_RATE.get()),
|
||||
SoundSource.PLAYERS, serverPlayer.getX(), serverPlayer.getY(), serverPlayer.getZ(), 1f, 1f, serverPlayer.level().random.nextLong()));
|
||||
|
|
Loading…
Add table
Reference in a new issue