diff --git a/src/main/java/com/atsuishio/superbwarfare/client/layer/SpeedBoatLayer.java b/src/main/java/com/atsuishio/superbwarfare/client/layer/SpeedBoatLayer.java new file mode 100644 index 000000000..18fe23f42 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/client/layer/SpeedBoatLayer.java @@ -0,0 +1,28 @@ +package com.atsuishio.superbwarfare.client.layer; + +import com.atsuishio.superbwarfare.ModUtils; +import com.atsuishio.superbwarfare.entity.SpeedboatEntity; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.resources.ResourceLocation; +import software.bernie.geckolib.cache.object.BakedGeoModel; +import software.bernie.geckolib.renderer.GeoRenderer; +import software.bernie.geckolib.renderer.layer.GeoRenderLayer; + +public class SpeedBoatLayer extends GeoRenderLayer { + + private static final ResourceLocation LAYER = ModUtils.loc("textures/entity/speedboat_e.png"); + + public SpeedBoatLayer(GeoRenderer entityRenderer) { + super(entityRenderer); + } + + @Override + public void render(PoseStack poseStack, SpeedboatEntity animatable, BakedGeoModel bakedModel, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, float partialTick, int packedLight, int packedOverlay) { + RenderType glowRenderType = RenderType.energySwirl(LAYER,1,1); + getRenderer().reRender(getDefaultBakedModel(animatable), poseStack, bufferSource, animatable, glowRenderType, bufferSource.getBuffer(glowRenderType), partialTick, packedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, 1); + } +} diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/entity/ProjectileEntityModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/entity/ProjectileEntityModel.java index 205cbc8dc..93917605b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/entity/ProjectileEntityModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/entity/ProjectileEntityModel.java @@ -44,7 +44,7 @@ public class ProjectileEntityModel extends GeoModel { CoreGeoBone bone = getAnimationProcessor().getBone("bone"); Player player = Minecraft.getInstance().player; if (player != null) { - bone.setHidden(animatable.position().distanceTo(player.position()) < 3); + bone.setHidden(animatable.position().distanceTo(player.position()) < 3 || animatable.tickCount < 1); } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/entity/SpeedboatModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/entity/SpeedboatModel.java index 7d1304661..a0999b882 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/entity/SpeedboatModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/entity/SpeedboatModel.java @@ -13,8 +13,7 @@ public class SpeedboatModel extends GeoModel { @Override public ResourceLocation getAnimationResource(SpeedboatEntity entity) { - return null; -// return ModUtils.loc("animations/mk_42.animation.json"); + return ModUtils.loc("animations/speedboat.animation.json"); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/SpeedboatRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/SpeedboatRenderer.java index a50cd13e3..6be4932b8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/SpeedboatRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/SpeedboatRenderer.java @@ -1,5 +1,6 @@ package com.atsuishio.superbwarfare.client.renderer.entity; +import com.atsuishio.superbwarfare.client.layer.SpeedBoatLayer; import com.atsuishio.superbwarfare.client.model.entity.SpeedboatModel; import com.atsuishio.superbwarfare.entity.SpeedboatEntity; import com.mojang.blaze3d.vertex.PoseStack; @@ -18,6 +19,7 @@ public class SpeedboatRenderer extends GeoEntityRenderer { public SpeedboatRenderer(EntityRendererProvider.Context renderManager) { super(renderManager, new SpeedboatModel()); + this.addRenderLayer(new SpeedBoatLayer(this)); } @Override @@ -51,6 +53,9 @@ public class SpeedboatRenderer extends GeoEntityRenderer { if (name.equals("gun")) { bone.setRotX(-Mth.lerp(partialTick, animatable.turretXRotO, animatable.getTurretXRot()) * Mth.DEG_TO_RAD); } + if (name.equals("flare")) { + bone.setRotZ((float) (0.5 * (Math.random() - 0.5))); + } super.renderRecursively(poseStack, animatable, bone, renderType, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java index 22db605e9..d2382e652 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java @@ -5,8 +5,10 @@ import com.atsuishio.superbwarfare.config.server.ExplosionDestroyConfig; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.ContainerBlockItem; +import com.atsuishio.superbwarfare.network.ModVariables; import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.ParticleTool; +import com.atsuishio.superbwarfare.tools.SoundTool; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.Packet; @@ -15,6 +17,7 @@ import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; 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; @@ -46,6 +49,10 @@ import org.joml.Math; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.core.animation.AnimatableManager; +import software.bernie.geckolib.core.animation.AnimationController; +import software.bernie.geckolib.core.animation.AnimationState; +import software.bernie.geckolib.core.animation.RawAnimation; +import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.util.GeckoLibUtil; public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, IVehicleEntity { @@ -56,6 +63,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, public static final EntityDataAccessor DELTA_ROT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor POWER = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor ROTOR = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor COOL_DOWN = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT); public static final float MAX_HEALTH = CannonConfig.MK42_HP.get(); @@ -88,6 +96,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, this.entityData.define(DELTA_ROT, 0f); this.entityData.define(POWER, 0f); this.entityData.define(ROTOR, 0f); + this.entityData.define(COOL_DOWN, 0); } @Override @@ -214,6 +223,10 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, public void baseTick() { super.baseTick(); + if (this.entityData.get(COOL_DOWN) > 0) { + this.entityData.set(COOL_DOWN, this.entityData.get(COOL_DOWN) - 1); + } + double fluidFloat; fluidFloat = -0.05 + 0.1 * getSubmergedHeight(this); this.setDeltaMovement(this.getDeltaMovement().add(0.0, fluidFloat, 0.0)); @@ -247,11 +260,41 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, collideBlock(); gunnerAngle(); -// gunnerFire(); + gunnerFire(); this.refreshDimensions(); } + private void gunnerFire() { + if (this.entityData.get(COOL_DOWN) != 0) return; + + Entity driver = this.getFirstPassenger(); + if (driver == null) return; + if (driver instanceof Player player) { + if (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).holdFire) { + ProjectileEntity projectile = new ProjectileEntity(driver.level()) + .shooter(player) + .damage(39) + .headShot(2.5f) + .zoom(false); + + projectile.setPos(this.xo - this.getViewVector(1).scale(0.57).x - this.getDeltaMovement().x, this.yo + 3.0, this.zo - this.getViewVector(1).scale(0.57).z - this.getDeltaMovement().z); + projectile.shoot(player, player.getLookAngle().x, player.getLookAngle().y + 0.001f, player.getLookAngle().z, 25, + (float) 0.3); + this.level().addFreshEntity(projectile); + + if (player instanceof ServerPlayer serverPlayer) { + SoundTool.playLocalSound(serverPlayer, ModSounds.MINIGUN_FIRE_1P.get(), 2, 1); + serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.MINIGUN_FIRE_3P.get(), SoundSource.PLAYERS, 6, 1); + serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.MINIGUN_FAR.get(), SoundSource.PLAYERS, 16, 1); + serverPlayer.level().playSound(null, serverPlayer.getOnPos(), ModSounds.MINIGUN_VERYFAR.get(), SoundSource.PLAYERS, 32, 1); + } + + this.entityData.set(COOL_DOWN, 3); + } + } + } + public void crushEntities(Vec3 velocity) { var frontBox = getBoundingBox().move(velocity.scale(0.5)); var velAdd = velocity.add(0, 0, 0).scale(1.5); @@ -494,9 +537,16 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, } + private PlayState firePredicate(AnimationState event) { + if (this.entityData.get(COOL_DOWN) > 1) { + return event.setAndContinue(RawAnimation.begin().thenPlay("animation.speedboat.fire")); + } + return event.setAndContinue(RawAnimation.begin().thenLoop("animation.speedboat.idle")); + } + @Override public void registerControllers(AnimatableManager.ControllerRegistrar data) { - + data.add(new AnimationController<>(this, "movement", 0, this::firePredicate)); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java index 0c78f4d74..3a9378464 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java @@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.tools.EntityFindUtil; import net.minecraft.client.Camera; import net.minecraft.client.CameraType; import net.minecraft.client.Minecraft; +import net.minecraft.client.player.LocalPlayer; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; @@ -34,7 +35,7 @@ public abstract class CameraMixin { cancellable = true) private void onSetup(BlockGetter level, Entity entity, boolean detached, boolean mirrored, float partialTicks, CallbackInfo info) { Minecraft mc = Minecraft.getInstance(); - Player player = mc.player; + LocalPlayer player = mc.player; if (player != null) { ItemStack stack = player.getMainHandItem(); @@ -45,10 +46,11 @@ public abstract class CameraMixin { yRot += 360; } yRot = yRot + 90 % 360; - var CameraPos = new Vector3d(-0.6, 3.3, 0); + var CameraPos = new Vector3d(-0.57, 3.3, 0); CameraPos.rotateZ(-boat.getXRot() * Mth.DEG_TO_RAD); CameraPos.rotateY(-yRot * Mth.DEG_TO_RAD); - setRotation(player.getViewYRot(partialTicks), player.getViewXRot(partialTicks)); + + setRotation(Mth.lerp(partialTicks, player.yBobO, player.yBob), Mth.lerp(partialTicks, player.xBobO, player.xBob)); setPosition(Mth.lerp(partialTicks, boat.xo + CameraPos.x, boat.getX() + CameraPos.x), Mth.lerp(partialTicks, boat.yo + CameraPos.y, boat.getY() + CameraPos.y), Mth.lerp(partialTicks, boat.zo + CameraPos.z, boat.getZ() + CameraPos.z)); info.cancel(); diff --git a/src/main/resources/assets/superbwarfare/animations/speedboat.animation.json b/src/main/resources/assets/superbwarfare/animations/speedboat.animation.json index 1a0b6b53e..65451e42a 100644 --- a/src/main/resources/assets/superbwarfare/animations/speedboat.animation.json +++ b/src/main/resources/assets/superbwarfare/animations/speedboat.animation.json @@ -2,35 +2,25 @@ "format_version": "1.8.0", "animations": { "animation.speedboat.idle": { - "loop": true, - "animation_length": 1, - "blend_weight": "10", - "start_delay": "10" - }, - "animation.speedboat.forward": { - "loop": true, - "animation_length": 0.5, - "blend_weight": "10", - "start_delay": "10", + "animation_length": 0.1, "bones": { - "Rotor": { - "rotation": { - "0.0": [0, 0, 0], - "0.5": [0, 0, 720] - } + "flare": { + "scale": 0 } } }, - "animation.speedboat.backward": { - "loop": true, - "animation_length": 0.5, - "blend_weight": "10", - "start_delay": "10", + "animation.speedboat.fire": { + "loop": "hold_on_last_frame", + "animation_length": 0.15, "bones": { - "Rotor": { - "rotation": { + "flare": { + "scale": { "0.0": [0, 0, 0], - "0.5": [0, 0, -720] + "0.0083": [8, 8, 8], + "0.05": [8, 8, 8], + "0.075": [1, 1, 1], + "0.0917": [0, 0, 0], + "0.15": [0, 0, 0] } } } diff --git a/src/main/resources/assets/superbwarfare/geo/speedboat.geo.json b/src/main/resources/assets/superbwarfare/geo/speedboat.geo.json index 3c607f869..3e4b755a9 100644 --- a/src/main/resources/assets/superbwarfare/geo/speedboat.geo.json +++ b/src/main/resources/assets/superbwarfare/geo/speedboat.geo.json @@ -4,8 +4,8 @@ { "description": { "identifier": "geometry.unknown", - "texture_width": 64, - "texture_height": 64, + "texture_width": 256, + "texture_height": 256, "visible_bounds_width": 9, "visible_bounds_height": 5, "visible_bounds_offset": [0, 1.5, 0] @@ -510,6 +510,69 @@ } ] }, + { + "name": "flare", + "parent": "gun", + "pivot": [0, 47.54, -15.18133], + "cubes": [ + { + "origin": [-0.60625, 46.93188, -15.25321], + "size": [1.2125, 1.2125, 0], + "pivot": [0, 47.53813, -15.68133], + "rotation": [0, 0, 0], + "uv": { + "north": {"uv": [256, 0], "uv_size": [-64, 64]}, + "east": {"uv": [192, 0], "uv_size": [64, 64]}, + "south": {"uv": [192, 0], "uv_size": [64, 64]}, + "west": {"uv": [192, 0], "uv_size": [64, 64]}, + "up": {"uv": [256, 64], "uv_size": [-64, -64]}, + "down": {"uv": [256, 64], "uv_size": [-64, -64]} + } + }, + { + "origin": [-1.525, 47.03188, -16.78445], + "size": [3.05, 1.0125, 0], + "pivot": [0, 47.53813, -16.78445], + "rotation": [0, -90, 30], + "uv": { + "north": {"uv": [256, 0], "uv_size": [-51.5, 64]}, + "east": {"uv": [204.5, 0], "uv_size": [51.5, 64]}, + "south": {"uv": [204.5, 0], "uv_size": [51.5, 64]}, + "west": {"uv": [204.5, 0], "uv_size": [51.5, 64]}, + "up": {"uv": [256, 64], "uv_size": [-51.5, -64]}, + "down": {"uv": [256, 64], "uv_size": [-51.5, -64]} + } + }, + { + "origin": [-1.525, 47.03187, -16.78446], + "size": [3.05, 1.0125, 0], + "pivot": [0, 47.53813, -16.78445], + "rotation": [0, -90, -31], + "uv": { + "north": {"uv": [256, 0], "uv_size": [-51.5, 64]}, + "east": {"uv": [204.5, 0], "uv_size": [51.5, 64]}, + "south": {"uv": [204.5, 0], "uv_size": [51.5, 64]}, + "west": {"uv": [204.5, 0], "uv_size": [51.5, 64]}, + "up": {"uv": [256, 64], "uv_size": [-51.5, -64]}, + "down": {"uv": [256, 64], "uv_size": [-51.5, -64]} + } + }, + { + "origin": [-1.525, 47.03187, -16.78445], + "size": [3.05, 1.0125, 0], + "pivot": [0, 47.53813, -16.78445], + "rotation": [0, -90, -91], + "uv": { + "north": {"uv": [256, 0], "uv_size": [-51.5, 64]}, + "east": {"uv": [204.5, 0], "uv_size": [51.5, 64]}, + "south": {"uv": [204.5, 0], "uv_size": [51.5, 64]}, + "west": {"uv": [204.5, 0], "uv_size": [51.5, 64]}, + "up": {"uv": [256, 64], "uv_size": [-51.5, -64]}, + "down": {"uv": [256, 64], "uv_size": [-51.5, -64]} + } + } + ] + }, { "name": "bone15", "parent": "paota", diff --git a/src/main/resources/assets/superbwarfare/textures/entity/speedboat.png b/src/main/resources/assets/superbwarfare/textures/entity/speedboat.png index 6d897a494..0dddda498 100644 Binary files a/src/main/resources/assets/superbwarfare/textures/entity/speedboat.png and b/src/main/resources/assets/superbwarfare/textures/entity/speedboat.png differ diff --git a/src/main/resources/assets/superbwarfare/textures/entity/speedboat_e.png b/src/main/resources/assets/superbwarfare/textures/entity/speedboat_e.png new file mode 100644 index 000000000..07dee8a72 Binary files /dev/null and b/src/main/resources/assets/superbwarfare/textures/entity/speedboat_e.png differ