微调camera摇晃效果,营业妨碍麻痹时修改按键的mixin
This commit is contained in:
parent
44c60a0a18
commit
37d6ddaee1
5 changed files with 82 additions and 43 deletions
|
@ -107,6 +107,23 @@ public class Target1Entity extends PathfinderMob implements GeoEntity, AnimatedE
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hurt(DamageSource source, float amount) {
|
public boolean hurt(DamageSource source, float amount) {
|
||||||
|
|
||||||
|
if (source.is(DamageTypes.IN_FIRE)
|
||||||
|
|| source.getDirectEntity() instanceof ThrownPotion
|
||||||
|
|| source.getDirectEntity() instanceof AreaEffectCloud
|
||||||
|
|| source.is(DamageTypes.FALL)
|
||||||
|
|| source.is(DamageTypes.CACTUS)
|
||||||
|
|| source.is(DamageTypes.DROWN)
|
||||||
|
|| source.is(DamageTypes.LIGHTNING_BOLT)
|
||||||
|
|| source.is(DamageTypes.FALLING_ANVIL)
|
||||||
|
|| source.is(DamageTypes.DRAGON_BREATH)
|
||||||
|
|| source.is(DamageTypes.WITHER)
|
||||||
|
|| source.is(DamageTypes.WITHER_SKULL)
|
||||||
|
|| source.is(DamageTypes.MAGIC)
|
||||||
|
|| this.getPersistentData().getDouble("target_down") > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.level().isClientSide()) {
|
if (!this.level().isClientSide()) {
|
||||||
this.level().playSound(null, BlockPos.containing(this.getX(), this.getY(), this.getZ()), TargetModSounds.HIT.get(), SoundSource.BLOCKS, 8, 1);
|
this.level().playSound(null, BlockPos.containing(this.getX(), this.getY(), this.getZ()), TargetModSounds.HIT.get(), SoundSource.BLOCKS, 8, 1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -139,31 +156,6 @@ public class Target1Entity extends PathfinderMob implements GeoEntity, AnimatedE
|
||||||
super.readAdditionalSaveData(compound);
|
super.readAdditionalSaveData(compound);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onEntityAttacked(LivingAttackEvent event, DamageSource source) {
|
|
||||||
var entity = event.getEntity();
|
|
||||||
if (entity == null) return;
|
|
||||||
if (entity instanceof Target1Entity target1) {
|
|
||||||
|
|
||||||
if (source.is(DamageTypes.IN_FIRE)
|
|
||||||
|| source.getDirectEntity() instanceof ThrownPotion
|
|
||||||
|| source.getDirectEntity() instanceof AreaEffectCloud
|
|
||||||
|| source.is(DamageTypes.FALL)
|
|
||||||
|| source.is(DamageTypes.CACTUS)
|
|
||||||
|| source.is(DamageTypes.DROWN)
|
|
||||||
|| source.is(DamageTypes.LIGHTNING_BOLT)
|
|
||||||
|| source.is(DamageTypes.FALLING_ANVIL)
|
|
||||||
|| source.is(DamageTypes.DRAGON_BREATH)
|
|
||||||
|| source.is(DamageTypes.WITHER)
|
|
||||||
|| source.is(DamageTypes.WITHER_SKULL)
|
|
||||||
|| source.is(DamageTypes.MAGIC)) {
|
|
||||||
event.setCanceled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity.getPersistentData().getDouble("target_down") > 0) {
|
|
||||||
event.setCanceled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onTarget1Down(LivingDeathEvent event) {
|
public static void onTarget1Down(LivingDeathEvent event) {
|
||||||
var entity = event.getEntity();
|
var entity = event.getEntity();
|
||||||
|
@ -342,13 +334,11 @@ public class Target1Entity extends PathfinderMob implements GeoEntity, AnimatedE
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityDimensions getDimensions(Pose p_33597_) {
|
public EntityDimensions getDimensions(Pose p_33597_) {
|
||||||
float num;
|
Entity entity = this;
|
||||||
if (this.getPersistentData().getDouble("target_down") > 0) {
|
float num = 0;
|
||||||
|
if (entity.getPersistentData().getDouble("target_down") > 0) {
|
||||||
num = 0.1f;
|
num = 0.1f;
|
||||||
} else {
|
|
||||||
num = 1f;
|
|
||||||
}
|
}
|
||||||
|
return super.getDimensions(p_33597_).scale(0.1f);
|
||||||
return super.getDimensions(p_33597_).scale(num);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ import net.minecraftforge.fml.common.Mod;
|
||||||
public class ClientEventHandler {
|
public class ClientEventHandler {
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onRenderHand(RenderHandEvent event) {
|
public static void handleWeaponTurn(RenderHandEvent event) {
|
||||||
LocalPlayer player = Minecraft.getInstance().player;
|
LocalPlayer player = Minecraft.getInstance().player;
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -208,10 +208,10 @@ public class ClientEventHandler {
|
||||||
if (-0.8 < velocity + 0.078 && velocity + 0.078 < 0.8) {
|
if (-0.8 < velocity + 0.078 && velocity + 0.078 < 0.8) {
|
||||||
if (data.getDouble("vy") < entity.getDeltaMovement().y() + 0.078) {
|
if (data.getDouble("vy") < entity.getDeltaMovement().y() + 0.078) {
|
||||||
data.putDouble("vy",
|
data.putDouble("vy",
|
||||||
((data.getDouble("vy") + 0.5 * Math.pow((velocity + 0.078) - data.getDouble("vy"), 2)) * (1 - 0.3 * data.getDouble("zoom_time"))));
|
((data.getDouble("vy") + 0.35 * Math.pow((velocity + 0.078) - data.getDouble("vy"), 2)) * (1 - 0.3 * data.getDouble("zoom_time"))));
|
||||||
} else {
|
} else {
|
||||||
data.putDouble("vy",
|
data.putDouble("vy",
|
||||||
((data.getDouble("vy") - 0.5 * Math.pow((velocity + 0.078) - data.getDouble("vy"), 2)) * (1 - 0.3 * data.getDouble("zoom_time"))));
|
((data.getDouble("vy") - 0.35 * Math.pow((velocity + 0.078) - data.getDouble("vy"), 2)) * (1 - 0.3 * data.getDouble("zoom_time"))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data.getDouble("vy") > 0.8) {
|
if (data.getDouble("vy") > 0.8) {
|
||||||
|
@ -351,13 +351,14 @@ public class ClientEventHandler {
|
||||||
double yaw = event.getYaw();
|
double yaw = event.getYaw();
|
||||||
double pitch = event.getPitch();
|
double pitch = event.getPitch();
|
||||||
double roll = event.getRoll();
|
double roll = event.getRoll();
|
||||||
|
if (entity.getMainHandItem().is(TargetModTags.Items.GUN)) {
|
||||||
|
|
||||||
event.setPitch((float) (pitch + data.getDouble("camera_rot_x")));
|
event.setPitch((float) (pitch + data.getDouble("camera_rot_x") + 0.2 * data.getDouble("xRot") + 3 * data.getDouble("vy")));
|
||||||
|
|
||||||
event.setYaw((float) (yaw + data.getDouble("camera_rot_y")));
|
event.setYaw((float) (yaw + data.getDouble("camera_rot_y") + 0.8 * data.getDouble("yRot")));
|
||||||
|
|
||||||
event.setRoll((float) (roll + data.getDouble("camera_rot_z")));
|
|
||||||
|
|
||||||
|
event.setRoll((float) (roll + data.getDouble("camera_rot_z") + 0.35 * data.getDouble("zRot")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleBowPullAnimation(LivingEntity entity) {
|
private static void handleBowPullAnimation(LivingEntity entity) {
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package net.mcreator.target.mixins;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.player.Input;
|
||||||
|
import net.minecraft.client.player.KeyboardInput;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import net.mcreator.target.init.TargetModMobEffects;
|
||||||
|
|
||||||
|
@Mixin(KeyboardInput.class)
|
||||||
|
public abstract class KeyMappingMixin extends Input {
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private static long virtuarealcraft$counter = 0;
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
private static float calculateImpulse(boolean pInput, boolean pOtherInput) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按键修改mixin
|
||||||
|
@Inject(method = "tick", at = @At("RETURN"))
|
||||||
|
public void tick(boolean pIsSneaking, float pSneakingSpeedMultiplier, CallbackInfo ci) {
|
||||||
|
if (Minecraft.getInstance().player == null || !Minecraft.getInstance().player.hasEffect(TargetModMobEffects.SHOCK.get())
|
||||||
|
|| Minecraft.getInstance().player.isSpectator()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var moveKeyDown = this.up | this.down | this.left | this.right;
|
||||||
|
|
||||||
|
this.up = false;
|
||||||
|
this.down = false;
|
||||||
|
|
||||||
|
virtuarealcraft$counter++;
|
||||||
|
var reserveLeftAndRight = virtuarealcraft$counter % 3 == 0;
|
||||||
|
this.left &= reserveLeftAndRight;
|
||||||
|
this.right &= reserveLeftAndRight;
|
||||||
|
|
||||||
|
this.shiftKeyDown = false;
|
||||||
|
|
||||||
|
this.forwardImpulse = Math.min(calculateImpulse(moveKeyDown, false) + 0.6f, 1);
|
||||||
|
this.leftImpulse *= 0.3f;
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,13 +29,12 @@ public class ShockMobEffect extends MobEffect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyEffectTick(LivingEntity entity, int amplifier) {
|
public void applyEffectTick(LivingEntity entity, int amplifier) {
|
||||||
entity.setDeltaMovement(new Vec3(0, (entity.getDeltaMovement().y()), 0));
|
// entity.setDeltaMovement(new Vec3(0, (entity.getDeltaMovement().y()), 0));
|
||||||
|
|
||||||
if (!entity.level().isClientSide()) {
|
// if (!entity.level().isClientSide()) {
|
||||||
entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 10, 10));
|
// entity.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 10, 10));
|
||||||
}
|
// }
|
||||||
|
|
||||||
entity.setShiftKeyDown(true);
|
|
||||||
entity.setYRot((float) (entity.getYRot() + Mth.nextDouble(RandomSource.create(), -15, 15)));
|
entity.setYRot((float) (entity.getYRot() + Mth.nextDouble(RandomSource.create(), -15, 15)));
|
||||||
entity.setXRot((float) Mth.nextDouble(RandomSource.create(), -20, -23));
|
entity.setXRot((float) Mth.nextDouble(RandomSource.create(), -20, -23));
|
||||||
entity.setYBodyRot(entity.getYRot());
|
entity.setYBodyRot(entity.getYRot());
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
"ClientboundSetEntityMotionPacketMixin"
|
"ClientboundSetEntityMotionPacketMixin"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
|
"KeyMappingMixin",
|
||||||
"GameRendererMixin",
|
"GameRendererMixin",
|
||||||
"MouseHandlerMixin"
|
"MouseHandlerMixin"
|
||||||
],
|
],
|
||||||
|
|
Loading…
Add table
Reference in a new issue