diff --git a/src/main/java/com/atsuishio/superbwarfare/ModUtils.java b/src/main/java/com/atsuishio/superbwarfare/ModUtils.java index 27459d451..002551a07 100644 --- a/src/main/java/com/atsuishio/superbwarfare/ModUtils.java +++ b/src/main/java/com/atsuishio/superbwarfare/ModUtils.java @@ -148,6 +148,7 @@ public class ModUtils { addNetworkMessage(ShootMessage.class, ShootMessage::encode, ShootMessage::decode, ShootMessage::handler); addNetworkMessage(LaserShootMessage.class, LaserShootMessage::encode, LaserShootMessage::decode, LaserShootMessage::handler); addNetworkMessage(ShootClientMessage.class, ShootClientMessage::encode, ShootClientMessage::decode, ShootClientMessage::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT)); + addNetworkMessage(ShakeClientMessage.class, ShakeClientMessage::encode, ShakeClientMessage::decode, ShakeClientMessage::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT)); addNetworkMessage(DrawClientMessage.class, DrawClientMessage::encode, DrawClientMessage::decode, DrawClientMessage::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT)); addNetworkMessage(EditModeMessage.class, EditModeMessage::encode, EditModeMessage::decode, EditModeMessage::handler); addNetworkMessage(EditMessage.class, EditMessage::encode, EditMessage::decode, EditMessage::handler); diff --git a/src/main/java/com/atsuishio/superbwarfare/datagen/ModDamageTypeTagProvider.java b/src/main/java/com/atsuishio/superbwarfare/datagen/ModDamageTypeTagProvider.java index 82583aed9..9b166fc80 100644 --- a/src/main/java/com/atsuishio/superbwarfare/datagen/ModDamageTypeTagProvider.java +++ b/src/main/java/com/atsuishio/superbwarfare/datagen/ModDamageTypeTagProvider.java @@ -24,10 +24,16 @@ public class ModDamageTypeTagProvider extends DamageTypeTagsProvider { this.tag(ModTags.DamageTypes.PROJECTILE).add(ModDamageTypes.GUN_FIRE, ModDamageTypes.GUN_FIRE_HEADSHOT, DamageTypes.ARROW, DamageTypes.TRIDENT, DamageTypes.THROWN) .addOptional(new ResourceLocation("tacz", "bullet")) - .addOptional(new ResourceLocation("tacz", "bullet_void")); + .addOptional(new ResourceLocation("tacz", "bullet_void")) + .addOptional(new ResourceLocation("virtuarealcraft", "rain_crystal")) + .addOptional(new ResourceLocation("virtuarealcraft", "rain_shower_butterfly")) + .addOptional(new ResourceLocation("virtuarealcraft", "sparkle_butterfly")) + .addOptional(new ResourceLocation("dreamaticvoyage", "blood_crystal")) + .addOptional(new ResourceLocation("dreamaticvoyage", "leviy_beam")); this.tag(ModTags.DamageTypes.PROJECTILE_ABSOLUTE).add(ModDamageTypes.GUN_FIRE_ABSOLUTE, ModDamageTypes.GUN_FIRE_HEADSHOT_ABSOLUTE) .addOptional(new ResourceLocation("tacz", "bullet_ignore_armor")) - .addOptional(new ResourceLocation("tacz", "bullet_void_ignore_armor")); + .addOptional(new ResourceLocation("tacz", "bullet_void_ignore_armor")) + .addOptional(new ResourceLocation("dreamaticvoyage", "leviy_beam_absolute")); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/Mk42Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/Mk42Entity.java index 837f95862..0739ae3be 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/Mk42Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/Mk42Entity.java @@ -1,10 +1,12 @@ package com.atsuishio.superbwarfare.entity; +import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.config.server.ExplosionDestroyConfig; import com.atsuishio.superbwarfare.entity.projectile.CannonShellEntity; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.ContainerBlockItem; import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem; +import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.SoundTool; @@ -32,6 +34,7 @@ import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.network.NetworkHooks; +import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PlayMessages; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; @@ -68,7 +71,7 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity { @Override public void addAdditionalSaveData(CompoundTag compound) { - compound.putInt("CoolDown", this.entityData.get(COOL_DOWN)); + compound.putInt("oolDown", this.entityData.get(COOL_DOWN)); compound.putFloat("Health", this.entityData.get(HEALTH)); } @@ -104,7 +107,7 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity { @Override public double getPassengersRidingOffset() { - return super.getPassengersRidingOffset() - 1.25; + return super.getPassengersRidingOffset() - 0.25; } @Override @@ -324,7 +327,6 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity { double z = this.getZ() + 9 * this.getLookAngle().z; server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, x, y, z, 10, 0.4, 0.4, 0.4, 0.0075); - server.sendParticles(ParticleTypes.CLOUD, x, y, z, 10, 0.4, 0.4, 0.4, 0.0075); int count = 6; @@ -336,6 +338,10 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity { this.getZ() + i * this.getLookAngle().z, Mth.clamp(count--, 1, 5), 0.15, 0.15, 0.15, 0.0025); } + + if (player.level() instanceof ServerLevel && player instanceof ServerPlayer serverPlayer) { + ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(15,15,45, this.getX(), this.getY(), this.getZ())); + } } } @@ -380,13 +386,6 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity { float f1 = Mth.clamp(f, -85.0F, 16.3F); entity.xRotO += f1 - f; entity.setXRot(entity.getXRot() + f1 - f); - -// entity.setYBodyRot(this.getYRot()); -// float f2 = Mth.wrapDegrees(entity.getYRot() - this.getYRot()); -// float f3 = Mth.clamp(f2, -60.0F, 60.0F); -// entity.yRotO += f3 - f2; -// entity.setYRot(entity.getYRot() + f3 - f2); -// entity.setYHeadRot(entity.getYRot()); } @Override @@ -398,7 +397,6 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity { if (this.entityData.get(COOL_DOWN) > 10) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mk42.fire")); } - return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mk42.idle")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/Mle1934Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/Mle1934Entity.java index 266fb4464..1a51dda5b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/Mle1934Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/Mle1934Entity.java @@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.entity.projectile.CannonShellEntity; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.ContainerBlockItem; import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem; +import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.SoundTool; @@ -33,6 +34,7 @@ import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.network.NetworkHooks; +import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PlayMessages; import org.joml.Vector3d; import software.bernie.geckolib.animatable.GeoEntity; @@ -112,7 +114,7 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity { @Override public double getPassengersRidingOffset() { - return super.getPassengersRidingOffset() - 1.075; + return super.getPassengersRidingOffset() - 0.075; } @Override @@ -422,6 +424,10 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity { this.getY(), this.getZ() + 5 * this.getLookAngle().z, 100, 7, 0.02, 7, 0.005); + + if (player.level() instanceof ServerLevel && player instanceof ServerPlayer serverPlayer) { + ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(17,20,50, this.getX(), this.getY(), this.getZ())); + } } } @@ -434,7 +440,6 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity { public void travel() { Entity passenger = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0); - if (!(passenger instanceof LivingEntity entity)) return; float passengerY = entity.getYHeadRot(); @@ -472,6 +477,8 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity { this.clampRotation(entity); } + + private PlayState movementPredicate(AnimationState event) { if (this.entityData.get(COOL_DOWN) > 64) { if (this.entityData.get(TYPE) == 1) { diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/model/Mk42Model.java b/src/main/java/com/atsuishio/superbwarfare/entity/model/Mk42Model.java index 02e88a568..feccc9c46 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/model/Mk42Model.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/model/Mk42Model.java @@ -1,8 +1,7 @@ package com.atsuishio.superbwarfare.entity.model; -import com.atsuishio.superbwarfare.entity.Mk42Entity; import com.atsuishio.superbwarfare.ModUtils; -import com.atsuishio.superbwarfare.event.ClientEventHandler; +import com.atsuishio.superbwarfare.entity.Mk42Entity; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; @@ -49,10 +48,5 @@ public class Mk42Model extends GeoModel { CoreGeoBone bone = getAnimationProcessor().getBone("maingun"); EntityModelData entityData = animationState.getData(DataTickets.ENTITY_MODEL_DATA); bone.setRotX((entityData.headPitch()) * Mth.DEG_TO_RAD); - - CoreGeoBone camera = getAnimationProcessor().getBone("camera"); - - if (animatable.getFirstPassenger() == null) return; - ClientEventHandler.shake(Mth.RAD_TO_DEG * camera.getRotX(), Mth.RAD_TO_DEG * camera.getRotY(), Mth.RAD_TO_DEG * camera.getRotZ()); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/model/Mle1934Model.java b/src/main/java/com/atsuishio/superbwarfare/entity/model/Mle1934Model.java index a2a7058c3..91b0d451e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/model/Mle1934Model.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/model/Mle1934Model.java @@ -1,8 +1,7 @@ package com.atsuishio.superbwarfare.entity.model; -import com.atsuishio.superbwarfare.entity.Mle1934Entity; import com.atsuishio.superbwarfare.ModUtils; -import com.atsuishio.superbwarfare.event.ClientEventHandler; +import com.atsuishio.superbwarfare.entity.Mle1934Entity; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; @@ -48,10 +47,5 @@ public class Mle1934Model extends GeoModel { CoreGeoBone barrle = getAnimationProcessor().getBone("barrel"); EntityModelData entityData = (EntityModelData) animationState.getData(DataTickets.ENTITY_MODEL_DATA); barrle.setRotX((entityData.headPitch()) * Mth.DEG_TO_RAD); - - CoreGeoBone camera = getAnimationProcessor().getBone("camera"); - - if (animatable.getFirstPassenger() == null) return; - ClientEventHandler.shake(Mth.RAD_TO_DEG * camera.getRotX(),Mth.RAD_TO_DEG * camera.getRotY(), Mth.RAD_TO_DEG * camera.getRotZ()); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HandGrenadeEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HandGrenadeEntity.java index 1ea5f0c84..0435a4846 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HandGrenadeEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HandGrenadeEntity.java @@ -1,12 +1,12 @@ package com.atsuishio.superbwarfare.entity.projectile; +import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.init.ModEntities; +import com.atsuishio.superbwarfare.init.ModItems; +import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.network.message.ClientIndicatorMessage; import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ProjectileTool; -import com.atsuishio.superbwarfare.ModUtils; -import com.atsuishio.superbwarfare.init.ModItems; -import com.atsuishio.superbwarfare.init.ModSounds; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.particles.ParticleTypes; @@ -16,7 +16,6 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundSource; -import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -28,7 +27,6 @@ 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.minecraft.world.phys.Vec3; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PlayMessages; @@ -139,15 +137,6 @@ public class HandGrenadeEntity extends ThrowableItemProjectile { 1, 0, 0, 0, 0.01, true); } } - @Override - public void shootFromRotation(Entity pShooter, float pX, float pY, float pZ, float pVelocity, float pInaccuracy) { - float f = -Mth.sin(pY * 0.017453292F) * Mth.cos(pX * 0.017453292F); - float f1 = -Mth.sin((pX + pZ) * 0.017453292F); - float f2 = Mth.cos(pY * 0.017453292F) * Mth.cos(pX * 0.017453292F); - this.shoot((double)f, (double)f1, (double)f2, pVelocity, pInaccuracy); - Vec3 vec3 = pShooter.getDeltaMovement(); - this.setDeltaMovement(this.getDeltaMovement().add(vec3.x, pShooter.onGround() ? 0.0 : -vec3.y, vec3.z)); - } @Override protected float getGravity() { diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RgoGrenadeEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RgoGrenadeEntity.java index 67b6fff21..d5823f6a0 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RgoGrenadeEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RgoGrenadeEntity.java @@ -78,9 +78,7 @@ public class RgoGrenadeEntity extends ThrowableItemProjectile implements GeoEnti if (state.getBlock() instanceof BellBlock bell) { bell.attemptToRing(this.level(), resultPos, blockResult.getDirection()); } - if (this.tickCount > 2) { - ProjectileTool.causeCustomExplode(this, 100f, 4f, 1.2f); - } + ProjectileTool.causeCustomExplode(this, 100f, 4f, 1.2f); break; case ENTITY: @@ -93,7 +91,7 @@ public class RgoGrenadeEntity extends ThrowableItemProjectile implements GeoEnti ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(0, 5)); } } - if (this.tickCount > 2 && !(entity instanceof DroneEntity)) { + if (entity instanceof DroneEntity) { ProjectileTool.causeCustomExplode(this, 100f, 4f, 1.2f); } break; @@ -114,11 +112,9 @@ public class RgoGrenadeEntity extends ThrowableItemProjectile implements GeoEnti } } - if (this.tickCount > 2) { - if (!this.level().isClientSide() && this.level() instanceof ServerLevel serverLevel) { - ParticleTool.sendParticle(serverLevel, ParticleTypes.SMOKE, this.xo, this.yo, this.zo, - 1, 0, 0, 0, 0.01, true); - } + if (!this.level().isClientSide() && this.level() instanceof ServerLevel serverLevel) { + ParticleTool.sendParticle(serverLevel, ParticleTypes.SMOKE, this.xo, this.yo, this.zo, + 1, 0, 0, 0, 0.01, true); } } @@ -146,13 +142,4 @@ public class RgoGrenadeEntity extends ThrowableItemProjectile implements GeoEnti this.xRotO = this.getXRot(); } - @Override - public void shootFromRotation(Entity pShooter, float pX, float pY, float pZ, float pVelocity, float pInaccuracy) { - float f = -Mth.sin(pY * 0.017453292F) * Mth.cos(pX * 0.017453292F); - float f1 = -Mth.sin((pX + pZ) * 0.017453292F); - float f2 = Mth.cos(pY * 0.017453292F) * Mth.cos(pX * 0.017453292F); - this.shoot((double)f, (double)f1, (double)f2, pVelocity, pInaccuracy); - Vec3 vec3 = pShooter.getDeltaMovement(); - this.setDeltaMovement(this.getDeltaMovement().add(vec3.x, pShooter.onGround() ? 0.0 : -vec3.y, vec3.z)); - } } diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index c77587719..d86dc084e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -6,7 +6,6 @@ import com.atsuishio.superbwarfare.config.client.DisplayConfig; import com.atsuishio.superbwarfare.entity.DroneEntity; import com.atsuishio.superbwarfare.entity.ICannonEntity; import com.atsuishio.superbwarfare.init.*; -import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem; import com.atsuishio.superbwarfare.network.ModVariables; import com.atsuishio.superbwarfare.network.message.LaserShootMessage; import com.atsuishio.superbwarfare.network.message.ShootMessage; @@ -20,6 +19,7 @@ import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.player.LocalPlayer; import net.minecraft.commands.arguments.EntityAnchorArgument; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; import net.minecraft.util.Mth; @@ -35,6 +35,7 @@ import net.minecraft.world.phys.Vec3; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.RenderGuiOverlayEvent; import net.minecraftforge.client.event.RenderHandEvent; +import net.minecraftforge.client.event.RenderPlayerEvent; import net.minecraftforge.client.event.ViewportEvent; import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay; import net.minecraftforge.common.capabilities.ForgeCapabilities; @@ -123,9 +124,13 @@ public class ClientEventHandler { public static int miniGunRot = 0; public static double revolverPreTime = 0; - public static double revolverWheelPreTime = 0; + public static double shakeTime = 0; + public static double shakeRadius = 0; + public static double shakeAmplitude = 0; + public static double[] shakePos = {0, 0, 0}; + public static double shakeType = 0; @SubscribeEvent public static void handleWeaponTurn(RenderHandEvent event) { @@ -201,6 +206,7 @@ public class ClientEventHandler { } beamShoot(player, stack); + } @SubscribeEvent @@ -439,7 +445,9 @@ public class ClientEventHandler { public static void handleClientShoot() { Player player = Minecraft.getInstance().player; if (player == null) return; + CompoundTag tag = player.getMainHandItem().getOrCreateTag(); + if (!player.getMainHandItem().is(ModTags.Items.GUN)) return; ModUtils.PACKET_HANDLER.sendToServer(new ShootMessage(gunSpread)); @@ -459,6 +467,20 @@ public class ClientEventHandler { randomShell[2] = (0.7 + (Math.random() - 0.5)); } + public static void handleShakeClient(double time, double radius, double amplitude, double x, double y,double z, Supplier ctx) { + if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) { + Player player = Minecraft.getInstance().player; + if (player == null) return; + shakeTime = time; + shakeRadius = radius; + shakeAmplitude = amplitude * Mth.DEG_TO_RAD; + shakePos[0] = x; + shakePos[1] = y; + shakePos[2] = z; + shakeType = 2 * (Math.random() - 0.5); + } + } + public static void playGunClientSounds(Player player) { ItemStack stack = player.getMainHandItem(); if (!stack.is(ModTags.Items.GUN)) { @@ -561,6 +583,7 @@ public class ClientEventHandler { ClientLevel level = Minecraft.getInstance().level; Entity entity = event.getCamera().getEntity(); handlePlayerCamera(event); + if (level != null && entity instanceof LivingEntity living && living.getMainHandItem().is(ModItems.MONITOR.get()) && living.getMainHandItem().getOrCreateTag().getBoolean("Using") @@ -572,6 +595,7 @@ public class ClientEventHandler { Minecraft.getInstance().gameRenderer.shutdownEffect(); } } + if (level != null && entity instanceof LivingEntity living && living.getMainHandItem().is(ModTags.Items.GUN)) { handleWeaponSway(living); handleWeaponMove(living); @@ -584,6 +608,33 @@ public class ClientEventHandler { handleBowPullAnimation(living); handleWeaponDraw(living); } + + float times = Minecraft.getInstance().getDeltaFrameTime(); + LocalPlayer player = Minecraft.getInstance().player; + + float yaw = event.getYaw(); + float pitch = event.getPitch(); + float roll = event.getRoll(); + float shakeRadiusAmplitude; + + shakeTime = Mth.lerp(0.25 * times, shakeTime, 0); + + if (player != null && shakeTime > 0) { + shakeRadiusAmplitude = (float) (1 - player.position().distanceTo(new Vec3(shakePos[0], shakePos[1], shakePos[2])) / shakeRadius); + + player.displayClientMessage(Component.literal(new java.text.DecimalFormat("##.##").format(shakeRadiusAmplitude)), true); + + if (shakeType > 0) { + event.setYaw((float) (yaw + (shakeTime * Math.sin(0.5 *Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * 0.75 * shakeType))); + event.setPitch((float) (pitch - (shakeTime * Math.sin(0.5 *Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType))); + event.setRoll((float) (roll - (shakeTime * Math.sin(0.5 *Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude))); + } else { + event.setYaw((float) (yaw - (shakeTime * Math.sin(0.5 *Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * 0.75 * shakeType))); + event.setPitch((float) (pitch + (shakeTime * Math.sin(0.5 *Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude * shakeType))); + event.setRoll((float) (roll + (shakeTime * Math.sin(0.5 *Math.PI * shakeTime) * shakeAmplitude * shakeRadiusAmplitude))); + } + + } } public static void droneBodyAngle(float RotX, float RotZ) { @@ -998,7 +1049,7 @@ public class ClientEventHandler { angle = Math.atan(Mth.abs((float) cameraLocation) / (lookDistance + 2.9)) * Mth.RAD_TO_DEG; } - if (player.getMainHandItem().is(ModTags.Items.GUN) || (player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity && player.getMainHandItem().getItem() instanceof CannonShellItem)) { + if (player.getMainHandItem().is(ModTags.Items.GUN)) { event.setPitch((float) (pitch + cameraRot[0] + (DisplayConfig.CAMERA_ROTATE.get() ? 0.2 : 0) * turnRot[0] + 3 * velocityY)); if (Minecraft.getInstance().options.getCameraType() == CameraType.THIRD_PERSON_BACK) { event.setYaw((float) (yaw + cameraRot[1] + (DisplayConfig.CAMERA_ROTATE.get() ? 0.8 : 0) * turnRot[1] - (cameraLocation > 0 ? 1 : -1) * angle * zoomPos)); @@ -1091,6 +1142,15 @@ public class ClientEventHandler { } } + @SubscribeEvent + public static void setPlayerInvisible(RenderPlayerEvent.Pre event) { + var otherPlayer = event.getEntity(); + + if (otherPlayer.getVehicle() instanceof ICannonEntity) { + event.setCanceled(true); + } + } + @SubscribeEvent public static void handleRenderCrossHair(RenderGuiOverlayEvent.Pre event) { if (event.getOverlay() != VanillaGuiOverlay.CROSSHAIR.type()) { diff --git a/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java index a48523488..9f5559137 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java @@ -120,36 +120,27 @@ public class LivingEventHandler { } //计算防弹插板减伤 - if (source.is(ModTags.DamageTypes.PROJECTILE) || source.is(ModTags.DamageTypes.PROJECTILE_ABSOLUTE) - || source.is(ModDamageTypes.PROJECTILE_BOOM) - || source.is(ModDamageTypes.MINE) - || source.is(ModDamageTypes.CANNON_FIRE) - || source.is(ModDamageTypes.CUSTOM_EXPLOSION) - || source.is(DamageTypes.EXPLOSION) - || source.is(DamageTypes.PLAYER_EXPLOSION) - || source.is(DamageTypes.MOB_PROJECTILE)) { - ItemStack armor = entity.getItemBySlot(EquipmentSlot.CHEST); + ItemStack armor = entity.getItemBySlot(EquipmentSlot.CHEST); - if (armor != ItemStack.EMPTY && armor.getTag() != null && armor.getTag().contains("ArmorPlate")) { - double armorValue; - armorValue = armor.getOrCreateTag().getDouble("ArmorPlate"); - armor.getOrCreateTag().putDouble("ArmorPlate", Math.max(armor.getOrCreateTag().getDouble("ArmorPlate") - damage, 0)); - damage = Math.max(damage - armorValue, 0); - } + if (armor != ItemStack.EMPTY && armor.getTag() != null && armor.getTag().contains("ArmorPlate")) { + double armorValue; + armorValue = armor.getOrCreateTag().getDouble("ArmorPlate"); + armor.getOrCreateTag().putDouble("ArmorPlate", Math.max(armor.getOrCreateTag().getDouble("ArmorPlate") - damage, 0)); + damage = Math.max(damage - armorValue, 0); + } - //计算防弹护具减伤 - if (source.is(ModTags.DamageTypes.PROJECTILE) || source.is(DamageTypes.MOB_PROJECTILE)) { - damage *= 1 - 0.8 * Mth.clamp(entity.getAttributeValue(ModAttributes.BULLET_RESISTANCE.get()), 0, 1); - } + //计算防弹护具减伤 + if (source.is(ModTags.DamageTypes.PROJECTILE) || source.is(DamageTypes.MOB_PROJECTILE)) { + damage *= 1 - 0.8 * Mth.clamp(entity.getAttributeValue(ModAttributes.BULLET_RESISTANCE.get()), 0, 1); + } - if (source.is(ModTags.DamageTypes.PROJECTILE_ABSOLUTE)) { - damage *= 1 - 0.2 * Mth.clamp(entity.getAttributeValue(ModAttributes.BULLET_RESISTANCE.get()), 0, 1); - } + if (source.is(ModTags.DamageTypes.PROJECTILE_ABSOLUTE)) { + damage *= 1 - 0.2 * Mth.clamp(entity.getAttributeValue(ModAttributes.BULLET_RESISTANCE.get()), 0, 1); + } - if (source.is(ModDamageTypes.PROJECTILE_BOOM) || source.is(ModDamageTypes.MINE) || source.is(ModDamageTypes.CANNON_FIRE) || source.is(ModDamageTypes.CUSTOM_EXPLOSION) - || source.is(DamageTypes.EXPLOSION) || source.is(DamageTypes.PLAYER_EXPLOSION)) { - damage *= 1 - 0.3 * Mth.clamp(entity.getAttributeValue(ModAttributes.BULLET_RESISTANCE.get()), 0, 1); - } + if (source.is(ModDamageTypes.PROJECTILE_BOOM) || source.is(ModDamageTypes.MINE) || source.is(ModDamageTypes.CANNON_FIRE) || source.is(ModDamageTypes.CUSTOM_EXPLOSION) + || source.is(DamageTypes.EXPLOSION) || source.is(DamageTypes.PLAYER_EXPLOSION)) { + damage *= 1 - 0.3 * Mth.clamp(entity.getAttributeValue(ModAttributes.BULLET_RESISTANCE.get()), 0, 1); } event.setAmount((float) damage); diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java index c9e936cbf..4440da74b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java @@ -1,7 +1,6 @@ package com.atsuishio.superbwarfare.mixins; import com.atsuishio.superbwarfare.entity.DroneEntity; -import com.atsuishio.superbwarfare.entity.ICannonEntity; import com.atsuishio.superbwarfare.entity.Mk42Entity; import com.atsuishio.superbwarfare.entity.Mle1934Entity; import com.atsuishio.superbwarfare.event.ClientEventHandler; @@ -42,11 +41,7 @@ public abstract class CameraMixin { if (player != null) { ItemStack stack = player.getMainHandItem(); - if (player.getVehicle() != null && mc.player.getVehicle() instanceof ICannonEntity && Minecraft.getInstance().options.getCameraType() == CameraType.FIRST_PERSON) { - setRotation(player.getViewYRot(partialTicks), player.getViewXRot(partialTicks)); - setPosition(player.getX(), player.getEyeY() + 1, player.getZ()); - info.cancel(); - } else if (stack.is(ModItems.MONITOR.get()) && stack.getOrCreateTag().getBoolean("Using") && stack.getOrCreateTag().getBoolean("Linked")) { + if (stack.is(ModItems.MONITOR.get()) && stack.getOrCreateTag().getBoolean("Using") && stack.getOrCreateTag().getBoolean("Linked")) { DroneEntity drone = EntityFindUtil.findDrone(player.level(), stack.getOrCreateTag().getString("LinkedDrone")); if (drone != null) { @@ -69,11 +64,11 @@ public abstract class CameraMixin { @Inject(method = "setup", at = @At("TAIL")) public void ia$setup(BlockGetter area, Entity entity, boolean thirdPerson, boolean inverseView, float tickDelta, CallbackInfo ci) { if (thirdPerson && entity.getVehicle() instanceof Mk42Entity) { - move(-getMaxZoom(8), 2, 0.0); + move(-getMaxZoom(8), 1, 0.0); return; } if (thirdPerson && entity.getVehicle() instanceof Mle1934Entity) { - move(-getMaxZoom(10), 2.3, 0.0); + move(-getMaxZoom(10), 1.3, 0.0); return; } if (Minecraft.getInstance().options.getCameraType() == CameraType.THIRD_PERSON_BACK && entity instanceof Player player && player.getMainHandItem().is(ModTags.Items.GUN)) { diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/ShakeClientMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/ShakeClientMessage.java new file mode 100644 index 000000000..0da3e02b2 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/ShakeClientMessage.java @@ -0,0 +1,49 @@ +package com.atsuishio.superbwarfare.network.message; + +import com.atsuishio.superbwarfare.event.ClientEventHandler; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; +import net.minecraftforge.network.NetworkEvent; + +import java.util.function.Supplier; + +public class ShakeClientMessage { + public double time; + public double radius; + public double amplitude; + + public double x; + + public double y; + + public double z; + + public ShakeClientMessage(double time, double radius, double amplitude, double x, double y, double z) { + this.time = time; + this.radius = radius; + this.amplitude = amplitude; + this.x = x; + this.y = y; + this.z = z; + } + + public static void encode(ShakeClientMessage message, FriendlyByteBuf buffer) { + buffer.writeDouble(message.time); + buffer.writeDouble(message.radius); + buffer.writeDouble(message.amplitude); + buffer.writeDouble(message.x); + buffer.writeDouble(message.y); + buffer.writeDouble(message.z); + } + + public static ShakeClientMessage decode(FriendlyByteBuf buffer) { + return new ShakeClientMessage(buffer.readDouble(), buffer.readDouble(), buffer.readDouble(), buffer.readDouble(), buffer.readDouble(), buffer.readDouble()); + } + + public static void handle(ShakeClientMessage message, Supplier context) { + context.get().enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, + () -> () -> ClientEventHandler.handleShakeClient(message.time, message.radius, message.amplitude, message.x, message.y, message.z, context))); + context.get().setPacketHandled(true); + } +} diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java b/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java index aa51dfc1f..fd15a2f5d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java @@ -1,7 +1,10 @@ package com.atsuishio.superbwarfare.tools; +import com.atsuishio.superbwarfare.ModUtils; +import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.google.common.collect.Sets; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; @@ -18,8 +21,10 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; +import net.minecraftforge.network.PacketDistributor; import javax.annotation.Nullable; +import java.util.Comparator; import java.util.List; import java.util.Optional; import java.util.Set; @@ -59,6 +64,15 @@ public class CustomExplosion extends Explosion { public CustomExplosion(Level pLevel, @Nullable Entity pSource, @Nullable DamageSource source, float damage, double pToBlowX, double pToBlowY, double pToBlowZ, float pRadius, Explosion.BlockInteraction pBlockInteraction) { this(pLevel, pSource, source, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, pBlockInteraction); + + final Vec3 center = new Vec3(pToBlowX, pToBlowY, pToBlowZ); + + for (Entity target : level.getEntitiesOfClass(Entity.class, new AABB(center, center).inflate(4 * radius), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(center))).toList()) { + + if (target instanceof ServerPlayer serverPlayer) { + ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(20 + 0.02 * damage,3 * pRadius,60 + 0.05 * damage, pToBlowX, pToBlowY, pToBlowZ)); + } + } } public CustomExplosion setFireTime(int fireTime) { diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 9b83ce759..a8b176dd3 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -25,7 +25,7 @@ side = "BOTH" [[dependencies.superbwarfare]] modId = "curios" -mandatory = false +mandatory = true versionRange = "[5.4.0,)" ordering = "NONE" side = "BOTH"