diff --git a/src/main/java/com/lzxnone/terraria/LzxnoneTerraria.java b/src/main/java/com/lzxnone/terraria/LzxnoneTerraria.java index b1c9cb1..77bd358 100644 --- a/src/main/java/com/lzxnone/terraria/LzxnoneTerraria.java +++ b/src/main/java/com/lzxnone/terraria/LzxnoneTerraria.java @@ -5,6 +5,7 @@ import com.lzxnone.terraria.creative_mode_tab.ModCreativeModeTabs; import com.lzxnone.terraria.effect.ModEffects; import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.summon.BeeSummon; +import com.lzxnone.terraria.entity.summon.StaticSummon; import com.lzxnone.terraria.item.ModItems; import com.lzxnone.terraria.particle.ModParticles; import net.neoforged.neoforge.event.entity.EntityAttributeCreationEvent; diff --git a/src/main/java/com/lzxnone/terraria/LzxnoneTerrariaClient.java b/src/main/java/com/lzxnone/terraria/LzxnoneTerrariaClient.java index 50c274e..7df52c6 100644 --- a/src/main/java/com/lzxnone/terraria/LzxnoneTerrariaClient.java +++ b/src/main/java/com/lzxnone/terraria/LzxnoneTerrariaClient.java @@ -1,7 +1,9 @@ package com.lzxnone.terraria; import com.lzxnone.terraria.entity.ModEntities; -import com.lzxnone.terraria.entity.projectile.TextureProjectileRenderer; +import com.lzxnone.terraria.entity.beam.SwordBeamRenderer; +import com.lzxnone.terraria.entity.projectile.StaticProjectileRenderer; +import com.lzxnone.terraria.entity.summon.StaticSummonRenderer; import com.lzxnone.terraria.particle.*; import net.minecraft.client.renderer.entity.BeeRenderer; import net.neoforged.api.distmarker.Dist; @@ -20,7 +22,13 @@ public class LzxnoneTerrariaClient { //Entity渲染 modEventBus.addListener(EntityRenderersEvent.RegisterRenderers.class, event -> { - event.registerEntityRenderer(ModEntities.TEXTURE_PROJECTILE.get(), TextureProjectileRenderer::new); + event.registerEntityRenderer(ModEntities.STATIC_PROJECTILE.get(), StaticProjectileRenderer::new); + }); + modEventBus.addListener(EntityRenderersEvent.RegisterRenderers.class, event -> { + event.registerEntityRenderer(ModEntities.STATIC_SUMMON.get(), StaticSummonRenderer::new); + }); + modEventBus.addListener(EntityRenderersEvent.RegisterRenderers.class, event -> { + event.registerEntityRenderer(ModEntities.SWORD_BEAM.get(), SwordBeamRenderer::new); }); modEventBus.addListener(EntityRenderersEvent.RegisterRenderers.class, event -> { event.registerEntityRenderer(ModEntities.BEE_SUMMON.get(), BeeRenderer::new); @@ -39,5 +47,8 @@ public class LzxnoneTerrariaClient { modEventBus.addListener(RegisterParticleProvidersEvent.class, event -> { event.registerSpriteSet(ModParticles.SEEDLER_THORN_PARTICLE.get(), SeedlerThornParticle.Provider::new); }); + modEventBus.addListener(RegisterParticleProvidersEvent.class, event -> { + event.registerSpriteSet(ModParticles.INFLUX_WAVER_DROP_PARTICLE.get(), InfluxWaverDropParticle.Provider::new); + }); } } diff --git a/src/main/java/com/lzxnone/terraria/ModSounds.java b/src/main/java/com/lzxnone/terraria/ModSounds.java index 274e896..1222591 100644 --- a/src/main/java/com/lzxnone/terraria/ModSounds.java +++ b/src/main/java/com/lzxnone/terraria/ModSounds.java @@ -23,6 +23,10 @@ public class ModSounds { SOUND_EVENTS.register("wave", () -> SoundEvent.createVariableRangeEvent( ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "wave"))); + public static final Supplier WAVE2 = + SOUND_EVENTS.register("wave2", + () -> SoundEvent.createVariableRangeEvent( + ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "wave2"))); public static final Supplier STAR_FALL = SOUND_EVENTS.register("star_fall", () -> SoundEvent.createVariableRangeEvent( @@ -35,4 +39,12 @@ public class ModSounds { SOUND_EVENTS.register("boom", () -> SoundEvent.createVariableRangeEvent( ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "boom"))); + public static final Supplier CAT = + SOUND_EVENTS.register("cat", + () -> SoundEvent.createVariableRangeEvent( + ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "cat"))); + public static final Supplier CAT2 = + SOUND_EVENTS.register("cat2", + () -> SoundEvent.createVariableRangeEvent( + ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "cat2"))); } diff --git a/src/main/java/com/lzxnone/terraria/entity/EntityEmissiveRenderer.java b/src/main/java/com/lzxnone/terraria/entity/EntityEmissiveRenderer.java new file mode 100644 index 0000000..a87616c --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/entity/EntityEmissiveRenderer.java @@ -0,0 +1,69 @@ +package com.lzxnone.terraria.entity; + +import com.lzxnone.terraria.LzxnoneTerraria; +import com.lzxnone.terraria.entity.beam.SwordBeam; +import com.lzxnone.terraria.entity.beam.SwordBeamBehaviors; +import com.lzxnone.terraria.entity.projectile.StaticProjectile; +import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors; +import com.lzxnone.terraria.entity.summon.StaticSummon; +import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.Camera; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.client.event.RenderLevelStageEvent; + +@EventBusSubscriber(modid = LzxnoneTerraria.MODID, value = Dist.CLIENT) +public class EntityEmissiveRenderer { + @SubscribeEvent + public static void onRenderStage(RenderLevelStageEvent event) { + if(event.getStage() != RenderLevelStageEvent.Stage.AFTER_WEATHER) return; + + Minecraft mc = Minecraft.getInstance(); + if(mc.level == null || mc.player == null) return; + + PoseStack poseStack = event.getPoseStack(); + Camera camera = event.getCamera(); + float partialTick = event.getPartialTick().getGameTimeDeltaPartialTick(true); + MultiBufferSource.BufferSource bufferSource = mc.renderBuffers().bufferSource(); + for(Entity entity : mc.level.entitiesForRendering()) { + double x = Mth.lerp(partialTick, entity.xo, entity.getX()); + double y = Mth.lerp(partialTick, entity.yo, entity.getY()); + double z = Mth.lerp(partialTick, entity.zo, entity.getZ()); + float entityYaw = Mth.lerp(partialTick, entity.yRotO, entity.getYRot()); + + double camX = x - camera.getPosition().x(); + double camY = y - camera.getPosition().y(); + double camZ = z - camera.getPosition().z(); + + if(entity instanceof StaticProjectile projectile && projectile.getEntityData().get(StaticProjectile.RENDER_MODE).equals("custom") && projectile.getEntityData().get(StaticProjectile.GLOW)) { + poseStack.pushPose(); + poseStack.translate(camX, camY, camZ); + StaticProjectileBehaviors.getBehavior(projectile.getEntityData().get(StaticProjectile.BEHAVIOR)) + .render(projectile, entityYaw, partialTick, poseStack, bufferSource, 15728880); + + poseStack.popPose(); + }else if(entity instanceof StaticSummon summon && summon.getEntityData().get(StaticSummon.RENDER_MODE).equals("custom") && summon.getEntityData().get(StaticSummon.GLOW)) { + poseStack.pushPose(); + poseStack.translate(camX, camY, camZ); + StaticSummonBehaviors.getBehavior(summon.getEntityData().get(StaticSummon.BEHAVIOR)) + .render(summon, entityYaw, partialTick, poseStack, bufferSource, 15728880); + + poseStack.popPose(); + }else if(entity instanceof SwordBeam beam) { + poseStack.pushPose(); + poseStack.translate(camX, camY, camZ); + SwordBeamBehaviors.getBehavior(beam.getEntityData().get(SwordBeam.BEHAVIOR)) + .render(beam, entityYaw, partialTick, poseStack, bufferSource, 15728880); + + poseStack.popPose(); + } + } + bufferSource.endBatch(); + } +} diff --git a/src/main/java/com/lzxnone/terraria/entity/ModEntities.java b/src/main/java/com/lzxnone/terraria/entity/ModEntities.java index 613ceed..0a13bb3 100644 --- a/src/main/java/com/lzxnone/terraria/entity/ModEntities.java +++ b/src/main/java/com/lzxnone/terraria/entity/ModEntities.java @@ -1,9 +1,13 @@ package com.lzxnone.terraria.entity; import com.lzxnone.terraria.LzxnoneTerraria; -import com.lzxnone.terraria.entity.projectile.TextureProjectile; +import com.lzxnone.terraria.entity.beam.SwordBeam; +import com.lzxnone.terraria.entity.projectile.StaticProjectile; import com.lzxnone.terraria.entity.summon.BeeSummon; +import com.lzxnone.terraria.entity.summon.StaticSummon; +import com.lzxnone.terraria.entity.summon.StaticSummonRenderer; import net.minecraft.core.registries.Registries; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MobCategory; import net.neoforged.neoforge.registries.DeferredRegister; @@ -14,13 +18,30 @@ public class ModEntities { public static final DeferredRegister> ENTITY_TYPES = DeferredRegister.create(Registries.ENTITY_TYPE, LzxnoneTerraria.MODID); - public static final Supplier> TEXTURE_PROJECTILE = - ENTITY_TYPES.register("texture_projectile", () -> EntityType.Builder.of( - TextureProjectile::new, MobCategory.MISC) + public static final Supplier> STATIC_PROJECTILE = + ENTITY_TYPES.register("static_projectile", () -> EntityType.Builder.of( + StaticProjectile::new, MobCategory.MISC) + .sized(1.0f, 1.0f) + .clientTrackingRange(1024) + .updateInterval(1) + .build("static_projectile") + ); + public static final Supplier> STATIC_SUMMON = + ENTITY_TYPES.register("static_summon", () -> EntityType.Builder.of( + StaticSummon::new, MobCategory.MISC) + .sized(1.0f, 1.0f) + .clientTrackingRange(1024) + .updateInterval(1) + .build("static_summon") + ); + + public static final Supplier> SWORD_BEAM = + ENTITY_TYPES.register("sword_beam", () -> EntityType.Builder.of( + SwordBeam::new, MobCategory.MISC) .sized(0.5f, 0.5f) .clientTrackingRange(1024) .updateInterval(1) - .build("texture_projectile") + .build("sword_beam") ); public static final Supplier> BEE_SUMMON = diff --git a/src/main/java/com/lzxnone/terraria/entity/TintedVertexConsumer.java b/src/main/java/com/lzxnone/terraria/entity/TintedVertexConsumer.java new file mode 100644 index 0000000..f6105df --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/entity/TintedVertexConsumer.java @@ -0,0 +1,52 @@ +package com.lzxnone.terraria.entity; + +import com.mojang.blaze3d.vertex.VertexConsumer; + +public class TintedVertexConsumer implements VertexConsumer { + private VertexConsumer vertexConsumer; + float r, g, b, a; + + public TintedVertexConsumer(VertexConsumer vertexConsumer, float r, float g, float b, float a) { + this.vertexConsumer = vertexConsumer; + this.r = r; + this.g = g; + this.b = b; + this.a = a; + } + + @Override + public VertexConsumer addVertex(float v, float v1, float v2) { + vertexConsumer.addVertex(v, v1, v2); + return this; + } + + @Override + public VertexConsumer setColor(int i, int i1, int i2, int i3) { + vertexConsumer.setColor((int) (i * r), (int) (i1 * g), (int) (i2 * b), (int) (i3 * a)); + return this; + } + + @Override + public VertexConsumer setUv(float v, float v1) { + vertexConsumer.setUv(v, v1); + return this; + } + + @Override + public VertexConsumer setUv1(int i, int i1) { + vertexConsumer.setUv1(i, i1); + return this; + } + + @Override + public VertexConsumer setUv2(int i, int i1) { + vertexConsumer.setUv2(i, i1); + return this; + } + + @Override + public VertexConsumer setNormal(float v, float v1, float v2) { + vertexConsumer.setNormal(v, v1, v2); + return this; + } +} diff --git a/src/main/java/com/lzxnone/terraria/entity/beam/ISwordBeamBehavior.java b/src/main/java/com/lzxnone/terraria/entity/beam/ISwordBeamBehavior.java new file mode 100644 index 0000000..215a50d --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/entity/beam/ISwordBeamBehavior.java @@ -0,0 +1,239 @@ +package com.lzxnone.terraria.entity.beam; + +import com.lzxnone.terraria.entity.ModEntities; +import com.lzxnone.terraria.utils.MathUtil; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Axis; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.Vec3; +import org.joml.Matrix4f; +import org.joml.Quaternionf; +import org.joml.Vector3f; + +public interface ISwordBeamBehavior { + ResourceLocation RES0 = ResourceLocation.parse("lzxnoneterraria:textures/vfx/terra_beam0.png"); + ResourceLocation RES1 = ResourceLocation.parse("lzxnoneterraria:textures/vfx/terra_beam1.png"); + ResourceLocation RES2 = ResourceLocation.parse("lzxnoneterraria:textures/vfx/terra_beam2.png"); + ResourceLocation RES3 = ResourceLocation.parse("lzxnoneterraria:textures/vfx/terra_beam3.png"); + ResourceLocation RES4 = ResourceLocation.parse("lzxnoneterraria:textures/vfx/terra_beam4.png"); + ResourceLocation RES5 = ResourceLocation.parse("lzxnoneterraria:textures/vfx/beam_sparkle.png"); + + float FADE_IN = 0.33f; + float FADE_OUT = 0.67f; + + default void render(Entity entity, float entityYaw, float partialTick, + PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { + if(!(entity instanceof SwordBeam beam)) return; + Entity owner = beam.getOwner(); + if(owner == null) return; + + int age = beam.getEntityData().get(SwordBeam.AGE); + int lifetime = Math.max(1, beam.getEntityData().get(SwordBeam.LIFETIME)); + + float progress = (age + partialTick) / (float) lifetime; + if(progress > 1.0f) progress = 1.0f; + + Vec3 look = owner.getLookAngle().normalize(); + Vector3f[] dirs = MathUtil.computeDir(MathUtil.toVector3f(look)); + + VertexConsumer vertexConsumer0 = bufferSource.getBuffer(RenderType.entityTranslucentEmissive(RES0)); + VertexConsumer vertexConsumer1 = bufferSource.getBuffer(RenderType.entityTranslucentEmissive(RES0)); + VertexConsumer vertexConsumer2 = bufferSource.getBuffer(RenderType.entityTranslucentEmissive(RES0)); + VertexConsumer vertexConsumer3 = bufferSource.getBuffer(RenderType.entityTranslucentEmissive(RES3)); + VertexConsumer vertexConsumer4 = bufferSource.getBuffer(RenderType.entityTranslucentEmissive(RES4)); + VertexConsumer vertexConsumer5 = bufferSource.getBuffer(RenderType.entityTranslucentEmissive(RES5)); + + Vector3f color0 = entity.getEntityData().get(SwordBeam.COLOR0); + Vector3f color1 = entity.getEntityData().get(SwordBeam.COLOR1); + Vector3f color2 = entity.getEntityData().get(SwordBeam.COLOR2); + Vector3f color3 = entity.getEntityData().get(SwordBeam.COLOR3); + float alpha; + + if(progress <= FADE_IN) { + alpha = 1 - (FADE_IN - progress) / FADE_IN; + }else if(progress >= FADE_OUT) { + alpha = 1 - (progress - FADE_OUT) / (1 - FADE_OUT); + }else { + alpha = 1.0f; + } + + float halfWidth = SwordBeam.HALF_WIDTH * SwordBeam.SCALE; + float halfHeight = SwordBeam.HALF_HEIGHT * SwordBeam.SCALE; + + //左边 + poseStack.pushPose(); + this.applyTranslate(poseStack, dirs, progress - 0.1f * (1.0f - progress), SwordBeam.DIST); + this.applyRotate(poseStack, dirs, progress - 0.1f * (1.0f - progress)); + renderQuad(poseStack.last().pose(), vertexConsumer0, + color0.x(), color0.y(), color0.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.01f); + poseStack.popPose(); + + //右边 + poseStack.pushPose(); + this.applyTranslate(poseStack, dirs, progress + 0.1f, SwordBeam.DIST); + this.applyRotate(poseStack, dirs, progress + 0.05f); + renderQuad(poseStack.last().pose(), vertexConsumer2, + color2.x(), color2.y(), color2.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.02f); + poseStack.popPose(); + + //中间 + poseStack.pushPose(); + this.applyTranslate(poseStack, dirs, progress, SwordBeam.DIST); + this.applyRotate(poseStack, dirs, progress); + renderQuad(poseStack.last().pose(), vertexConsumer1, + color1.x(), color1.y(), color1.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0f); + poseStack.popPose(); + + //三线 + poseStack.pushPose(); + this.applyTranslate(poseStack, dirs, progress, SwordBeam.DIST / 1.5f); + this.applyRotate(poseStack, dirs, progress); + poseStack.scale(0.5f, 0.5f, 0.5f); + renderQuad(poseStack.last().pose(), vertexConsumer3, + color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.02f); + poseStack.popPose(); + + poseStack.pushPose(); + this.applyTranslate(poseStack, dirs, progress, SwordBeam.DIST / 1.25f); + this.applyRotate(poseStack, dirs, progress); + poseStack.scale(0.75f, 0.75f, 0.75f); + renderQuad(poseStack.last().pose(), vertexConsumer3, + color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.02f); + poseStack.popPose(); + + poseStack.pushPose(); + this.applyTranslate(poseStack, dirs, progress, SwordBeam.DIST * 1.15f); + this.applyRotate(poseStack, dirs, progress); + poseStack.scale(0.95f, 0.95f, 0.95f); + renderQuad(poseStack.last().pose(), vertexConsumer3, + color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.02f); + poseStack.popPose(); + + //边缘高光 + poseStack.pushPose(); + this.applyTranslate(poseStack, dirs, progress + 0.05f, SwordBeam.DIST * 1.15f); + this.applyRotate(poseStack, dirs, progress + 0.05f); + poseStack.scale(1.0f, 1.0f, 1.0f); + for(int i = 0;i < 20;i++) { + renderQuad(poseStack.last().pose(), vertexConsumer4, + color1.x(), color1.y(), color1.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.03f); + } + poseStack.popPose(); + + //闪烁 + poseStack.pushPose(); + this.applyTranslate(poseStack, dirs, progress + 0.25f, SwordBeam.DIST * 2.25f); + this.applyRotate(poseStack, dirs, progress + 0.25f); + poseStack.mulPose(Axis.ZP.rotationDegrees(45.0F)); + poseStack.scale(1.0f, 1.0f, 1.0f); + for(int i = 0;i < 20;i++) { + renderQuad(poseStack.last().pose(), vertexConsumer5, + color1.x(), color1.y(), color1.z(), alpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.03f); + } + poseStack.popPose(); + } + + default void applyRotate(PoseStack poseStack, Vector3f[] dirs, float progress) { + Vector3f dir = dirs[0]; + Vector3f up = dirs[1]; + + float angle = (float) ((0.5 - progress) * Math.PI); + Quaternionf rotation = new Quaternionf().fromAxisAngleRad(up, angle); + poseStack.mulPose(rotation); + + float xzLen0 = (float) Math.sqrt(dir.x * dir.x + dir.z * dir.z); + float pitch0 = (float) (Math.atan2(-dir.y, xzLen0) * (180.0 / Math.PI)); + float yaw0 = (float) (Math.atan2(-dir.x, dir.z) * (180.0 / Math.PI)); + poseStack.mulPose(Axis.YP.rotationDegrees(-yaw0)); + poseStack.mulPose(Axis.XP.rotationDegrees(pitch0)); + + poseStack.mulPose(Axis.XP.rotationDegrees(-90.0F)); + poseStack.mulPose(Axis.ZP.rotationDegrees(-90.0F)); + } + + default void applyTranslate(PoseStack poseStack, Vector3f[] dirs, float progress, float dist) { + Vector3f dir = dirs[0]; + Vector3f right = dirs[2]; + + float cos = (float) Math.cos(progress * Math.PI); + float sin = (float) Math.sin(progress * Math.PI); + Vector3f current = new Vector3f( + cos * right.x + sin * dir.x, + cos * right.y + sin * dir.y, + cos * right.z + sin * dir.z + ); + poseStack.translate(current.x * dist, current.y * dist, current.z * dist); + } + + default void renderQuad(Matrix4f matrix, VertexConsumer consumer, float r, float g, float b, float a, float halfWidth, float halfHeight, float offsetX, float offsetY, float offsetZ) { + int ir = (int) (r * 255.0F); + int ig = (int) (g * 255.0F); + int ib = (int) (b * 255.0F); + int ia = (int) (a * 255.0F); + + consumer.addVertex(matrix, -halfWidth, -halfHeight + offsetY, offsetZ) + .setColor(ir, ig, ib, ia).setUv(0.0f, 1.0f) + .setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f); + consumer.addVertex(matrix, halfWidth, -halfHeight + offsetY, offsetZ) + .setColor(ir, ig, ib, ia).setUv(1.0f, 1.0f) + .setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f); + consumer.addVertex(matrix, halfWidth, halfHeight + offsetY, offsetZ) + .setColor(ir, ig, ib, ia).setUv(1.0f, 0.0f) + .setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f); + consumer.addVertex(matrix, -halfWidth, halfHeight + offsetY, offsetZ) + .setColor(ir, ig, ib, ia).setUv(0.0f, 0.0f) + .setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f); + } + + default void generate(Entity entity, CompoundTag beamData) { + if(entity == null) return; + SwordBeam beam = new SwordBeam(ModEntities.SWORD_BEAM.get(), entity.level()); + beam.setOwner(entity); + Vec3 pos = new Vec3(entity.getX(), entity.getY() + entity.getBbHeight() / 2, entity.getZ()); + beam.setPos(pos); + if(beamData.contains("behavior")) beam.getEntityData().set(SwordBeam.BEHAVIOR, beamData.getString("behavior")); + if(beamData.contains("color0R") && beamData.contains("color0G") && beamData.contains("color0B")) { + beam.getEntityData().set(SwordBeam.COLOR0, new Vector3f(beamData.getFloat("color0R"), beamData.getFloat("color0G"), beamData.getFloat("color0B"))); + } + if(beamData.contains("color1R") && beamData.contains("color1G") && beamData.contains("color1B")) { + beam.getEntityData().set(SwordBeam.COLOR1, new Vector3f(beamData.getFloat("color1R"), beamData.getFloat("color1G"), beamData.getFloat("color1B"))); + } + if(beamData.contains("color2R") && beamData.contains("color2G") && beamData.contains("color2B")) { + beam.getEntityData().set(SwordBeam.COLOR2, new Vector3f(beamData.getFloat("color2R"), beamData.getFloat("color2G"), beamData.getFloat("color2B"))); + } + if(beamData.contains("color3R") && beamData.contains("color3G") && beamData.contains("color3B")) { + beam.getEntityData().set(SwordBeam.COLOR3, new Vector3f(beamData.getFloat("color3R"), beamData.getFloat("color3G"), beamData.getFloat("color3B"))); + } + if(beamData.contains("age")) beam.getEntityData().set(SwordBeam.AGE, beamData.getInt("age")); + if(beamData.contains("lifetime")) beam.getEntityData().set(SwordBeam.LIFETIME, beamData.getInt("lifetime")); + if(beamData.contains("customData")) beam.getEntityData().set(SwordBeam.CUSTOM_DATA, beamData.getCompound("customData").copy()); + if(beamData.contains("behavior") && beamData.contains("cooldown") && entity instanceof Player player) { + ResourceLocation itemKey = ResourceLocation.fromNamespaceAndPath("lzxnoneterraria", beamData.getString("behavior")); + Item item = BuiltInRegistries.ITEM.get(itemKey); + if(item != Items.AIR) player.getCooldowns().addCooldown(item, beamData.getInt("cooldown")); + } + entity.level().addFreshEntity(beam); + } + + default void onMoving(SwordBeam beam) {} + default void onHitEntity(SwordBeam beam, EntityHitResult result) {} + default void onHitBlock(SwordBeam beam, BlockHitResult result) {} + default void onDied(SwordBeam beam) { + if(!beam.level().isClientSide()) { + beam.discard(); + } + } +} diff --git a/src/main/java/com/lzxnone/terraria/entity/beam/SwordBeam.java b/src/main/java/com/lzxnone/terraria/entity/beam/SwordBeam.java new file mode 100644 index 0000000..d4b58e9 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/entity/beam/SwordBeam.java @@ -0,0 +1,252 @@ +package com.lzxnone.terraria.entity.beam; + +import com.lzxnone.terraria.LzxnoneTerraria; +import com.lzxnone.terraria.utils.FilterUtil; +import com.lzxnone.terraria.utils.MathUtil; +import net.minecraft.nbt.CompoundTag; +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.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.*; +import org.joml.Quaternionf; +import org.joml.Vector3f; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public class SwordBeam extends Entity { + public static final float HALF_WIDTH = 30.0f; + public static final float HALF_HEIGHT = 72.0f; + public static final float HALF_THICKNESS = 0.25f; + public static final float SCALE = 0.05f; + public static final float DIST = HALF_WIDTH * SCALE; + + public static final EntityDataAccessor BEHAVIOR = + SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.STRING); + public static final EntityDataAccessor COLOR0 = + SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.VECTOR3); + public static final EntityDataAccessor COLOR1 = + SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.VECTOR3); + public static final EntityDataAccessor COLOR2 = + SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.VECTOR3); + public static final EntityDataAccessor COLOR3 = + SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.VECTOR3); + public static final EntityDataAccessor AGE = + SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.INT); + public static final EntityDataAccessor LIFETIME = + SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.INT); + + public static final EntityDataAccessor> OWNER = + SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.OPTIONAL_UUID); + public static final EntityDataAccessor CUSTOM_DATA = + SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.COMPOUND_TAG); + + private Entity owner = null; + + public Vec3 prevPosition = null; + public Vec3 currentPosition = null; + public Vector3f[] dirs = null; + + public SwordBeam(EntityType type, Level level) { + super(type, level); + this.setNoGravity(true); + this.noPhysics = true; + } + + public void setOwner(Entity entity) { + if(entity == null) return; + this.entityData.set(OWNER, Optional.of(entity.getUUID())); + this.owner = entity; + } + + public Entity getOwner() { + if(owner == null) { + if(this.entityData.get(OWNER).orElse(null) != null) { + UUID uuid = this.entityData.get(OWNER).orElse(null); + if(!this.level().isClientSide()) { + setOwner(((ServerLevel) this.level()).getEntity(uuid)); + }else { + for(Entity entity : this.level().getEntities(this, this.getBoundingBox().inflate(64.0))) { + if(entity.getUUID().equals(uuid)) { + setOwner(entity); + } + } + } + } + } + return owner; + } + + @Override + public void tick() { + super.tick(); + + if(!this.level().isClientSide()) { + if(this.getEntityData().get(AGE) >= this.getEntityData().get(LIFETIME)) { + SwordBeamBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onDied(this); + return; + } + this.getEntityData().set(AGE, this.getEntityData().get(AGE) + 1); + } + + if(this.getOwner() != null) { + this.setPos(this.getOwner().getX(), this.getOwner().getY() + this.getOwner().getBbHeight() * 0.5, this.getOwner().getZ()); + }else { + SwordBeamBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onDied(this); + return; + } + + SwordBeamBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onMoving(this); + this.checkCollision(); + } + + public void checkCollision() { + if(owner == null) return; + float progress = (float) this.entityData.get(AGE) / (float) this.entityData.get(LIFETIME); + if(progress > 1.0f) progress = 1.0f; + + Vec3 look = owner.getLookAngle().normalize(); + this.dirs = MathUtil.computeDir(MathUtil.toVector3f(look)); + Vector3f dir = dirs[0]; + Vector3f up = dirs[1]; + Vector3f right = dirs[2]; + + float cos = (float) Math.cos(progress * Math.PI); + float sin = (float) Math.sin(progress * Math.PI); + Vector3f current = new Vector3f( + cos * right.x + sin * dir.x, + cos * right.y + sin * dir.y, + cos * right.z + sin * dir.z + ); + + double centerX = this.getX() + current.x() * DIST; + double centerY = this.getY() + current.y() * DIST; + double centerZ = this.getZ() + current.z() * DIST; + + this.currentPosition = new Vec3(centerX, centerY, centerZ); + + float angle = (float) ((0.5 - progress) * Math.PI); + float xzLen = (float) Math.sqrt(current.x() * current.x() + current.z() * current.z()); + float pitch = (float) (Math.atan2(-current.y(), xzLen) * (180.0 / Math.PI)); + float yaw = (float) (Math.atan2(-current.x(), current.z()) * (180.0 / Math.PI)); + + Quaternionf rotation = new Quaternionf() + .fromAxisAngleRad(up, angle) + .rotateY((float) Math.toRadians(-yaw)) + .rotateX((float) Math.toRadians(pitch)) + .rotateX((float) Math.toRadians(-90.0)) + .rotateZ((float) Math.toRadians(-90.0)); + + Vector3f axisX = new Vector3f(1, 0, 0).rotate(rotation); + Vector3f axisY = new Vector3f(0, 1, 0).rotate(rotation); + Vector3f axisZ = new Vector3f(0, 0, 1).rotate(rotation); + + float extX = HALF_WIDTH * SCALE * Math.abs(axisX.x()) + HALF_HEIGHT * SCALE * Math.abs(axisY.x()) + HALF_THICKNESS * SCALE * Math.abs(axisZ.x()); + float extY = HALF_WIDTH * SCALE * Math.abs(axisX.y()) + HALF_HEIGHT * SCALE * Math.abs(axisY.y()) + HALF_THICKNESS * SCALE * Math.abs(axisZ.y()); + float extZ = HALF_WIDTH * SCALE * Math.abs(axisX.z()) + HALF_HEIGHT * SCALE * Math.abs(axisY.z()) + HALF_THICKNESS * SCALE * Math.abs(axisZ.z()); + + AABB hitBox = new AABB( + centerX - extX, centerY - extY, centerZ - extZ, + centerX + extX, centerY + extY, centerZ + extZ + ); + this.setBoundingBox(hitBox); + + List targets = this.level().getEntities(this, hitBox, FilterUtil.createTargetFilter(this, this.getOwner())); + + for(Entity target : targets) SwordBeamBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onHitEntity(this, new EntityHitResult(target, currentPosition)); + + if(this.prevPosition == null) return; + + ClipContext context = new ClipContext( + this.prevPosition, + this.currentPosition, + ClipContext.Block.COLLIDER, + ClipContext.Fluid.NONE, + this + ); + + BlockHitResult blockHit = this.level().clip(context); + + if(blockHit.getType() != HitResult.Type.MISS) { + SwordBeamBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onHitBlock(this, blockHit); + } + + this.prevPosition = this.currentPosition; + } + + @Override + protected void defineSynchedData(SynchedEntityData.Builder builder) { + builder.define(BEHAVIOR, "default"); + builder.define(COLOR0, new Vector3f(1.0f, 1.0f, 1.0f)); + builder.define(COLOR1, new Vector3f(1.0f, 1.0f, 1.0f)); + builder.define(COLOR2, new Vector3f(1.0f, 1.0f, 1.0f)); + builder.define(COLOR3, new Vector3f(1.0f, 1.0f, 1.0f)); + builder.define(AGE, 0); + builder.define(LIFETIME, 10); + builder.define(OWNER, Optional.empty()); + builder.define(CUSTOM_DATA, new CompoundTag()); + } + + @Override + protected void addAdditionalSaveData(CompoundTag tag) { + tag.putString("behavior", this.entityData.get(BEHAVIOR)); + Vector3f c0 = this.entityData.get(COLOR0); + tag.putFloat("color0R", c0.x); + tag.putFloat("color0G", c0.y); + tag.putFloat("color0B", c0.z); + Vector3f c1 = this.entityData.get(COLOR1); + tag.putFloat("color1R", c1.x); + tag.putFloat("color1G", c1.y); + tag.putFloat("color1B", c1.z); + Vector3f c2 = this.entityData.get(COLOR2); + tag.putFloat("color2R", c2.x); + tag.putFloat("color2G", c2.y); + tag.putFloat("color2B", c2.z); + Vector3f c3 = this.entityData.get(COLOR3); + tag.putFloat("color3R", c3.x); + tag.putFloat("color3G", c3.y); + tag.putFloat("color3B", c3.z); + tag.putInt("age", this.entityData.get(AGE)); + tag.putInt("lifetime", this.entityData.get(LIFETIME)); + if(getOwner() != null) tag.putUUID("owner", getOwner().getUUID()); + tag.put("customData", this.entityData.get(CUSTOM_DATA)); + } + + @Override + protected void readAdditionalSaveData(CompoundTag tag) { + if(tag.contains("behavior")) this.entityData.set(BEHAVIOR, tag.getString("behavior")); + if(tag.contains("color0R")) { + this.entityData.set(COLOR0, new Vector3f( + tag.getFloat("color0R"), tag.getFloat("color0G"), tag.getFloat("color0B") + )); + } + if(tag.contains("color1R")) { + this.entityData.set(COLOR1, new Vector3f( + tag.getFloat("color1R"), tag.getFloat("color1G"), tag.getFloat("color1B") + )); + } + if(tag.contains("color2R")) { + this.entityData.set(COLOR2, new Vector3f( + tag.getFloat("color2R"), tag.getFloat("color2G"), tag.getFloat("color2B") + )); + } + if(tag.contains("color3R")) { + this.entityData.set(COLOR3, new Vector3f( + tag.getFloat("color3R"), tag.getFloat("color3G"), tag.getFloat("color3B") + )); + } + if(tag.contains("age")) this.entityData.set(AGE, tag.getInt("age")); + if(tag.contains("lifetime")) this.entityData.set(LIFETIME, tag.getInt("lifetime")); + if(tag.contains("owner")) { + this.entityData.set(OWNER, Optional.of(tag.getUUID("owner"))); + getOwner(); + } + if(tag.contains("customData")) this.entityData.set(CUSTOM_DATA, tag.getCompound("customData")); + } +} diff --git a/src/main/java/com/lzxnone/terraria/entity/beam/SwordBeamBehaviors.java b/src/main/java/com/lzxnone/terraria/entity/beam/SwordBeamBehaviors.java new file mode 100644 index 0000000..1638630 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/entity/beam/SwordBeamBehaviors.java @@ -0,0 +1,25 @@ +package com.lzxnone.terraria.entity.beam; + +import com.lzxnone.terraria.item.weapon.melee.TerraBlade; +import com.lzxnone.terraria.item.weapon.melee.TheHorsemansBlade; + +import java.util.HashMap; +import java.util.Map; + +public class SwordBeamBehaviors { + private static final Map BEHAVIORS = new HashMap<>(); + + public static final String DEFAULT = "default"; + public static final String THE_HORSEMANS_BLADE = "the_horsemans_blade"; + public static final String TERRA_BLADE = "terra_blade"; + + static { + BEHAVIORS.put(DEFAULT, new ISwordBeamBehavior() {}); + BEHAVIORS.put(THE_HORSEMANS_BLADE, TheHorsemansBlade.SWORD_BEAM_BEHAVIOR); + BEHAVIORS.put(TERRA_BLADE, TerraBlade.SWORD_BEAM_BEHAVIOR); + } + + public static ISwordBeamBehavior getBehavior(String id) { + return BEHAVIORS.getOrDefault(id, BEHAVIORS.get(DEFAULT)); + } +} diff --git a/src/main/java/com/lzxnone/terraria/entity/beam/SwordBeamRenderer.java b/src/main/java/com/lzxnone/terraria/entity/beam/SwordBeamRenderer.java new file mode 100644 index 0000000..545f68c --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/entity/beam/SwordBeamRenderer.java @@ -0,0 +1,25 @@ +package com.lzxnone.terraria.entity.beam; + +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; + +public class SwordBeamRenderer extends EntityRenderer { + public SwordBeamRenderer(EntityRendererProvider.Context context) { + super(context); + } + + @Override + public void render(Entity entity, float entityYaw, float partialTick, + PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { + super.render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); + } + + @Override + public ResourceLocation getTextureLocation(Entity entity) { + return ResourceLocation.parse("lzxnoneterraria:textures/item/terra_beam.png"); + } +} diff --git a/src/main/java/com/lzxnone/terraria/entity/projectile/IProjectileBehavior.java b/src/main/java/com/lzxnone/terraria/entity/projectile/IProjectileBehavior.java deleted file mode 100644 index 80ee776..0000000 --- a/src/main/java/com/lzxnone/terraria/entity/projectile/IProjectileBehavior.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.lzxnone.terraria.entity.projectile; - -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.EntityHitResult; - -public interface IProjectileBehavior { - default void onMoving(TextureProjectile projectile) {} - default void onHitEntity(TextureProjectile projectile, EntityHitResult result) {} - default void onHitBlock(TextureProjectile projectile, BlockHitResult result) {} - default void onDied(TextureProjectile projectile) { - if(!projectile.level().isClientSide()) { - projectile.discard(); - } - } -} diff --git a/src/main/java/com/lzxnone/terraria/entity/projectile/IStaticProjectileBehavior.java b/src/main/java/com/lzxnone/terraria/entity/projectile/IStaticProjectileBehavior.java new file mode 100644 index 0000000..d26429b --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/entity/projectile/IStaticProjectileBehavior.java @@ -0,0 +1,154 @@ +package com.lzxnone.terraria.entity.projectile; + +import com.lzxnone.terraria.entity.TintedVertexConsumer; +import com.lzxnone.terraria.utils.MathUtil; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Axis; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.item.ItemDisplayContext; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Blocks; +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.Vec3; +import org.joml.Matrix3f; +import org.joml.Quaternionf; +import org.joml.Vector3f; + +public interface IStaticProjectileBehavior { + default void renderItem(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { + if(!(entity instanceof StaticProjectile proj)) return; + ItemStack stack = proj.getEntityData().get(StaticProjectile.ITEM); + if(stack.isEmpty()) return; + + poseStack.pushPose(); + + //对齐坐标系 + Vec3 velCurrent = entity.getDeltaMovement(); + Vec3 velOld = proj.prevDeltaMovement; + if(velOld == null) velOld = velCurrent; + + Vector3f velForRot; + if(velCurrent.lengthSqr() > 0.0001) { + velForRot = new Vector3f( + (float) Mth.lerp(partialTick, velOld.x, velCurrent.x), + (float) Mth.lerp(partialTick, velOld.y, velCurrent.y), + (float) Mth.lerp(partialTick, velOld.z, velCurrent.z) + ); + }else { + velForRot = new Vector3f(proj.getEntityData().get(StaticProjectile.DIRECTION)); + } + + Vector3f[] dirs = MathUtil.computeDir(velForRot); + + Matrix3f rotMatrix = new Matrix3f().set(dirs[2], dirs[1], dirs[0]); + poseStack.mulPose(new Quaternionf().setFromNormalized(rotMatrix)); + + //旋转 + poseStack.mulPose(Axis.XP.rotationDegrees(proj.getEntityData().get(StaticProjectile.RXP) + proj.getEntityData().get(StaticProjectile.RXPS) * (proj.getEntityData().get(StaticProjectile.AGE) + partialTick))); + poseStack.mulPose(Axis.YP.rotationDegrees(proj.getEntityData().get(StaticProjectile.RYP) + proj.getEntityData().get(StaticProjectile.RYPS) * (proj.getEntityData().get(StaticProjectile.AGE) + partialTick))); + poseStack.mulPose(Axis.ZP.rotationDegrees(proj.getEntityData().get(StaticProjectile.RZP) + proj.getEntityData().get(StaticProjectile.RZPS) * (proj.getEntityData().get(StaticProjectile.AGE) + partialTick))); + + //缩放 + poseStack.scale( + proj.getEntityData().get(StaticProjectile.SCALE_X), + proj.getEntityData().get(StaticProjectile.SCALE_Y), + proj.getEntityData().get(StaticProjectile.SCALE_Z) + ); + + Minecraft.getInstance().getItemRenderer().renderStatic( + stack, + ItemDisplayContext.NONE, + proj.getEntityData().get(StaticProjectile.GLOW) ? LightTexture.FULL_BRIGHT : packedLight, + OverlayTexture.NO_OVERLAY, + poseStack, + renderType -> { + VertexConsumer vertexConsumer = bufferSource.getBuffer(renderType); + return new TintedVertexConsumer(vertexConsumer, + proj.getEntityData().get(StaticProjectile.COLOR_R), + proj.getEntityData().get(StaticProjectile.COLOR_G), + proj.getEntityData().get(StaticProjectile.COLOR_B), + proj.getEntityData().get(StaticProjectile.COLOR_A)); + }, + entity.level(), + 0 + ); + + poseStack.popPose(); + } + + default void renderBlock(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { + if(!(entity instanceof StaticProjectile proj)) return; + BlockState blockState = proj.getEntityData().get(StaticProjectile.BLOCK); + if(blockState == Blocks.AIR.defaultBlockState()) return; + + //对齐坐标系 + Vec3 velCurrent = entity.getDeltaMovement(); + Vec3 velOld = proj.prevDeltaMovement; + if(velOld == null) velOld = velCurrent; + + Vector3f velForRot; + if(velCurrent.lengthSqr() > 0.0001) { + velForRot = new Vector3f( + (float) Mth.lerp(partialTick, velOld.x, velCurrent.x), + (float) Mth.lerp(partialTick, velOld.y, velCurrent.y), + (float) Mth.lerp(partialTick, velOld.z, velCurrent.z) + ); + }else { + velForRot = new Vector3f(proj.getEntityData().get(StaticProjectile.DIRECTION)); + } + + Vector3f[] dirs = MathUtil.computeDir(velForRot); + + Matrix3f rotMatrix = new Matrix3f().set(dirs[2], dirs[1], dirs[0]); + poseStack.mulPose(new Quaternionf().setFromNormalized(rotMatrix)); + + //旋转 + poseStack.mulPose(Axis.XP.rotationDegrees(proj.getEntityData().get(StaticProjectile.RXP) + proj.getEntityData().get(StaticProjectile.RXPS) * (proj.getEntityData().get(StaticProjectile.AGE) + partialTick))); + poseStack.mulPose(Axis.YP.rotationDegrees(proj.getEntityData().get(StaticProjectile.RYP) + proj.getEntityData().get(StaticProjectile.RYPS) * (proj.getEntityData().get(StaticProjectile.AGE) + partialTick))); + poseStack.mulPose(Axis.ZP.rotationDegrees(proj.getEntityData().get(StaticProjectile.RZP) + proj.getEntityData().get(StaticProjectile.RZPS) * (proj.getEntityData().get(StaticProjectile.AGE) + partialTick))); + + //缩放 + poseStack.scale( + proj.getEntityData().get(StaticProjectile.SCALE_X), + proj.getEntityData().get(StaticProjectile.SCALE_Y), + proj.getEntityData().get(StaticProjectile.SCALE_Z) + ); + + Minecraft.getInstance().getBlockRenderer().renderSingleBlock( + blockState, + poseStack, + renderType -> { + VertexConsumer vertexConsumer = bufferSource.getBuffer(renderType); + return new TintedVertexConsumer(vertexConsumer, + proj.getEntityData().get(StaticProjectile.COLOR_R), + proj.getEntityData().get(StaticProjectile.COLOR_G), + proj.getEntityData().get(StaticProjectile.COLOR_B), + proj.getEntityData().get(StaticProjectile.COLOR_A)); + }, + proj.getEntityData().get(StaticProjectile.GLOW) ? LightTexture.FULL_BRIGHT : packedLight, + OverlayTexture.NO_OVERLAY, + net.neoforged.neoforge.client.model.data.ModelData.EMPTY, + null + ); + + poseStack.popPose(); + } + + default void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {} + default void onMoving(StaticProjectile projectile) {} + default void onHitEntity(StaticProjectile projectile, EntityHitResult result) {} + default void onHitBlock(StaticProjectile projectile, BlockHitResult result) {} + default void onDied(StaticProjectile projectile) { + if(!projectile.level().isClientSide()) { + projectile.discard(); + } + } +} diff --git a/src/main/java/com/lzxnone/terraria/entity/projectile/TextureProjectile.java b/src/main/java/com/lzxnone/terraria/entity/projectile/StaticProjectile.java similarity index 56% rename from src/main/java/com/lzxnone/terraria/entity/projectile/TextureProjectile.java rename to src/main/java/com/lzxnone/terraria/entity/projectile/StaticProjectile.java index 24efb0d..0c06287 100644 --- a/src/main/java/com/lzxnone/terraria/entity/projectile/TextureProjectile.java +++ b/src/main/java/com/lzxnone/terraria/entity/projectile/StaticProjectile.java @@ -1,69 +1,85 @@ package com.lzxnone.terraria.entity.projectile; +import com.lzxnone.terraria.entity.summon.StaticSummon; +import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtUtils; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.entity.projectile.ProjectileUtil; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.*; import net.objecthunter.exp4j.Expression; import net.objecthunter.exp4j.ExpressionBuilder; import org.joml.Vector3f; -public class TextureProjectile extends Projectile { +public class StaticProjectile extends Projectile { public static final EntityDataAccessor BEHAVIOR = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.STRING); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.STRING); + public static final EntityDataAccessor RENDER_MODE = + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.STRING); public static final EntityDataAccessor ITEM = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.ITEM_STACK); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.ITEM_STACK); + public static final EntityDataAccessor BLOCK = + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.BLOCK_STATE); public static final EntityDataAccessor ORIGIN = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.VECTOR3); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.VECTOR3); public static final EntityDataAccessor DIRECTION = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.VECTOR3); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.VECTOR3); public static final EntityDataAccessor UP = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.VECTOR3); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.VECTOR3); public static final EntityDataAccessor RIGHT = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.VECTOR3); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.VECTOR3); public static final EntityDataAccessor SCALE_X = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.FLOAT); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor SCALE_Y = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.FLOAT); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor SCALE_Z = + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor RXP = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.INT); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.INT); public static final EntityDataAccessor RYP = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.INT); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.INT); public static final EntityDataAccessor RZP = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.INT); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.INT); public static final EntityDataAccessor RXPS = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.INT); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.INT); public static final EntityDataAccessor RYPS = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.INT); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.INT); public static final EntityDataAccessor RZPS = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.INT); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.INT); + public static final EntityDataAccessor COLOR_R = + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor COLOR_G = + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor COLOR_B = + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor COLOR_A = + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor GLOW = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.BOOLEAN); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.BOOLEAN); public static final EntityDataAccessor AGE = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.INT); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.INT); public static final EntityDataAccessor LIFETIME = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.INT); + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.INT); public static final EntityDataAccessor EXPRESSION_X = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.STRING); //右 + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.STRING); //右 public static final EntityDataAccessor EXPRESSION_Y = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.STRING); //上 + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.STRING); //上 public static final EntityDataAccessor EXPRESSION_Z = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.STRING); //前 + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.STRING); //前 public static final EntityDataAccessor CUSTOM_DATA = - SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.COMPOUND_TAG); - + SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.COMPOUND_TAG); public boolean isInit = false; @@ -76,7 +92,7 @@ public class TextureProjectile extends Projectile { public boolean positionOverridden = false; - public TextureProjectile(EntityType type, Level level) { + public StaticProjectile(EntityType type, Level level) { super(type, level); this.setNoGravity(true); } @@ -84,19 +100,26 @@ public class TextureProjectile extends Projectile { @Override protected void defineSynchedData(SynchedEntityData.Builder builder) { builder.define(BEHAVIOR, "default"); + builder.define(RENDER_MODE, "custom"); builder.define(ITEM, ItemStack.EMPTY); + builder.define(BLOCK, Blocks.AIR.defaultBlockState()); builder.define(ORIGIN, new Vector3f(0, 0, 0)); builder.define(DIRECTION, new Vector3f(0, 0, 1)); builder.define(UP, new Vector3f(0, 1, 0)); builder.define(RIGHT, new Vector3f(1, 0, 0)); builder.define(SCALE_X, 1.0f); builder.define(SCALE_Y, 1.0f); + builder.define(SCALE_Z, 1.0f); builder.define(RXP, 0); builder.define(RYP, 0); builder.define(RZP, 0); builder.define(RXPS, 0); builder.define(RYPS, 0); builder.define(RZPS, 0); + builder.define(COLOR_R, 1.0f); + builder.define(COLOR_G, 1.0f); + builder.define(COLOR_B, 1.0f); + builder.define(COLOR_A, 1.0f); builder.define(GLOW, false); builder.define(AGE, 0); builder.define(LIFETIME, 60); @@ -110,34 +133,34 @@ public class TextureProjectile extends Projectile { public void onSyncedDataUpdated(EntityDataAccessor key) { super.onSyncedDataUpdated(key); if(!isInit) return; - if(key.equals(TextureProjectile.EXPRESSION_Y) && exprY != null) { - this.exprY = new ExpressionBuilder(this.entityData.get(TextureProjectile.EXPRESSION_Y)).variables("t").build(); - }else if (key.equals(TextureProjectile.EXPRESSION_Z) && exprZ != null) { - this.exprZ = new ExpressionBuilder(this.entityData.get(TextureProjectile.EXPRESSION_Z)).variables("t").build(); - }else if (key.equals(TextureProjectile.EXPRESSION_X) && exprX != null) { - this.exprX = new ExpressionBuilder(this.entityData.get(TextureProjectile.EXPRESSION_X)).variables("t").build(); + if(key.equals(StaticProjectile.EXPRESSION_Y) && exprY != null) { + this.exprY = new ExpressionBuilder(this.entityData.get(StaticProjectile.EXPRESSION_Y)).variables("t").build(); + }else if (key.equals(StaticProjectile.EXPRESSION_Z) && exprZ != null) { + this.exprZ = new ExpressionBuilder(this.entityData.get(StaticProjectile.EXPRESSION_Z)).variables("t").build(); + }else if (key.equals(StaticProjectile.EXPRESSION_X) && exprX != null) { + this.exprX = new ExpressionBuilder(this.entityData.get(StaticProjectile.EXPRESSION_X)).variables("t").build(); } } @Override public void tick() { super.tick(); - if(!isInit) { - this.exprX = new ExpressionBuilder(this.entityData.get(EXPRESSION_X)).variables("t").build(); - this.exprY = new ExpressionBuilder(this.entityData.get(EXPRESSION_Y)).variables("t").build(); - this.exprZ = new ExpressionBuilder(this.entityData.get(EXPRESSION_Z)).variables("t").build(); - isInit = true; + if(!this.isInit) { + this.exprX = new ExpressionBuilder(this.getEntityData().get(StaticProjectile.EXPRESSION_X)).variables("t").build(); + this.exprY = new ExpressionBuilder(this.getEntityData().get(StaticProjectile.EXPRESSION_Y)).variables("t").build(); + this.exprZ = new ExpressionBuilder(this.getEntityData().get(StaticProjectile.EXPRESSION_Z)).variables("t").build(); + this.isInit = true; } this.prevPos = this.position(); this.prevDeltaMovement = this.getDeltaMovement(); - double valX = this.exprX.setVariable("t", this.entityData.get(AGE)).evaluate(); - double valY = this.exprY.setVariable("t", this.entityData.get(AGE)).evaluate(); - double valZ = this.exprZ.setVariable("t", this.entityData.get(AGE)).evaluate(); - Vector3f origin = this.entityData.get(ORIGIN); - Vector3f right = this.entityData.get(RIGHT); - Vector3f up = this.entityData.get(UP); - Vector3f dir = this.entityData.get(DIRECTION); + double valX = this.exprX.setVariable("t", this.getEntityData().get(StaticProjectile.AGE)).evaluate(); + double valY = this.exprY.setVariable("t", this.getEntityData().get(StaticProjectile.AGE)).evaluate(); + double valZ = this.exprZ.setVariable("t", this.getEntityData().get(StaticProjectile.AGE)).evaluate(); + Vector3f origin = this.getEntityData().get(StaticProjectile.ORIGIN); + Vector3f right = this.getEntityData().get(StaticProjectile.RIGHT); + Vector3f up = this.getEntityData().get(StaticProjectile.UP); + Vector3f dir = this.getEntityData().get(StaticProjectile.DIRECTION); double newX = origin.x + (valX * right.x) + (valY * up.x) + (valZ * dir.x); double newY = origin.y + (valX * right.y) + (valY * up.y) + (valZ * dir.y); double newZ = origin.z + (valX * right.z) + (valY * up.z) + (valZ * dir.z); @@ -145,19 +168,20 @@ public class TextureProjectile extends Projectile { Vec3 nextPos = new Vec3(newX, newY, newZ); this.setDeltaMovement(nextPos.subtract(this.position())); + if(!this.positionOverridden) { + this.setPos(nextPos); + } + this.positionOverridden = false; + + StaticProjectileBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onMoving(this); + HitResult hitResult = ProjectileUtil.getHitResultOnMoveVector(this, this::canHitEntity); if(hitResult.getType() != HitResult.Type.MISS) { this.onHit(hitResult); } - if(!this.positionOverridden) { - this.setPos(nextPos); - } - this.positionOverridden = false; - ProjectileBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onMoving(this); - if(this.entityData.get(AGE) > this.entityData.get(LIFETIME)) { - ProjectileBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onDied(this); + StaticProjectileBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onDied(this); } this.entityData.set(AGE, this.entityData.get(AGE) + 1); } @@ -165,8 +189,10 @@ public class TextureProjectile extends Projectile { @Override protected void addAdditionalSaveData(CompoundTag tag) { tag.putString("behavior", this.entityData.get(BEHAVIOR)); + tag.putString("renderMode", this.entityData.get(RENDER_MODE)); ItemStack stack = this.entityData.get(ITEM); if(!stack.isEmpty()) tag.put("item", stack.save(this.level().registryAccess())); + tag.put("block", NbtUtils.writeBlockState(this.entityData.get(BLOCK))); tag.putFloat("originX", this.entityData.get(ORIGIN).x); tag.putFloat("originY", this.entityData.get(ORIGIN).y); tag.putFloat("originZ", this.entityData.get(ORIGIN).z); @@ -181,12 +207,17 @@ public class TextureProjectile extends Projectile { tag.putFloat("rightZ", this.entityData.get(RIGHT).z); tag.putFloat("scaleX", this.entityData.get(SCALE_X)); tag.putFloat("scaleY", this.entityData.get(SCALE_Y)); + tag.putFloat("scaleZ", this.entityData.get(SCALE_Z)); tag.putInt("rxp", this.entityData.get(RXP)); tag.putInt("ryp", this.entityData.get(RYP)); tag.putInt("rzp", this.entityData.get(RZP)); tag.putInt("rxps", this.entityData.get(RXPS)); tag.putInt("ryps", this.entityData.get(RYPS)); tag.putInt("rzps", this.entityData.get(RZPS)); + tag.putFloat("colorR", this.entityData.get(COLOR_R)); + tag.putFloat("colorG", this.entityData.get(COLOR_G)); + tag.putFloat("colorB", this.entityData.get(COLOR_B)); + tag.putFloat("colorA", this.entityData.get(COLOR_A)); tag.putBoolean("glow", this.entityData.get(GLOW)); tag.putInt("age", this.entityData.get(AGE)); tag.putInt("lifetime", this.entityData.get(LIFETIME)); @@ -199,10 +230,18 @@ public class TextureProjectile extends Projectile { @Override protected void readAdditionalSaveData(CompoundTag tag) { if(tag.contains("behavior")) this.entityData.set(BEHAVIOR, tag.getString("behavior")); + if(tag.contains("renderMode")) this.entityData.set(RENDER_MODE, tag.getString("renderMode")); if(tag.contains("item")) { ItemStack.parse(this.level().registryAccess(), tag.getCompound("item")) .ifPresent(stack -> this.entityData.set(ITEM, stack)); } + if(tag.contains("block")) { + BlockState blockState = NbtUtils.readBlockState( + this.level().holderLookup(Registries.BLOCK), + tag.getCompound("block") + ); + this.entityData.set(BLOCK, blockState); + } Vector3f origin = new Vector3f(); if(tag.contains("originX")) origin.x = tag.getFloat("originX"); if(tag.contains("originY")) origin.y = tag.getFloat("originY"); @@ -214,23 +253,28 @@ public class TextureProjectile extends Projectile { if(tag.contains("dirZ")) dir.z = tag.getFloat("dirZ"); this.entityData.set(DIRECTION, dir); Vector3f up = this.entityData.get(UP); - tag.putFloat("upX", up.x); - tag.putFloat("upY", up.y); - tag.putFloat("upZ", up.z); + if(tag.contains("upX")) up.x = tag.getFloat("upX"); + if(tag.contains("upY")) up.y = tag.getFloat("upY"); + if(tag.contains("upZ")) up.z = tag.getFloat("upZ"); this.entityData.set(UP, up); Vector3f right = this.entityData.get(RIGHT); - tag.putFloat("rightX", right.x); - tag.putFloat("rightY", right.y); - tag.putFloat("rightZ", right.z); + if(tag.contains("rightX")) right.x = tag.getFloat("rightX"); + if(tag.contains("rightY")) right.y = tag.getFloat("rightY"); + if(tag.contains("rightZ")) right.z = tag.getFloat("rightZ"); this.entityData.set(RIGHT, right); if(tag.contains("scaleX")) this.entityData.set(SCALE_X, tag.getFloat("scaleX")); if(tag.contains("scaleY")) this.entityData.set(SCALE_Y, tag.getFloat("scaleY")); + if(tag.contains("scaleZ")) this.entityData.set(SCALE_Z, tag.getFloat("scaleZ")); if(tag.contains("rxp")) this.entityData.set(RXP, tag.getInt("rxp")); if(tag.contains("ryp")) this.entityData.set(RYP, tag.getInt("ryp")); if(tag.contains("rzp")) this.entityData.set(RZP, tag.getInt("rzp")); if(tag.contains("rxps")) this.entityData.set(RXPS, tag.getInt("rxps")); if(tag.contains("ryps")) this.entityData.set(RYPS, tag.getInt("ryps")); if(tag.contains("rzps")) this.entityData.set(RZPS, tag.getInt("rzps")); + if(tag.contains("colorR")) this.entityData.set(COLOR_R, tag.getFloat("colorR")); + if(tag.contains("colorG")) this.entityData.set(COLOR_G, tag.getFloat("colorG")); + if(tag.contains("colorB")) this.entityData.set(COLOR_B, tag.getFloat("colorB")); + if(tag.contains("colorA")) this.entityData.set(COLOR_A, tag.getFloat("colorA")); if(tag.contains("glow")) this.entityData.set(GLOW, tag.getBoolean("glow")); if(tag.contains("age")) this.entityData.set(AGE, tag.getInt("age")); if(tag.contains("lifetime")) this.entityData.set(LIFETIME, tag.getInt("lifetime")); @@ -246,15 +290,12 @@ public class TextureProjectile extends Projectile { @Override protected void onHitEntity(EntityHitResult result) { super.onHitEntity(result); - Entity target = result.getEntity(); - Entity owner = this.getOwner(); - if(owner != null && target.getUUID().equals(owner.getUUID())) return; - ProjectileBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onHitEntity(this, result); + StaticProjectileBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onHitEntity(this, result); } @Override protected void onHitBlock(BlockHitResult result) { super.onHitBlock(result); - ProjectileBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onHitBlock(this, result); + StaticProjectileBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onHitBlock(this, result); } } diff --git a/src/main/java/com/lzxnone/terraria/entity/projectile/ProjectileBehaviors.java b/src/main/java/com/lzxnone/terraria/entity/projectile/StaticProjectileBehaviors.java similarity index 58% rename from src/main/java/com/lzxnone/terraria/entity/projectile/ProjectileBehaviors.java rename to src/main/java/com/lzxnone/terraria/entity/projectile/StaticProjectileBehaviors.java index e744c85..48f55cb 100644 --- a/src/main/java/com/lzxnone/terraria/entity/projectile/ProjectileBehaviors.java +++ b/src/main/java/com/lzxnone/terraria/entity/projectile/StaticProjectileBehaviors.java @@ -1,49 +1,45 @@ package com.lzxnone.terraria.entity.projectile; -import com.lzxnone.terraria.item.weapon.melee.EnchantedSword; -import com.lzxnone.terraria.item.weapon.melee.Seedler; -import com.lzxnone.terraria.item.weapon.melee.Starfury; +import com.lzxnone.terraria.item.weapon.melee.*; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.EntityHitResult; import java.util.HashMap; import java.util.Map; -public class ProjectileBehaviors { - private static final Map BEHAVIORS = new HashMap<>(); +public class StaticProjectileBehaviors { + private static final Map BEHAVIORS = new HashMap<>(); public static final String DEFAULT = "default"; public static final String ENCHANTED_SWORD_BEAM = "enchanted_sword_beam"; public static final String STARFURY_STAR = "starfury_star"; public static final String SEEDLER_NUT = "seedler_nut"; public static final String SEEDLER_THORN = "seedler_thorn"; + public static final String INFLUX_WAVER_BEAM = "influx_waver"; + public static final String STAR_WRATH_STAR = "star_wrath_star"; static { - BEHAVIORS.put(DEFAULT, new IProjectileBehavior() { + BEHAVIORS.put(DEFAULT, new IStaticProjectileBehavior() { @Override - public void onHitEntity(TextureProjectile projectile, EntityHitResult result) { + public void onHitEntity(StaticProjectile projectile, EntityHitResult result) { if(projectile.level().isClientSide()) return; projectile.discard(); } @Override - public void onHitBlock(TextureProjectile projectile, BlockHitResult result) { + public void onHitBlock(StaticProjectile projectile, BlockHitResult result) { if(projectile.level().isClientSide()) return; if(!projectile.level().getBlockState(result.getBlockPos()).getCollisionShape(projectile.level(), result.getBlockPos()).isEmpty()) { projectile.discard(); } } - @Override - public void onDied(TextureProjectile projectile) { - projectile.discard(); - } }); BEHAVIORS.put(ENCHANTED_SWORD_BEAM, EnchantedSword.PROJECTILE_BEHAVIOR); BEHAVIORS.put(STARFURY_STAR, Starfury.PROJECTILE_BEHAVIOR); - BEHAVIORS.put(SEEDLER_NUT, Seedler.NUT_PROJECTILE_BEHAVIOR); - BEHAVIORS.put(SEEDLER_THORN, Seedler.THORN_PROJECTILE_BEHAVIOR); + BEHAVIORS.put(SEEDLER_THORN, Seedler.PROJECTILE_BEHAVIOR); + BEHAVIORS.put(STAR_WRATH_STAR, StarWrath.PROJECTILE_BEHAVIOR); } - public static IProjectileBehavior getBehavior(String id) { + public static IStaticProjectileBehavior getBehavior(String id) { return BEHAVIORS.getOrDefault(id, BEHAVIORS.get(DEFAULT)); } } \ No newline at end of file diff --git a/src/main/java/com/lzxnone/terraria/entity/projectile/StaticProjectileRenderer.java b/src/main/java/com/lzxnone/terraria/entity/projectile/StaticProjectileRenderer.java new file mode 100644 index 0000000..1988536 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/entity/projectile/StaticProjectileRenderer.java @@ -0,0 +1,38 @@ +package com.lzxnone.terraria.entity.projectile; + +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Blocks; + +public class StaticProjectileRenderer extends EntityRenderer { + + public StaticProjectileRenderer(EntityRendererProvider.Context context) { + super(context); + } + + @Override + public void render(Entity entity, float entityYaw, float partialTick, + PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { + if(!(entity instanceof StaticProjectile proj)) return; + if(!proj.isInit) return; + if(proj.getEntityData().get(StaticProjectile.RENDER_MODE).equals("item") && proj.getEntityData().get(StaticProjectile.ITEM) != ItemStack.EMPTY) { + StaticProjectileBehaviors.getBehavior(proj.getEntityData().get(StaticProjectile.BEHAVIOR)).renderItem(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); + }else if(proj.getEntityData().get(StaticProjectile.RENDER_MODE).equals("block") && proj.getEntityData().get(StaticProjectile.BLOCK) != Blocks.AIR.defaultBlockState()) { + StaticProjectileBehaviors.getBehavior(proj.getEntityData().get(StaticProjectile.BEHAVIOR)).renderBlock(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); + }else if(!proj.getEntityData().get(StaticProjectile.GLOW)) { + StaticProjectileBehaviors.getBehavior(proj.getEntityData().get(StaticProjectile.BEHAVIOR)).render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); + } + super.render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); + } + + @Override + public ResourceLocation getTextureLocation(Entity entity) { + return InventoryMenu.BLOCK_ATLAS; + } +} diff --git a/src/main/java/com/lzxnone/terraria/entity/projectile/TextureProjectileRenderer.java b/src/main/java/com/lzxnone/terraria/entity/projectile/TextureProjectileRenderer.java deleted file mode 100644 index 7db77ef..0000000 --- a/src/main/java/com/lzxnone/terraria/entity/projectile/TextureProjectileRenderer.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.lzxnone.terraria.entity.projectile; - -import com.lzxnone.terraria.utils.MathUtil; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Axis; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.LightTexture; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.renderer.entity.EntityRenderer; -import net.minecraft.client.renderer.entity.EntityRendererProvider; -import net.minecraft.client.renderer.texture.OverlayTexture; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Mth; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.item.ItemDisplayContext; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.phys.Vec3; -import org.joml.Matrix3f; -import org.joml.Quaternionf; -import org.joml.Vector3f; - -public class TextureProjectileRenderer extends EntityRenderer { - - public TextureProjectileRenderer(EntityRendererProvider.Context context) { - super(context); - } - - @Override - public void render(Entity entity, float entityYaw, float partialTick, - PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { - if(!(entity instanceof TextureProjectile proj)) return; - if(!proj.isInit || proj.getEntityData().get(TextureProjectile.AGE) < 2) return; - - ItemStack stack = proj.getEntityData().get(TextureProjectile.ITEM); - if(stack.isEmpty()) return; - - float scaleX = proj.getEntityData().get(TextureProjectile.SCALE_X); - float scaleY = proj.getEntityData().get(TextureProjectile.SCALE_Y); - - poseStack.pushPose(); - - // 缩放 - poseStack.scale(scaleX, scaleY, scaleX); - - // 朝飞行方向旋转 - Vec3 velCurrent = entity.getDeltaMovement(); - Vec3 velOld = proj.prevDeltaMovement; - - Vector3f velForRot; - if(velCurrent.lengthSqr() > 0.0001) { - velForRot = new Vector3f( - (float) Mth.lerp(partialTick, velOld.x, velCurrent.x), - (float) Mth.lerp(partialTick, velOld.y, velCurrent.y), - (float) Mth.lerp(partialTick, velOld.z, velCurrent.z) - ); - } else { - velForRot = new Vector3f(proj.getEntityData().get(TextureProjectile.DIRECTION)); - } - - Vector3f[] dirs = MathUtil.computeProjectileDir(velForRot); - - Matrix3f rotMatrix = new Matrix3f().set(dirs[2], dirs[1], dirs[0]); - poseStack.mulPose(new Quaternionf().setFromNormalized(rotMatrix)); - - poseStack.mulPose(Axis.XP.rotationDegrees(proj.getEntityData().get(TextureProjectile.RXP) + proj.getEntityData().get(TextureProjectile.RXPS) * proj.getEntityData().get(TextureProjectile.AGE))); - poseStack.mulPose(Axis.YP.rotationDegrees(proj.getEntityData().get(TextureProjectile.RYP) + proj.getEntityData().get(TextureProjectile.RYPS) * proj.getEntityData().get(TextureProjectile.AGE))); - poseStack.mulPose(Axis.ZP.rotationDegrees(proj.getEntityData().get(TextureProjectile.RZP) + proj.getEntityData().get(TextureProjectile.RZPS) * proj.getEntityData().get(TextureProjectile.AGE))); - - Minecraft.getInstance().getItemRenderer().renderStatic( - stack, - ItemDisplayContext.NONE, - proj.getEntityData().get(TextureProjectile.GLOW) ? LightTexture.FULL_BRIGHT : packedLight, - OverlayTexture.NO_OVERLAY, - poseStack, - bufferSource, - entity.level(), - 0 - ); - - poseStack.popPose(); - - super.render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); - } - - @Override - public ResourceLocation getTextureLocation(Entity entity) { - return ResourceLocation.parse("lzxnoneterraria:textures/particle/enchanted_sword_beam.png"); - } -} diff --git a/src/main/java/com/lzxnone/terraria/entity/summon/BeeSummon.java b/src/main/java/com/lzxnone/terraria/entity/summon/BeeSummon.java index b84f669..6cba290 100644 --- a/src/main/java/com/lzxnone/terraria/entity/summon/BeeSummon.java +++ b/src/main/java/com/lzxnone/terraria/entity/summon/BeeSummon.java @@ -1,6 +1,8 @@ package com.lzxnone.terraria.entity.summon; +import com.lzxnone.terraria.utils.MathUtil; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; @@ -17,22 +19,25 @@ import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; -import java.util.UUID; - public class BeeSummon extends Bee { - public static final int LIFETIME = 1200; public static final int MAX_ATTACK_COUNT = 2; + + public static final double RANGE = 32.0; + public static final double SPEED = 1; + public static final double FRICTION = 0.25; + public int customAge = 0; public int customAttackCount = 0; - public UUID owner = null; + public LivingEntity owner = null; public BeeSummon(EntityType entityType, Level level) { super(entityType, level); - this.moveControl = new FlyingMoveControl(this, 45, true); - this.lookControl = new LookControl(this); - this.navigation = createNavigation(level); + this.setNoGravity(true); + //this.moveControl = new FlyingMoveControl(this, 45, true); + //this.lookControl = new LookControl(this); + //this.navigation = createNavigation(level); } public static AttributeSupplier.@NotNull Builder createAttributes() { @@ -47,26 +52,26 @@ public class BeeSummon extends Bee { public void tick() { super.tick(); if(!this.level().isClientSide()) { - if(owner == null || this.level().getPlayerByUUID(owner) == null) { + if(owner == null) { discard(); + return; } this.customAge++; if(this.customAge >= LIFETIME) { this.discard(); } - Player player = this.level().getPlayerByUUID(owner); LivingEntity target = null; - if(player != null) { - LivingEntity playerAttackTarget = player.getLastHurtMob(); - if(playerAttackTarget != null && playerAttackTarget.isAlive() && this.distanceToSqr(playerAttackTarget) <= 1024) { + if(owner != null) { + LivingEntity playerAttackTarget = owner.getLastHurtMob(); + if(playerAttackTarget != null && playerAttackTarget.isAlive() && this.distanceToSqr(playerAttackTarget) <= RANGE * RANGE) { target = playerAttackTarget; } if(target == null) { - LivingEntity playerAttacker = player.getLastHurtByMob(); - if(playerAttacker != null && playerAttacker.isAlive() && this.distanceToSqr(playerAttacker) <= 1024) { + LivingEntity playerAttacker = owner.getLastHurtByMob(); + if(playerAttacker != null && playerAttacker.isAlive() && this.distanceToSqr(playerAttacker) <= RANGE * RANGE) { target = playerAttacker; } } @@ -79,40 +84,28 @@ public class BeeSummon extends Bee { target = this.getTarget(); if(target != null && target.isAlive()) { double dist = this.distanceToSqr(target); - if(dist > 256) { - flyTowards(target.getBoundingBox().getCenter(), 1, 0.5); - }else if(dist > 64) { - flyTowards(target.getBoundingBox().getCenter(), 0.75, 0.5); - }else if(dist > 4) { - flyTowards(target.getBoundingBox().getCenter(), 0.5, 0.5); + if(dist > 4) { + Vec3 targetPos = new Vec3(target.getX(), target.getY() + target.getBbHeight() / 2, target.getZ()); + this.setDeltaMovement(targetPos.subtract(this.position()).normalize().scale(SPEED)); }else { + this.setDeltaMovement(this.getDeltaMovement().normalize().scale(FRICTION)); this.doHurtTarget(target); } - }else if(player != null) { - Vec3 hoverPos = player.position().add(0, 1.5, 0); - if(this.distanceToSqr(player) > 64) { - flyTowards(hoverPos, 0.75, 0.5); - }else { - this.setDeltaMovement(this.getDeltaMovement().scale(0.8)); + float[] xyRot = MathUtil.computeXYRot(MathUtil.toVector3f(this.getDeltaMovement())); + this.setXRot(xyRot[0]); + this.setYRot(xyRot[1]); + }else { + if(this.tickCount % 40 == 0) { + Vec3 targetPos = MathUtil.getRandomPosInRadius(this.position(), 16); + this.setDeltaMovement(targetPos.subtract(this.position()).normalize().scale(SPEED / 4)); + float[] xyRot = MathUtil.computeXYRot(MathUtil.toVector3f(this.getDeltaMovement())); + this.setXRot(xyRot[0]); + this.setYRot(xyRot[1]); } } } } - private void flyTowards(Vec3 destination, double acceleration, double friction) { - Vec3 myPos = this.getBoundingBox().getCenter(); - Vec3 dir = destination.subtract(myPos); - - if(dir.lengthSqr() > 0.05) { - dir = dir.normalize().scale(acceleration); - Vec3 newMovement = this.getDeltaMovement().add(dir).scale(friction); - this.setDeltaMovement(newMovement); - - this.getLookControl().setLookAt(destination.x, destination.y, destination.z, 30.0F, 30.0F); - this.setYRot((float)(Math.atan2(newMovement.z, newMovement.x) * (180F / Math.PI)) - 90.0F); - } - } - @Override protected void registerGoals() { super.registerGoals(); @@ -124,9 +117,7 @@ public class BeeSummon extends Bee { @Override public boolean doHurtTarget(Entity target) { if(owner == null) return false; - Player player = this.level().getPlayerByUUID(owner); - if(player == null) return false; - DamageSource damageSource = this.damageSources().mobAttack(player); + DamageSource damageSource = this.damageSources().mobAttack(owner); boolean isHurt = target.hurt(damageSource, (float) this.getAttributeValue(Attributes.ATTACK_DAMAGE)); if(isHurt) { @@ -162,7 +153,7 @@ public class BeeSummon extends Bee { @Override public boolean isPushable() { - return false; + return true; } @Override @@ -170,7 +161,7 @@ public class BeeSummon extends Bee { super.addAdditionalSaveData(tag); tag.putInt("customAttackCount", this.customAttackCount); tag.putInt("customAge", this.customAge); - if(this.owner != null) tag.putUUID("owner", this.owner); + if(this.owner != null) tag.putUUID("owner", this.owner.getUUID()); } @Override @@ -178,7 +169,10 @@ public class BeeSummon extends Bee { super.readAdditionalSaveData(tag); if(tag.contains("customAttackCount")) this.customAttackCount = tag.getInt("customAttackCount"); if(tag.contains("customAge")) this.customAge = tag.getInt("customAge"); - if(tag.contains("owner")) this.owner = tag.getUUID("owner"); + if(tag.contains("owner") && this.level() instanceof ServerLevel level) { + Entity entity = level.getEntity(tag.getUUID("owner")); + if(entity instanceof LivingEntity livingEntity) this.owner = livingEntity; + } } } diff --git a/src/main/java/com/lzxnone/terraria/entity/summon/IStaticSummonBehavior.java b/src/main/java/com/lzxnone/terraria/entity/summon/IStaticSummonBehavior.java new file mode 100644 index 0000000..7698841 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/entity/summon/IStaticSummonBehavior.java @@ -0,0 +1,133 @@ +package com.lzxnone.terraria.entity.summon; + +import com.lzxnone.terraria.entity.TintedVertexConsumer; +import com.lzxnone.terraria.entity.projectile.StaticProjectile; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Axis; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.PathfinderMob; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemDisplayContext; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import java.util.UUID; + +public interface IStaticSummonBehavior { + default void renderItem(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { + if(!(entity instanceof StaticSummon summon)) return; + ItemStack itemStack = summon.getEntityData().get(StaticSummon.ITEM); + if(itemStack == ItemStack.EMPTY) return; + + poseStack.pushPose(); + + //旋转(方向修正) + poseStack.mulPose(Axis.YP.rotationDegrees(-Mth.lerp(partialTick, summon.yRotO, summon.getYRot()))); + poseStack.mulPose(Axis.XP.rotationDegrees(Mth.lerp(partialTick, summon.xRotO, summon.getXRot()))); + + //旋转(自修正) + poseStack.mulPose(Axis.XP.rotationDegrees(summon.getEntityData().get(StaticSummon.RXP) + summon.getEntityData().get(StaticSummon.RXPS) * (summon.getEntityData().get(StaticSummon.AGE) + partialTick))); + poseStack.mulPose(Axis.YP.rotationDegrees(summon.getEntityData().get(StaticSummon.RYP) + summon.getEntityData().get(StaticSummon.RYPS) * (summon.getEntityData().get(StaticSummon.AGE) + partialTick))); + poseStack.mulPose(Axis.ZP.rotationDegrees(summon.getEntityData().get(StaticSummon.RZP) + summon.getEntityData().get(StaticSummon.RZPS) * (summon.getEntityData().get(StaticSummon.AGE) + partialTick))); + + //缩放 + poseStack.scale( + summon.getEntityData().get(StaticSummon.SCALE_X), + summon.getEntityData().get(StaticSummon.SCALE_Y), + summon.getEntityData().get(StaticSummon.SCALE_Z) + ); + + Minecraft.getInstance().getItemRenderer().renderStatic( + itemStack, + ItemDisplayContext.NONE, + summon.getEntityData().get(StaticSummon.GLOW) ? LightTexture.FULL_BRIGHT : packedLight, + OverlayTexture.NO_OVERLAY, + poseStack, + renderType -> { + VertexConsumer vertexConsumer = bufferSource.getBuffer(renderType); + return new TintedVertexConsumer(vertexConsumer, + summon.getEntityData().get(StaticSummon.COLOR_R), + summon.getEntityData().get(StaticSummon.COLOR_G), + summon.getEntityData().get(StaticSummon.COLOR_B), + summon.getEntityData().get(StaticSummon.COLOR_A)); + }, + entity.level(), + 0 + ); + poseStack.popPose(); + } + + default void renderBlock(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { + if(!(entity instanceof StaticSummon summon)) return; + BlockState blockState = summon.getEntityData().get(StaticSummon.BLOCK); + if(blockState == Blocks.AIR.defaultBlockState()) return; + + poseStack.pushPose(); + + //旋转(方向修正) + poseStack.mulPose(Axis.YP.rotationDegrees(-Mth.lerp(partialTick, summon.yRotO, summon.getYRot()))); + poseStack.mulPose(Axis.XP.rotationDegrees(Mth.lerp(partialTick, summon.xRotO, summon.getXRot()))); + + //旋转(自修正) + poseStack.mulPose(Axis.XP.rotationDegrees(summon.getEntityData().get(StaticSummon.RXP) + summon.getEntityData().get(StaticSummon.RXPS) * (summon.getEntityData().get(StaticSummon.AGE) + partialTick))); + poseStack.mulPose(Axis.YP.rotationDegrees(summon.getEntityData().get(StaticSummon.RYP) + summon.getEntityData().get(StaticSummon.RYPS) * (summon.getEntityData().get(StaticSummon.AGE) + partialTick))); + poseStack.mulPose(Axis.ZP.rotationDegrees(summon.getEntityData().get(StaticSummon.RZP) + summon.getEntityData().get(StaticSummon.RZPS) * (summon.getEntityData().get(StaticSummon.AGE) + partialTick))); + + //缩放 + poseStack.scale( + summon.getEntityData().get(StaticSummon.SCALE_X), + summon.getEntityData().get(StaticSummon.SCALE_Y), + summon.getEntityData().get(StaticSummon.SCALE_Z) + ); + + //位移(中心对齐) + poseStack.translate(-0.5D, -0.5D, -0.5D); + + Minecraft.getInstance().getBlockRenderer().renderSingleBlock( + blockState, + poseStack, + renderType -> { + VertexConsumer vertexConsumer = bufferSource.getBuffer(renderType); + return new TintedVertexConsumer(vertexConsumer, + summon.getEntityData().get(StaticSummon.COLOR_R), + summon.getEntityData().get(StaticSummon.COLOR_G), + summon.getEntityData().get(StaticSummon.COLOR_B), + summon.getEntityData().get(StaticSummon.COLOR_A)); + }, + summon.getEntityData().get(StaticSummon.GLOW) ? LightTexture.FULL_BRIGHT : packedLight, + OverlayTexture.NO_OVERLAY, + net.neoforged.neoforge.client.model.data.ModelData.EMPTY, + null + ); + poseStack.popPose(); + } + + default void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {} + + default void checkBeforeTick(StaticSummon summon) { + if(summon.level().isClientSide()) return; + if(summon.getOwner() == null) { + onDied(summon); + return; + } + if(summon.getEntityData().get(StaticSummon.AGE) > summon.getEntityData().get(StaticSummon.LIFETIME)) { + onDied(summon); + }else { + summon.getEntityData().set(StaticSummon.AGE, summon.getEntityData().get(StaticSummon.AGE) + 1); + } + } + + default void tick(StaticSummon summon) { + checkBeforeTick(summon); + } + + default void onDied(StaticSummon summon) { + if(!summon.level().isClientSide()) summon.discard(); + } +} diff --git a/src/main/java/com/lzxnone/terraria/entity/summon/StaticSummon.java b/src/main/java/com/lzxnone/terraria/entity/summon/StaticSummon.java new file mode 100644 index 0000000..b1da385 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/entity/summon/StaticSummon.java @@ -0,0 +1,200 @@ +package com.lzxnone.terraria.entity.summon; + +import net.minecraft.core.registries.Registries; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtUtils; +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.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.MoverType; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec3; + +import java.util.*; + +public class StaticSummon extends Entity { + public static final EntityDataAccessor BEHAVIOR = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.STRING); + public static final EntityDataAccessor RENDER_MODE = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.STRING); + public static final EntityDataAccessor ITEM = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.ITEM_STACK); + public static final EntityDataAccessor BLOCK = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.BLOCK_STATE); + public static final EntityDataAccessor SCALE_X = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor SCALE_Y = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor SCALE_Z = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor RXP = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.INT); + public static final EntityDataAccessor RYP = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.INT); + public static final EntityDataAccessor RZP = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.INT); + public static final EntityDataAccessor RXPS = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.INT); + public static final EntityDataAccessor RYPS = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.INT); + public static final EntityDataAccessor RZPS = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.INT); + public static final EntityDataAccessor COLOR_R = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor COLOR_G = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor COLOR_B = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor COLOR_A = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.FLOAT); + public static final EntityDataAccessor GLOW = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.BOOLEAN); + public static final EntityDataAccessor AGE = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.INT); + public static final EntityDataAccessor LIFETIME = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.INT); + + public static final EntityDataAccessor> OWNER = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.OPTIONAL_UUID); + public static final EntityDataAccessor CUSTOM_DATA = + SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.COMPOUND_TAG); + + public LinkedList trailPositions = new LinkedList<>(); + + private Entity owner = null; + + public StaticSummon(EntityType entityType, Level level) { + super(entityType, level); + } + + public void setOwner(Entity entity) { + if(entity == null) return; + this.entityData.set(OWNER, Optional.of(entity.getUUID())); + this.owner = entity; + } + + public Entity getOwner() { + if(owner == null) { + if(this.entityData.get(OWNER).orElse(null) != null) { + UUID uuid = this.entityData.get(OWNER).orElse(null); + if(!this.level().isClientSide()) { + setOwner(((ServerLevel) this.level()).getEntity(uuid)); + }else { + for(Entity entity : this.level().getEntities(this, this.getBoundingBox().inflate(64.0))) { + if(entity.getUUID().equals(uuid)) { + setOwner(entity); + } + } + } + } + } + return owner; + } + + @Override + protected void defineSynchedData(SynchedEntityData.Builder builder) { + builder.define(BEHAVIOR, "default"); + builder.define(RENDER_MODE, "custom"); + builder.define(ITEM, ItemStack.EMPTY); + builder.define(BLOCK, Blocks.AIR.defaultBlockState()); + builder.define(SCALE_X, 1.0f); + builder.define(SCALE_Y, 1.0f); + builder.define(SCALE_Z, 1.0f); + builder.define(RXP, 0); + builder.define(RYP, 0); + builder.define(RZP, 0); + builder.define(RXPS, 0); + builder.define(RYPS, 0); + builder.define(RZPS, 0); + builder.define(COLOR_R, 1.0f); + builder.define(COLOR_G, 1.0f); + builder.define(COLOR_B, 1.0f); + builder.define(COLOR_A, 1.0f); + builder.define(GLOW, false); + builder.define(AGE, 0); + builder.define(LIFETIME, 100); + builder.define(OWNER, Optional.empty()); + builder.define(CUSTOM_DATA, new CompoundTag()); + } + + @Override + public void tick() { + super.tick(); + this.owner = getOwner(); + StaticSummonBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).tick(this); + this.move(MoverType.SELF, this.getDeltaMovement()); + } + + @Override + public void addAdditionalSaveData(CompoundTag tag) { + tag.putString("behavior", this.entityData.get(BEHAVIOR)); + tag.putString("renderMode", this.entityData.get(RENDER_MODE)); + ItemStack stack = this.entityData.get(ITEM); + if(!stack.isEmpty()) tag.put("item", stack.save(this.level().registryAccess())); + tag.put("block", NbtUtils.writeBlockState(this.entityData.get(BLOCK))); + tag.putFloat("scaleX", this.entityData.get(SCALE_X)); + tag.putFloat("scaleY", this.entityData.get(SCALE_Y)); + tag.putFloat("scaleZ", this.entityData.get(SCALE_Z)); + tag.putInt("rxp", this.entityData.get(RXP)); + tag.putInt("ryp", this.entityData.get(RYP)); + tag.putInt("rzp", this.entityData.get(RZP)); + tag.putInt("rxps", this.entityData.get(RXPS)); + tag.putInt("ryps", this.entityData.get(RYPS)); + tag.putInt("rzps", this.entityData.get(RZPS)); + tag.putFloat("colorR", this.entityData.get(COLOR_R)); + tag.putFloat("colorG", this.entityData.get(COLOR_G)); + tag.putFloat("colorB", this.entityData.get(COLOR_B)); + tag.putFloat("colorA", this.entityData.get(COLOR_A)); + tag.putBoolean("glow", this.entityData.get(GLOW)); + tag.putInt("age", this.entityData.get(AGE)); + tag.putInt("lifetime", this.entityData.get(LIFETIME)); + if(getOwner() != null) tag.putUUID("owner", getOwner().getUUID()); + tag.put("customData", this.entityData.get(CUSTOM_DATA)); + } + + @Override + public void readAdditionalSaveData(CompoundTag tag) { + if(tag.contains("behavior")) this.entityData.set(BEHAVIOR, tag.getString("behavior")); + if(tag.contains("renderMode")) this.entityData.set(RENDER_MODE, tag.getString("renderMode")); + if(tag.contains("item")) { + ItemStack.parse(this.level().registryAccess(), tag.getCompound("item")) + .ifPresent(stack -> this.entityData.set(ITEM, stack)); + } + if(tag.contains("block")) { + BlockState blockState = NbtUtils.readBlockState( + this.level().holderLookup(Registries.BLOCK), + tag.getCompound("block") + ); + this.entityData.set(BLOCK, blockState); + } + if(tag.contains("scaleX")) this.entityData.set(SCALE_X, tag.getFloat("scaleX")); + if(tag.contains("scaleY")) this.entityData.set(SCALE_Y, tag.getFloat("scaleY")); + if(tag.contains("scaleZ")) this.entityData.set(SCALE_Z, tag.getFloat("scaleZ")); + if(tag.contains("rxp")) this.entityData.set(RXP, tag.getInt("rxp")); + if(tag.contains("ryp")) this.entityData.set(RYP, tag.getInt("ryp")); + if(tag.contains("rzp")) this.entityData.set(RZP, tag.getInt("rzp")); + if(tag.contains("rxps")) this.entityData.set(RXPS, tag.getInt("rxps")); + if(tag.contains("ryps")) this.entityData.set(RYPS, tag.getInt("ryps")); + if(tag.contains("rzps")) this.entityData.set(RZPS, tag.getInt("rzps")); + if(tag.contains("colorR")) this.entityData.set(COLOR_R, tag.getFloat("colorR")); + if(tag.contains("colorG")) this.entityData.set(COLOR_G, tag.getFloat("colorG")); + if(tag.contains("colorB")) this.entityData.set(COLOR_B, tag.getFloat("colorB")); + if(tag.contains("colorA")) this.entityData.set(COLOR_A, tag.getFloat("colorA")); + if(tag.contains("glow")) this.entityData.set(GLOW, tag.getBoolean("glow")); + if(tag.contains("age")) this.entityData.set(AGE, tag.getInt("age")); + if(tag.contains("lifetime")) this.entityData.set(LIFETIME, tag.getInt("lifetime")); + if(tag.contains("owner")) { + this.entityData.set(OWNER, Optional.of(tag.getUUID("owner"))); + getOwner(); + } + if(tag.contains("customData")) this.entityData.set(CUSTOM_DATA, tag.getCompound("customData")); + } + +} diff --git a/src/main/java/com/lzxnone/terraria/entity/summon/StaticSummonBehaviors.java b/src/main/java/com/lzxnone/terraria/entity/summon/StaticSummonBehaviors.java new file mode 100644 index 0000000..d17c0d5 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/entity/summon/StaticSummonBehaviors.java @@ -0,0 +1,30 @@ +package com.lzxnone.terraria.entity.summon; + +import com.lzxnone.terraria.item.weapon.melee.*; + +import java.util.HashMap; +import java.util.Map; + +public class StaticSummonBehaviors { + private static final Map BEHAVIORS = new HashMap<>(); + + public static final String DEFAULT = "default"; + public static final String SEEDLER_NUT = "seedler_nut"; + public static final String THE_HORSEMANS_BLADE_JACK = "the_horsemans_blade_jack"; + public static final String INFLUX_WAVER_BEAM = "influx_waver_beam"; + public static final String MEOWMERE_PROJECTILE = "meowmere_projectile"; + public static final String TERRA_BLADE_BEAM = "terra_blade_beam"; + + static { + BEHAVIORS.put(DEFAULT, new IStaticSummonBehavior() {}); + BEHAVIORS.put(SEEDLER_NUT, Seedler.SUMMON_BEHAVIOR); + BEHAVIORS.put(THE_HORSEMANS_BLADE_JACK, TheHorsemansBlade.SUMMON_BEHAVIOR); + BEHAVIORS.put(INFLUX_WAVER_BEAM, InfluxWaver.SUMMON_BEHAVIOR); + BEHAVIORS.put(MEOWMERE_PROJECTILE, Meowmere.SUMMON_BEHAVIOR); + BEHAVIORS.put(TERRA_BLADE_BEAM, TerraBlade.SUMMON_BEHAVIOR); + } + + public static IStaticSummonBehavior getBehavior(String id) { + return BEHAVIORS.getOrDefault(id, BEHAVIORS.get(DEFAULT)); + } +} diff --git a/src/main/java/com/lzxnone/terraria/entity/summon/StaticSummonRenderer.java b/src/main/java/com/lzxnone/terraria/entity/summon/StaticSummonRenderer.java new file mode 100644 index 0000000..ad07262 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/entity/summon/StaticSummonRenderer.java @@ -0,0 +1,37 @@ +package com.lzxnone.terraria.entity.summon; + +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.PathfinderMob; +import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Blocks; + +public class StaticSummonRenderer extends EntityRenderer { + public StaticSummonRenderer(EntityRendererProvider.Context context) { + super(context); + } + + @Override + public void render(Entity entity, float entityYaw, float partialTick, + PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { + if(!(entity instanceof StaticSummon summon)) return; + if(summon.getEntityData().get(StaticSummon.RENDER_MODE).equals("item") && summon.getEntityData().get(StaticSummon.ITEM) != ItemStack.EMPTY) { + StaticSummonBehaviors.getBehavior(summon.getEntityData().get(StaticSummon.BEHAVIOR)).renderItem(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); + }else if(summon.getEntityData().get(StaticSummon.RENDER_MODE).equals("block") && summon.getEntityData().get(StaticSummon.BLOCK) != Blocks.AIR.defaultBlockState()) { + StaticSummonBehaviors.getBehavior(summon.getEntityData().get(StaticSummon.BEHAVIOR)).renderBlock(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); + }else if(!summon.getEntityData().get(StaticSummon.GLOW)) { + StaticSummonBehaviors.getBehavior(summon.getEntityData().get(StaticSummon.BEHAVIOR)).render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); + } + super.render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); + } + + @Override + public ResourceLocation getTextureLocation(Entity entity) { + return InventoryMenu.BLOCK_ATLAS; + } +} diff --git a/src/main/java/com/lzxnone/terraria/item/ItemWaveBehaviors.java b/src/main/java/com/lzxnone/terraria/item/ItemWaveBehaviors.java index 0d5c8f2..c174222 100644 --- a/src/main/java/com/lzxnone/terraria/item/ItemWaveBehaviors.java +++ b/src/main/java/com/lzxnone/terraria/item/ItemWaveBehaviors.java @@ -1,6 +1,8 @@ package com.lzxnone.terraria.item; import com.lzxnone.terraria.item.weapon.melee.BeeKeeper; +import com.lzxnone.terraria.item.weapon.melee.TerraBlade; +import com.lzxnone.terraria.item.weapon.melee.TheHorsemansBlade; import java.util.HashMap; import java.util.Map; @@ -10,11 +12,14 @@ public class ItemWaveBehaviors { public static final String DEFAULT = "default"; public static final String BEE_KEEPER = "bee_keeper"; + public static final String THE_HORSEMANS_BLADE = "the_horsemans_blade"; + public static final String TERRA_BLADE = "terra_blade"; static { - BEHAVIORS.put(DEFAULT, new IItemWaveBehavior() { - }); + BEHAVIORS.put(DEFAULT, new IItemWaveBehavior() {}); BEHAVIORS.put(BEE_KEEPER, BeeKeeper.ITEM_WAVE_BEHAVIOR); + BEHAVIORS.put(THE_HORSEMANS_BLADE, TheHorsemansBlade.ITEM_WAVE_BEHAVIOR); + BEHAVIORS.put(TERRA_BLADE, TerraBlade.ITEM_WAVE_BEHAVIOR); } public static IItemWaveBehavior getBehavior(String id) { diff --git a/src/main/java/com/lzxnone/terraria/item/ModItems.java b/src/main/java/com/lzxnone/terraria/item/ModItems.java index 901607c..8457250 100644 --- a/src/main/java/com/lzxnone/terraria/item/ModItems.java +++ b/src/main/java/com/lzxnone/terraria/item/ModItems.java @@ -1,10 +1,7 @@ package com.lzxnone.terraria.item; import com.lzxnone.terraria.LzxnoneTerraria; -import com.lzxnone.terraria.item.projectile.EnchantedSwordBeam; -import com.lzxnone.terraria.item.projectile.SeedlerNut; -import com.lzxnone.terraria.item.projectile.SeedlerThorn; -import com.lzxnone.terraria.item.projectile.StarfuryStar; +import com.lzxnone.terraria.item.projectile.*; import com.lzxnone.terraria.item.weapon.melee.*; import net.minecraft.world.item.Item; import net.neoforged.neoforge.registries.DeferredItem; @@ -13,28 +10,26 @@ import net.neoforged.neoforge.registries.DeferredRegister; public class ModItems { public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(LzxnoneTerraria.MODID); - public static final DeferredItem COPPER_SHORTSWORD = ITEMS.register("copper_shortsword", CopperShortsword::new); - public static final DeferredItem ENCHANTED_SWORD = ITEMS.register("enchanted_sword", EnchantedSword::new); + public static final DeferredItem COPPER_SHORTSWORD = ITEMS.register("copper_shortsword", CopperShortsword::new); + public static final DeferredItem ENCHANTED_SWORD = ITEMS.register("enchanted_sword", EnchantedSword::new); public static final DeferredItem BEE_KEEPER = ITEMS.register("bee_keeper", BeeKeeper::new); public static final DeferredItem STARFURY = ITEMS.register("starfury", Starfury::new); public static final DeferredItem SEEDLER = ITEMS.register("seedler", Seedler::new); + public static final DeferredItem THE_HORSEMANS_BLADE = ITEMS.register("the_horsemans_blade", TheHorsemansBlade::new); + public static final DeferredItem INFLUX_WAVER = ITEMS.register("influx_waver", InfluxWaver::new); + public static final DeferredItem STAR_WRATH = ITEMS.register("star_wrath", StarWrath::new); + public static final DeferredItem MEOWMERE = ITEMS.register("meowmere", Meowmere::new); + public static final DeferredItem TERRA_BLADE = ITEMS.register("terra_blade", TerraBlade::new); - public static final DeferredItem INFLUX_WAVER = ITEMS.register("influx_waver", - () -> new Item(new Item.Properties())); - public static final DeferredItem MEOWMERE = ITEMS.register("meowmere", - () -> new Item(new Item.Properties())); - public static final DeferredItem STAR_WRATH = ITEMS.register("star_wrath", - () -> new Item(new Item.Properties())); - public static final DeferredItem TERRA_BLADE = ITEMS.register("terra_blade", - () -> new Item(new Item.Properties())); - public static final DeferredItem THE_HORSEMANS_BLADE = ITEMS.register("the_horsemans_blade", - () -> new Item(new Item.Properties())); public static final DeferredItem ZENITH = ITEMS.register("zenith", () -> new Item(new Item.Properties())); //弹射物 - public static final DeferredItem ENCHANTED_SWORD_BEAM = ITEMS.register("enchanted_sword_beam", EnchantedSwordBeam::new); - public static final DeferredItem STARFURY_STAR = ITEMS.register("starfury_star", StarfuryStar::new); - public static final DeferredItem SEEDLER_NUT = ITEMS.register("seedler_nut", SeedlerNut::new); - public static final DeferredItem SEEDLER_THORN = ITEMS.register("seedler_thorn", SeedlerThorn::new); + public static final DeferredItem ENCHANTED_SWORD_BEAM = ITEMS.register("enchanted_sword_beam", EnchantedSwordBeam::new); + public static final DeferredItem STARFURY_STAR = ITEMS.register("starfury_star", StarfuryStar::new); + public static final DeferredItem SEEDLER_NUT = ITEMS.register("seedler_nut", SeedlerNut::new); + public static final DeferredItem SEEDLER_THORN = ITEMS.register("seedler_thorn", SeedlerThorn::new); + public static final DeferredItem INFLUX_WAVER_BEAM = ITEMS.register("influx_waver_beam", InfluxWaverBeam::new); + public static final DeferredItem STAR_WRATH_STAR = ITEMS.register("star_wrath_star", StarWrathStar::new); + public static final DeferredItem MEOWMERE_PROJECTILE = ITEMS.register("meowmere_projectile", MeowmereProjectile::new); } diff --git a/src/main/java/com/lzxnone/terraria/item/projectile/InfluxWaverBeam.java b/src/main/java/com/lzxnone/terraria/item/projectile/InfluxWaverBeam.java new file mode 100644 index 0000000..2a2d3ba --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/item/projectile/InfluxWaverBeam.java @@ -0,0 +1,9 @@ +package com.lzxnone.terraria.item.projectile; + +import net.minecraft.world.item.Item; + +public class InfluxWaverBeam extends Item { + public InfluxWaverBeam() { + super(new Item.Properties()); + } +} diff --git a/src/main/java/com/lzxnone/terraria/item/projectile/MeowmereProjectile.java b/src/main/java/com/lzxnone/terraria/item/projectile/MeowmereProjectile.java new file mode 100644 index 0000000..1bc97fb --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/item/projectile/MeowmereProjectile.java @@ -0,0 +1,9 @@ +package com.lzxnone.terraria.item.projectile; + +import net.minecraft.world.item.Item; + +public class MeowmereProjectile extends Item { + public MeowmereProjectile() { + super(new Item.Properties()); + } +} diff --git a/src/main/java/com/lzxnone/terraria/item/projectile/StarWrathStar.java b/src/main/java/com/lzxnone/terraria/item/projectile/StarWrathStar.java new file mode 100644 index 0000000..03977ab --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/item/projectile/StarWrathStar.java @@ -0,0 +1,9 @@ +package com.lzxnone.terraria.item.projectile; + +import net.minecraft.world.item.Item; + +public class StarWrathStar extends Item { + public StarWrathStar() { + super(new Item.Properties()); + } +} diff --git a/src/main/java/com/lzxnone/terraria/item/weapon/melee/BeeKeeper.java b/src/main/java/com/lzxnone/terraria/item/weapon/melee/BeeKeeper.java index d8b76e5..97e1998 100644 --- a/src/main/java/com/lzxnone/terraria/item/weapon/melee/BeeKeeper.java +++ b/src/main/java/com/lzxnone/terraria/item/weapon/melee/BeeKeeper.java @@ -5,6 +5,8 @@ import com.lzxnone.terraria.effect.ModEffects; import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.summon.BeeSummon; import com.lzxnone.terraria.item.IItemWaveBehavior; +import com.lzxnone.terraria.utils.FilterUtil; +import com.lzxnone.terraria.utils.MathUtil; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.Entity; @@ -18,6 +20,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.SwordItem; import net.minecraft.world.item.Tiers; import net.minecraft.world.item.component.ItemAttributeModifiers; +import net.minecraft.world.phys.Vec3; import net.neoforged.neoforge.event.entity.player.AttackEntityEvent; public class BeeKeeper extends SwordItem { @@ -43,7 +46,7 @@ public class BeeKeeper extends SwordItem { Item item = itemStack.getItem(); if(item instanceof BeeKeeper && !player.getCooldowns().isOnCooldown(item)) { Entity target = event.getTarget(); - if(target instanceof LivingEntity livingTarget) { + if(target instanceof LivingEntity livingTarget && FilterUtil.createLivingTargetFilter(player).test(livingTarget)) { livingTarget.addEffect(new MobEffectInstance( ModEffects.CONFUSED, 40, @@ -54,8 +57,8 @@ public class BeeKeeper extends SwordItem { while(count-- > 0) { BeeSummon bee = ModEntities.BEE_SUMMON.get().create(player.level()); if(bee != null) { - bee.owner = player.getUUID(); - bee.setPos(target.position()); + bee.owner = player; + bee.setPos(new Vec3(target.getX(), target.getY() + target.getBbHeight() / 2, target.getZ())); player.level().addFreshEntity(bee); } } diff --git a/src/main/java/com/lzxnone/terraria/item/weapon/melee/EnchantedSword.java b/src/main/java/com/lzxnone/terraria/item/weapon/melee/EnchantedSword.java index d9450db..932a706 100644 --- a/src/main/java/com/lzxnone/terraria/item/weapon/melee/EnchantedSword.java +++ b/src/main/java/com/lzxnone/terraria/item/weapon/melee/EnchantedSword.java @@ -3,19 +3,23 @@ package com.lzxnone.terraria.item.weapon.melee; import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.ModSounds; import com.lzxnone.terraria.entity.ModEntities; -import com.lzxnone.terraria.entity.projectile.IProjectileBehavior; -import com.lzxnone.terraria.entity.projectile.ProjectileBehaviors; -import com.lzxnone.terraria.entity.projectile.TextureProjectile; +import com.lzxnone.terraria.entity.projectile.IStaticProjectileBehavior; +import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors; +import com.lzxnone.terraria.entity.projectile.StaticProjectile; import com.lzxnone.terraria.item.ModItems; -import com.lzxnone.terraria.particle.DustParticleOptions; import com.lzxnone.terraria.particle.ModParticles; +import com.lzxnone.terraria.utils.FilterUtil; import com.lzxnone.terraria.utils.MathUtil; +import com.lzxnone.terraria.utils.ParticleUtil; +import com.lzxnone.terraria.utils.SoundUtil; import net.minecraft.core.component.DataComponents; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlotGroup; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.AttributeModifier; @@ -49,39 +53,38 @@ public class EnchantedSword extends SwordItem { )); } - - - public static final IProjectileBehavior PROJECTILE_BEHAVIOR = new IProjectileBehavior() { + public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileBehavior() { @Override - public void onMoving(TextureProjectile projectile) { - projectile.level().addParticle( - ModParticles.COLORFUL_PARTICLE, - projectile.getX(), projectile.getY(), projectile.getZ(), - (Math.random() * 2 - 1) * 0.1, (Math.random() * 2 - 1) * 0.1, (Math.random() * 2 - 1) * 0.1 + public void onMoving(StaticProjectile projectile) { + ParticleUtil.addParticle( + projectile.level(), ModParticles.COLORFUL_PARTICLE, + projectile.position(), 0.0, + new Vec3(0, 0, 0), 0.1 ); } @Override - public void onHitEntity(TextureProjectile projectile, EntityHitResult result) { + public void onHitEntity(StaticProjectile projectile, EntityHitResult result) { if(!projectile.level().isClientSide()) { if(result.getEntity() instanceof LivingEntity target) { - if(target.hurt(projectile.damageSources().thrown(projectile, projectile.getOwner()), 5.5f)) { - ((ServerLevel) projectile.level()).sendParticles( - ModParticles.COLORFUL_PARTICLE, - projectile.getX(), projectile.getY(), projectile.getZ(), - 25, - 0.2, 0.2, 0.2, - 0.2 + Entity owner = projectile.getOwner(); + if(owner == null) return; + if(!FilterUtil.createLivingTargetFilter(owner).test(target) || !(owner instanceof Player player)) return; + if(target.hurt(projectile.damageSources().playerAttack(player), 5.5f)) { + ParticleUtil.addParticles( + (ServerLevel) projectile.level(), ModParticles.COLORFUL_PARTICLE, + projectile.position(), new Vec3(0.2, 0.2, 0.2), + 0.2, 25 ); - projectile.discard(); + onDied(projectile); } } } } @Override - public void onHitBlock(TextureProjectile projectile, BlockHitResult result) { + public void onHitBlock(StaticProjectile projectile, BlockHitResult result) { if(projectile.level().isClientSide()) return; if(!projectile.level().getBlockState(result.getBlockPos()).getCollisionShape(projectile.level(), result.getBlockPos()).isEmpty()) { - projectile.discard(); + onDied(projectile); } } }; @@ -93,38 +96,38 @@ public class EnchantedSword extends SwordItem { if(!level.isClientSide()) { Vec3 lookVec = player.getLookAngle(); - Vector3f[] dirs = MathUtil.computeProjectileDir( + Vector3f[] dirs = MathUtil.computeDir( MathUtil.toVector3f(lookVec) ); - TextureProjectile projectile = new TextureProjectile(ModEntities.TEXTURE_PROJECTILE.get(), level); + StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level); projectile.setOwner(player); Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ()); projectile.setPos(pos); - projectile.getEntityData().set(TextureProjectile.BEHAVIOR, ProjectileBehaviors.ENCHANTED_SWORD_BEAM); - projectile.getEntityData().set(TextureProjectile.ORIGIN, MathUtil.toVector3f(pos)); - projectile.getEntityData().set(TextureProjectile.DIRECTION, dirs[0]); - projectile.getEntityData().set(TextureProjectile.UP, dirs[1]); - projectile.getEntityData().set(TextureProjectile.RIGHT, dirs[2]); - projectile.getEntityData().set(TextureProjectile.ITEM, new ItemStack(ModItems.ENCHANTED_SWORD_BEAM.get())); - projectile.getEntityData().set(TextureProjectile.SCALE_X, 0.5f); - projectile.getEntityData().set(TextureProjectile.SCALE_Y, 0.5f); - projectile.getEntityData().set(TextureProjectile.RXP, 90); - projectile.getEntityData().set(TextureProjectile.RZP, 45); - projectile.getEntityData().set(TextureProjectile.RYPS, 10); - projectile.getEntityData().set(TextureProjectile.GLOW, true); - projectile.getEntityData().set(TextureProjectile.EXPRESSION_Z, "t"); + projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.ENCHANTED_SWORD_BEAM); + projectile.getEntityData().set(StaticProjectile.RENDER_MODE, "item"); + projectile.getEntityData().set(StaticProjectile.ORIGIN, MathUtil.toVector3f(pos)); + projectile.getEntityData().set(StaticProjectile.DIRECTION, dirs[0]); + projectile.getEntityData().set(StaticProjectile.UP, dirs[1]); + projectile.getEntityData().set(StaticProjectile.RIGHT, dirs[2]); + projectile.getEntityData().set(StaticProjectile.ITEM, new ItemStack(ModItems.ENCHANTED_SWORD_BEAM.get())); + projectile.getEntityData().set(StaticProjectile.SCALE_X, 0.5f); + projectile.getEntityData().set(StaticProjectile.SCALE_Y, 0.5f); + projectile.getEntityData().set(StaticProjectile.RXP, 90); + projectile.getEntityData().set(StaticProjectile.RZP, 45); + projectile.getEntityData().set(StaticProjectile.RYPS, 10); + projectile.getEntityData().set(StaticProjectile.GLOW, true); + projectile.getEntityData().set(StaticProjectile.EXPRESSION_Z, "t"); projectile.setDeltaMovement(MathUtil.toVec3(dirs[0])); level.addFreshEntity(projectile); - - ((ServerLevel) player.level()).sendParticles( - ModParticles.COLORFUL_PARTICLE, - player.getX(), player.getY() + 0.5, player.getZ(), - 25, - 0.2, 0.2, 0.2, - 0.2 + }else { + ParticleUtil.addParticles( + player.level(), ModParticles.COLORFUL_PARTICLE, + new Vec3(player.getX(), player.getY() + 0.5, player.getZ()), 0.2, + new Vec3(0, 0, 0), 0.2, + 25 ); - player.level().playSound(null, player, ModSounds.BEAM.get(), SoundSource.PLAYERS, 4.0F, 1.0F); + SoundUtil.playClientSound(player, ModSounds.BEAM.get()); } player.getCooldowns().addCooldown(stack.getItem(), 15); @@ -134,27 +137,28 @@ public class EnchantedSword extends SwordItem { @Override public void inventoryTick(ItemStack stack, Level level, net.minecraft.world.entity.Entity entity, int slotId, boolean isSelected) { super.inventoryTick(stack, level, entity, slotId, isSelected); - if(isSelected && entity instanceof Player player) { - boolean currentlyOnCooldown = player.getCooldowns().isOnCooldown(this); - boolean wasOnCooldown = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY) - .copyTag().getBoolean("WasOnCooldown"); - - if(wasOnCooldown && !currentlyOnCooldown) { - if(level.isClientSide()) { - player.playSound(ModSounds.MAX_MANA.get(), 4.0F, 1.0F); - }else { - ((ServerLevel) player.level()).sendParticles( - ModParticles.MAX_MANA_PARTICLE, - player.getX(), player.getY() + 0.5, player.getZ(), - 5, - 0.2, 0.2, 0.2, - 0.2 - ); + if(entity instanceof Player player) { + if(isSelected) { + boolean current = player.getCooldowns().isOnCooldown(this); + boolean prev = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY) + .copyTag().getBoolean("onCooldown"); + if(prev && !current) { + if(level.isClientSide()) { + SoundUtil.playClientSound(player, ModSounds.MAX_MANA.get()); + ParticleUtil.addParticles( + player.level(), ModParticles.MAX_MANA_PARTICLE, + new Vec3(player.getX(), player.getY() + 1.0, player.getZ()), 0.05, + new Vec3(0, 0, 0), 0.05, + 5 + ); + } } + CustomData.update(DataComponents.CUSTOM_DATA, stack, + tag -> tag.putBoolean("onCooldown", current)); + }else { + CustomData.update(DataComponents.CUSTOM_DATA, stack, + tag -> tag.putBoolean("onCooldown", false)); } - - CustomData.update(DataComponents.CUSTOM_DATA, stack, - tag -> tag.putBoolean("WasOnCooldown", currentlyOnCooldown)); } } } diff --git a/src/main/java/com/lzxnone/terraria/item/weapon/melee/InfluxWaver.java b/src/main/java/com/lzxnone/terraria/item/weapon/melee/InfluxWaver.java new file mode 100644 index 0000000..a9c930b --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/item/weapon/melee/InfluxWaver.java @@ -0,0 +1,250 @@ +package com.lzxnone.terraria.item.weapon.melee; + +import com.lzxnone.terraria.LzxnoneTerraria; +import com.lzxnone.terraria.ModSounds; +import com.lzxnone.terraria.entity.ModEntities; +import com.lzxnone.terraria.entity.projectile.IStaticProjectileBehavior; +import com.lzxnone.terraria.entity.projectile.StaticProjectile; +import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors; +import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior; +import com.lzxnone.terraria.entity.summon.StaticSummon; +import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors; +import com.lzxnone.terraria.item.ModItems; +import com.lzxnone.terraria.particle.ModParticles; +import com.lzxnone.terraria.utils.CollisionUtil; +import com.lzxnone.terraria.utils.FilterUtil; +import com.lzxnone.terraria.utils.MathUtil; +import com.lzxnone.terraria.utils.ParticleUtil; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EquipmentSlotGroup; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.ai.targeting.TargetingConditions; +import net.minecraft.world.entity.monster.Monster; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.SwordItem; +import net.minecraft.world.item.Tiers; +import net.minecraft.world.item.component.CustomData; +import net.minecraft.world.item.component.ItemAttributeModifiers; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.phys.*; +import net.objecthunter.exp4j.ExpressionBuilder; +import org.joml.Vector3f; + +import java.util.Comparator; +import java.util.List; +import java.util.Locale; + +public class InfluxWaver extends SwordItem { + public InfluxWaver() { + super(Tiers.DIAMOND, new Item.Properties().attributes(ItemAttributeModifiers.builder() + .add(Attributes.ATTACK_DAMAGE, + new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_damage"), 11, AttributeModifier.Operation.ADD_VALUE), + EquipmentSlotGroup.MAINHAND) + .add(Attributes.ATTACK_SPEED, + new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_speed"), -2.4, AttributeModifier.Operation.ADD_VALUE), + EquipmentSlotGroup.MAINHAND) + .build() + )); + } + + public static final int MAX_SUMMON_COUNT = 2; + public static final double SPEED = 1.0; + public static final float FADE_OUT = 0.1f; + public static final float FRICTION = 0.1f; + public static final float SUMMON_RADIUS = 8.0f; + public static final float SEARCH_RADIUS = 24.0f; + + public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() { + @Override + public void tick(StaticSummon summon) { + this.checkBeforeTick(summon); + + CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA); + if(!customData.contains("idx")) return; + int idx = customData.getInt("idx"); + + boolean checkBlock = true; + boolean checkEntity = true; + + //粒子 + if(summon.level().isClientSide()) { + ParticleUtil.addParticle( + summon.level(), ModParticles.INFLUX_WAVER_DROP_PARTICLE.get(), + summon.position(), 0.0, + new Vec3(0, idx == 0 ? -0.1 : 0, 0), 0.00 + ); + } + + //运动逻辑 + if(customData.contains("dead")) { + if(customData.getBoolean("dead")) { + Vec3 currentMovement = summon.getDeltaMovement(); + double speed = currentMovement.length(); + + if(speed <= FRICTION) { + summon.setDeltaMovement(Vec3.ZERO); + }else { + Vec3 newMovement = currentMovement.scale((speed - FRICTION) / speed); + summon.setDeltaMovement(newMovement); + } + } + float alpha = summon.getEntityData().get(StaticSummon.COLOR_A) - FADE_OUT; + summon.getEntityData().set(StaticSummon.COLOR_A, alpha); + if(alpha < 0.001f) { + this.onDied(summon); + return; + } + checkBlock = false; + checkEntity = false; + }else { + if(idx == 0) { + summon.setDeltaMovement(summon.getLookAngle().normalize().scale(SPEED)); + }else { + checkBlock = false; + if(customData.contains("target")) { + Entity target = summon.level().getEntity(customData.getInt("target")); + if(target == null || !target.isAlive()) { + summon.setDeltaMovement(summon.getLookAngle().normalize().scale(SPEED)); + checkEntity = false; + }else { + Vec3 targetPos = new Vec3(target.getX(), target.getY() + target.getBbHeight() / 2, target.getZ()); + summon.setDeltaMovement(targetPos.subtract(summon.position()).normalize().scale(SPEED)); + } + }else { + summon.setDeltaMovement(summon.getLookAngle().normalize().scale(SPEED)); + checkEntity = false; + } + } + } + + float[] xyRot = MathUtil.computeXYRot(MathUtil.toVector3f(summon.getDeltaMovement())); + summon.setXRot(xyRot[0]); + summon.xRotO = xyRot[0]; + summon.setYRot(xyRot[1]); + summon.yRotO = xyRot[1]; + + //碰撞逻辑 + if(!summon.level().isClientSide()) { + Vec3 motion = summon.getDeltaMovement(); + if(checkBlock) { + BlockHitResult blockHitResult = CollisionUtil.checkBlockHit(summon, summon.position().add(motion)); + if(blockHitResult.getType() != HitResult.Type.MISS) { + customData.putBoolean("dead", true); + summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData); + return; + } + } + if(checkEntity) { + EntityHitResult entityHitResult = CollisionUtil.checkEntityHit(summon, summon.position().add(motion)); + if(entityHitResult != null) { + Entity hitTarget = entityHitResult.getEntity(); + Entity target = customData.contains("target") ? summon.level().getEntity(customData.getInt("target")) : null; + if(target != null && !hitTarget.getUUID().equals(target.getUUID())) return; + if(hitTarget instanceof LivingEntity livingEntity && summon.getOwner() instanceof Player player && FilterUtil.createLivingTargetFilter(player).test(livingEntity)) { + if(livingEntity.hurt(summon.damageSources().playerAttack(player), 12.0f)) { + customData.putBoolean("dead", false); + summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData); + return; + } + } + } + } + } + } + + @Override + public void onDied(StaticSummon summon) { + if(!summon.level().isClientSide()) { + CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA); + if(customData.contains("dead") && !customData.getBoolean("dead") && customData.contains("idx") && customData.getInt("idx") < MAX_SUMMON_COUNT) { + if(summon.getOwner() instanceof Player player) { + Entity target = InfluxWaver.search(player, summon.position()); + if(target != null) { + Vec3 targetPos = new Vec3(target.getX(), target.getY() + target.getBbHeight() / 2, target.getZ()); + Vec3 summonPos = MathUtil.getRandomPosOnRadius(targetPos, SUMMON_RADIUS); + InfluxWaver.summon(player, summonPos, targetPos.subtract(summonPos).normalize(), target, customData.getInt("idx") + 1); + } + } + } + summon.discard(); + } + } + }; + + public static void summon(Player player, Vec3 pos, Vec3 dir, Entity target, int idx) { + if(player == null) return; + StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), player.level()); + summon.setOwner(player); + summon.setPos(pos); + float[] xyRot = MathUtil.computeXYRot(MathUtil.toVector3f(dir)); + summon.setXRot(xyRot[0]); + summon.xRotO = xyRot[0]; + summon.setYRot(xyRot[1]); + summon.yRotO = xyRot[1]; + + summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.INFLUX_WAVER_BEAM); + summon.getEntityData().set(StaticSummon.RENDER_MODE, "item"); + summon.getEntityData().set(StaticSummon.ITEM, new ItemStack(ModItems.INFLUX_WAVER_BEAM.get())); + summon.getEntityData().set(StaticSummon.SCALE_X, 1.25f); + summon.getEntityData().set(StaticSummon.SCALE_Y, 1.25f); + summon.getEntityData().set(StaticSummon.RXP, -90); + summon.getEntityData().set(StaticSummon.RZP, -135); + summon.getEntityData().set(StaticSummon.GLOW, true); + summon.setNoGravity(true); + summon.noPhysics = true; + + CompoundTag customData = new CompoundTag(); + if(target != null) customData.putInt("target", target.getId()); + customData.putInt("idx", idx); + summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData); + + player.level().addFreshEntity(summon); + } + + public static Entity search(Player player, Vec3 pos) { + AABB searchBox = new AABB( + pos.x - SEARCH_RADIUS, pos.y - SEARCH_RADIUS, pos.z - SEARCH_RADIUS, + pos.x + SEARCH_RADIUS, pos.y + SEARCH_RADIUS, pos.z + SEARCH_RADIUS + ); + List entities = player.level().getEntitiesOfClass( + Monster.class, + searchBox, + FilterUtil.createMonsterFilter(player) + ); + Monster target = null; + entities.sort(Comparator.comparingDouble(e -> e.distanceToSqr(pos))); + if(!entities.isEmpty()) target = entities.getFirst(); + return target; + } + + @Override + public InteractionResultHolder use(Level level, Player player, InteractionHand hand) { + ItemStack stack = player.getItemInHand(hand); + + if(!level.isClientSide()) { + summon(player, new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ()), player.getLookAngle(), null, 0); + }else { + ParticleUtil.addParticles( + level, ModParticles.INFLUX_WAVER_DROP_PARTICLE.get(), + player.position(), 1.0, + new Vec3(0, 0, 0), 0, + 25 + ); + } + + player.getCooldowns().addCooldown(stack.getItem(), 8); + return InteractionResultHolder.sidedSuccess(stack, level.isClientSide()); + } +} diff --git a/src/main/java/com/lzxnone/terraria/item/weapon/melee/Meowmere.java b/src/main/java/com/lzxnone/terraria/item/weapon/melee/Meowmere.java new file mode 100644 index 0000000..51c9b29 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/item/weapon/melee/Meowmere.java @@ -0,0 +1,311 @@ +package com.lzxnone.terraria.item.weapon.melee; + +import com.lzxnone.terraria.LzxnoneTerraria; +import com.lzxnone.terraria.ModSounds; +import com.lzxnone.terraria.entity.ModEntities; +import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior; +import com.lzxnone.terraria.entity.summon.StaticSummon; +import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors; +import com.lzxnone.terraria.item.ModItems; +import com.lzxnone.terraria.particle.DustParticleOptions; +import com.lzxnone.terraria.utils.*; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EquipmentSlotGroup; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.*; +import net.minecraft.world.item.component.ItemAttributeModifiers; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.*; +import org.joml.Matrix4f; +import org.joml.Vector3f; + +import java.util.List; + +public class Meowmere extends SwordItem { + public Meowmere() { + super(Tiers.DIAMOND, new Item.Properties().attributes(ItemAttributeModifiers.builder() + .add(Attributes.ATTACK_DAMAGE, + new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_damage"), 19, AttributeModifier.Operation.ADD_VALUE), + EquipmentSlotGroup.MAINHAND) + .add(Attributes.ATTACK_SPEED, + new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_speed"), -2.4, AttributeModifier.Operation.ADD_VALUE), + EquipmentSlotGroup.MAINHAND) + .build() + )); + } + + public static final DustParticleOptions PARTICLE = new DustParticleOptions( + 0.05f, 0.5f, 40, true, new Vector3f[]{ + new Vector3f(1.00f, 0.50f, 0.50f), // 淡红 (柔粉红) + new Vector3f(1.00f, 0.75f, 0.50f), // 淡橙 (奶油橘) + new Vector3f(1.00f, 1.00f, 0.50f), // 淡黄 (米黄色) + new Vector3f(0.50f, 1.00f, 0.50f), // 淡绿 (薄荷绿) + new Vector3f(0.50f, 1.00f, 1.00f), // 淡青 (冰蓝色) + new Vector3f(0.50f, 0.50f, 1.00f), // 淡蓝 (天蓝色) + new Vector3f(0.75f, 0.50f, 1.00f) // 淡紫 (薰衣草) + } + ); + + public static final DustParticleOptions PARTICLE2 = new DustParticleOptions( + 0.2f, 0.5f, 40, true, new Vector3f[]{ + new Vector3f(1.00f, 0.50f, 0.50f), // 淡红 (柔粉红) + new Vector3f(1.00f, 0.75f, 0.50f), // 淡橙 (奶油橘) + new Vector3f(1.00f, 1.00f, 0.50f), // 淡黄 (米黄色) + new Vector3f(0.50f, 1.00f, 0.50f), // 淡绿 (薄荷绿) + new Vector3f(0.50f, 1.00f, 1.00f), // 淡青 (冰蓝色) + new Vector3f(0.50f, 0.50f, 1.00f), // 淡蓝 (天蓝色) + new Vector3f(0.75f, 0.50f, 1.00f) // 淡紫 (薰衣草) + } + ); + + public static final double GRAVITY = 0.025; //重力 + public static final double VZ = 1.5; + + public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() { + public static final ResourceLocation RES = ResourceLocation.parse("lzxnoneterraria:textures/vfx/rainbow.png"); + public static final int MAX_LENGTH = 100; + + @Override + public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { + if(!(entity instanceof StaticSummon summon)) return; + + this.renderItem(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); + + Vec3 currentPos = summon.getPosition(partialTick); + + VertexConsumer vertexConsumer = bufferSource.getBuffer(RenderType.entityTranslucentEmissive(RES)); + Matrix4f matrix = poseStack.last().pose(); + + int quadCount = summon.trailPositions.size() / 2 - 1; + for(int i = 0; i < quadCount;i++) { + Vec3 currentPoint1 = summon.trailPositions.get(i * 2); + Vec3 currentPoint2 = summon.trailPositions.get(i * 2 + 1); + Vec3 nextPoint1 = summon.trailPositions.get(i * 2 + 3); + Vec3 nextPoint2 = summon.trailPositions.get(i * 2 + 2); + + double x1 = currentPoint1.x - currentPos.x; + double y1 = currentPoint1.y - currentPos.y; + double z1 = currentPoint1.z - currentPos.z; + + double x2 = currentPoint2.x - currentPos.x; + double y2 = currentPoint2.y - currentPos.y; + double z2 = currentPoint2.z - currentPos.z; + + double x3 = nextPoint1.x - currentPos.x; + double y3 = nextPoint1.y - currentPos.y; + double z3 = nextPoint1.z - currentPos.z; + + double x4 = nextPoint2.x - currentPos.x; + double y4 = nextPoint2.y - currentPos.y; + double z4 = nextPoint2.z - currentPos.z; + + float alpha1 = 1.0F - (float) i / quadCount; + float alpha2 = 1.0F - (float) (i + 1) / quadCount; + + vertexConsumer.addVertex(matrix, (float)x1, (float)y1, (float)z1) + .setColor(1.0f, 1.0f, 1.0f, alpha1).setUv(0.0f, 0.0f) + .setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0); + vertexConsumer.addVertex(matrix, (float)x2, (float)y2, (float)z2) + .setColor(1.0f, 1.0f, 1.0f, alpha1).setUv(0.0f, 1.0f) + .setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0); + vertexConsumer.addVertex(matrix, (float)x3, (float)y3, (float)z3) + .setColor(1.0f, 1.0f, 1.0f, alpha2).setUv(1.0f, 1.0f) + .setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0); + vertexConsumer.addVertex(matrix, (float)x4, (float)y4, (float)z4) + .setColor(1.0f, 1.0f, 1.0f, alpha2).setUv(1.0f, 0.0f) + .setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0); + } + } + + @Override + public void tick(StaticSummon summon) { + this.checkBeforeTick(summon); + Vec3 motion = summon.getDeltaMovement(); + motion = motion.add(0, -GRAVITY, 0); + Vec3 up = MathUtil.toVec3(MathUtil.computeDir(MathUtil.toVector3f(motion))[1]).normalize(); + + summon.trailPositions.addFirst(summon.position().add(up.scale(0.5))); + summon.trailPositions.addFirst(summon.position().add(up.scale(-0.5))); + while(summon.trailPositions.size() > MAX_LENGTH) summon.trailPositions.removeLast(); + + CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA); + + EntityHitResult entityHitResult = CollisionUtil.checkEntityHit(summon, summon.position().add(motion)); + if(entityHitResult != null) { + Entity target = entityHitResult.getEntity(); + if(summon.getOwner() instanceof Player player && target instanceof LivingEntity livingEntity) { + if(livingEntity.hurt(summon.damageSources().playerAttack(player), 20.0f)) { + if(customData.contains("hitEntity") && customData.getInt("hitEntity") < 4) { + customData.putInt("hitEntity", customData.getInt("hitEntity") + 1); + summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData); + }else { + onDied(summon); + return; + } + } + } + return; + } + + BlockHitResult blockHitResult = CollisionUtil.checkBlockHit(summon, summon.position().add(motion)); + if(blockHitResult.getType() != HitResult.Type.MISS) { + if(customData.contains("hitBlock")) { + int hitBlock = customData.getInt("hitBlock"); + + int soundIndex = summon.getRandom().nextInt(2); + if(soundIndex == 0) SoundUtil.playServerSound(summon.level(), ModSounds.CAT.get(), summon.position()); + else SoundUtil.playServerSound(summon.level(), ModSounds.CAT2.get(), summon.position()); + + if(summon.level().isClientSide()) { + Vec3 dir = summon.getDeltaMovement(); + Vector3f[] dirs = MathUtil.computeDir(MathUtil.toVector3f(dir)); + int count = (hitBlock + 1) * 15; + double deltaAngle = 360.0 / count; + for(int i = 0;i < count;i++) { + double angle = i * deltaAngle; + double cos = Math.cos(Math.toRadians(angle)); + double sin = Math.sin(Math.toRadians(angle)); + Vec3 speed = new Vec3( + dirs[1].x * cos + dirs[2].x * sin, + dirs[1].y * cos + dirs[2].y * sin, + dirs[1].z * cos + dirs[2].z * sin + ); + ParticleUtil.addParticle( + summon.level(), PARTICLE2, + summon.position(), 0.0, + speed.scale(0.05 * (hitBlock + 1)), 0.0 + ); + } + }else { + if(summon.getOwner() instanceof Player player) { + List hitEntities = summon.level().getEntitiesOfClass( + LivingEntity.class, + new AABB( + summon.getX() - 0.25 * (hitBlock + 1), summon.getY() - 0.25 * (hitBlock + 1), summon.getZ() - 0.25 * (hitBlock + 1), + summon.getX() + 0.25 * (hitBlock + 1), summon.getY() + 0.25 * (hitBlock + 1), summon.getZ() + 0.25 * (hitBlock + 1) + ), + FilterUtil.createLivingTargetFilter(summon.getOwner()) + ); + for(LivingEntity livingEntity : hitEntities) livingEntity.hurt(summon.damageSources().playerAttack(player), 20.0f); + } + } + + if(hitBlock < 4) { + customData.putInt("hitBlock", hitBlock + 1); + summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData); + + Direction face = blockHitResult.getDirection(); + + double mx = motion.x; + double my = motion.y; + double mz = motion.z; + + switch(face.getAxis()) { + case X -> mx = -mx; + case Y -> my = -my; + case Z -> mz = -mz; + } + + if(face == Direction.UP && Math.abs(my) < 0.1) { + my = 0; + } + + motion = new Vec3(mx, my, mz); + + Vec3 hitVec = blockHitResult.getLocation(); + summon.setPos( + hitVec.x + face.getStepX() * 0.05, + hitVec.y + face.getStepY() * 0.05, + hitVec.z + face.getStepZ() * 0.05 + ); + }else { + onDied(summon); + return; + } + }else { + onDied(summon); + return; + } + } + summon.setDeltaMovement(motion); + } + + @Override + public void onDied(StaticSummon summon) { + if(!summon.level().isClientSide()) { + for(int i = 0;i < summon.trailPositions.size();i += 2) { + Vec3 pos1 = summon.trailPositions.get(i); + Vec3 pos2 = summon.trailPositions.get(i + 1); + Vec3 mid = new Vec3( + (pos1.x + pos2.x) / 2, + (pos1.y + pos2.y) / 2, + (pos1.z + pos2.z) / 2 + ); + ParticleUtil.addParticles( + (ServerLevel) summon.level(), PARTICLE, + mid, new Vec3(0, 0, 0), 0, 1 + ); + } + summon.discard(); + } + } + }; + + @Override + public InteractionResultHolder use(Level level, Player player, InteractionHand hand) { + ItemStack stack = player.getItemInHand(hand); + + if(!level.isClientSide()) { + StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level); + summon.setOwner(player); + Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ()); + summon.setPos(pos); + summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.MEOWMERE_PROJECTILE); + summon.getEntityData().set(StaticSummon.RENDER_MODE, "custom"); + summon.getEntityData().set(StaticSummon.ITEM, new ItemStack(ModItems.MEOWMERE_PROJECTILE.get())); + summon.getEntityData().set(StaticSummon.RYP, -90); + summon.getEntityData().set(StaticSummon.RZP, -90); + summon.getEntityData().set(StaticSummon.LIFETIME, 200); + summon.getEntityData().set(StaticSummon.GLOW, true); + + CompoundTag customData = new CompoundTag(); + customData.putInt("hitBlock", 0); + customData.putInt("hitEntity", 0); + summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData); + + summon.setNoGravity(true); + summon.noPhysics = true; + + float[] xyRot = MathUtil.computeXYRot(MathUtil.toVector3f(player.getLookAngle())); + summon.setXRot(xyRot[0]); + summon.setYRot(xyRot[1]); + summon.setDeltaMovement(player.getLookAngle().normalize().scale(VZ)); + level.addFreshEntity(summon); + }else { + ParticleUtil.addParticles( + player.level(), PARTICLE, + player.position(), 2.0, + new Vec3(0, 0, 0), 0.1, + 25 + ); + } + + player.getCooldowns().addCooldown(stack.getItem(), 3); + return InteractionResultHolder.sidedSuccess(stack, level.isClientSide()); + } +} diff --git a/src/main/java/com/lzxnone/terraria/item/weapon/melee/Seedler.java b/src/main/java/com/lzxnone/terraria/item/weapon/melee/Seedler.java index 761ce6a..d62332f 100644 --- a/src/main/java/com/lzxnone/terraria/item/weapon/melee/Seedler.java +++ b/src/main/java/com/lzxnone/terraria/item/weapon/melee/Seedler.java @@ -3,16 +3,18 @@ package com.lzxnone.terraria.item.weapon.melee; import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.ModSounds; import com.lzxnone.terraria.entity.ModEntities; -import com.lzxnone.terraria.entity.projectile.IProjectileBehavior; -import com.lzxnone.terraria.entity.projectile.ProjectileBehaviors; -import com.lzxnone.terraria.entity.projectile.TextureProjectile; +import com.lzxnone.terraria.entity.projectile.IStaticProjectileBehavior; +import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors; +import com.lzxnone.terraria.entity.projectile.StaticProjectile; +import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior; +import com.lzxnone.terraria.entity.summon.StaticSummon; +import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors; import com.lzxnone.terraria.item.ModItems; import com.lzxnone.terraria.particle.ModParticles; -import com.lzxnone.terraria.utils.MathUtil; -import net.minecraft.nbt.CompoundTag; +import com.lzxnone.terraria.utils.*; +import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; -import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.Entity; @@ -20,6 +22,7 @@ import net.minecraft.world.entity.EquipmentSlotGroup; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.monster.Monster; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -27,16 +30,11 @@ import net.minecraft.world.item.SwordItem; import net.minecraft.world.item.Tiers; import net.minecraft.world.item.component.ItemAttributeModifiers; import net.minecraft.world.level.Level; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraft.world.phys.EntityHitResult; -import net.minecraft.world.phys.Vec3; -import net.objecthunter.exp4j.ExpressionBuilder; +import net.minecraft.world.phys.*; import org.joml.Vector3f; import java.util.Comparator; import java.util.List; -import java.util.Locale; public class Seedler extends SwordItem { public Seedler() { @@ -51,200 +49,142 @@ public class Seedler extends SwordItem { )); } - public static final double GRAVITY = 0.1; //重力 - public static final double NORMAL_DAMPING = 0.6; - public static final double TANGENT_DAMPING = 0.9; + public static final double GRAVITY = 0.075; //重力 + public static final double BOUNCINESS = 0.5; + public static final double VZ = 0.75; - public static final IProjectileBehavior NUT_PROJECTILE_BEHAVIOR = new IProjectileBehavior() { + public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() { @Override - public void onHitBlock(TextureProjectile projectile, BlockHitResult result) { - if(projectile.level().isClientSide()) return; + public void tick(StaticSummon summon) { + this.checkBeforeTick(summon); + Vec3 motion = summon.getDeltaMovement(); + motion = motion.add(0, -GRAVITY, 0); - int age = projectile.getEntityData().get(TextureProjectile.AGE); - int currentLifetime = projectile.getEntityData().get(TextureProjectile.LIFETIME); - int remainingLifetime = currentLifetime - age; - if(remainingLifetime <= 0) { - this.onDied(projectile); + EntityHitResult entityHitResult = CollisionUtil.checkEntityHit(summon, summon.position().add(motion)); + if(entityHitResult != null) { + Entity target = entityHitResult.getEntity(); + if(summon.getOwner() instanceof Player player && target instanceof LivingEntity livingEntity) livingEntity.hurt(summon.damageSources().playerAttack(player), 7.0f); + onDied(summon); return; } - CompoundTag customData = projectile.getEntityData().get(TextureProjectile.CUSTOM_DATA); - double oldVy = customData.getDouble("vy"); - double vz = customData.getDouble("vz"); - double vy = oldVy - GRAVITY * age; + BlockHitResult blockHitResult = CollisionUtil.checkBlockHit(summon, summon.position().add(motion)); + if(blockHitResult.getType() != HitResult.Type.MISS) { + Direction face = blockHitResult.getDirection(); - Vector3f dir = projectile.getEntityData().get(TextureProjectile.DIRECTION); - Vector3f up = projectile.getEntityData().get(TextureProjectile.UP); + double mx = motion.x; + double my = motion.y; + double mz = motion.z; - Vec3 velocity = new Vec3( - vy * up.x() + vz * dir.x(), - vy * up.y() + vz * dir.y(), - vy * up.z() + vz * dir.z() - ); + switch(face.getAxis()) { + case X -> mx = -mx * BOUNCINESS; + case Y -> my = -my * BOUNCINESS; + case Z -> mz = -mz * BOUNCINESS; + } - Vec3 normal = Vec3.atLowerCornerOf(result.getDirection().getNormal()); - Vec3 reflected = velocity.subtract(normal.scale(2 * velocity.dot(normal))); - double normalMag = reflected.dot(normal); - Vec3 tangentDir = reflected.subtract(normal.scale(normalMag)); - double tangentMag = tangentDir.length(); - Vec3 finalVelocity = normal.scale(normalMag * NORMAL_DAMPING); - if(tangentMag > 0.0001) { - finalVelocity = finalVelocity.add(tangentDir.normalize().scale(tangentMag * TANGENT_DAMPING)); + if(face == Direction.UP && Math.abs(my) < 0.1) { + my = 0; + mx *= BOUNCINESS; + mz *= BOUNCINESS; + } + + motion = new Vec3(mx, my, mz); + + Vec3 hitVec = blockHitResult.getLocation(); + summon.setPos( + hitVec.x + face.getStepX() * 0.05, + hitVec.y + face.getStepY() * 0.05, + hitVec.z + face.getStepZ() * 0.05 + ); } - double newVz = Math.sqrt(finalVelocity.x * finalVelocity.x + finalVelocity.z * finalVelocity.z); - double newVy = finalVelocity.y; - - boolean isBounced = false; - - //竖直弹射时 - if(newVy < 0.1 && newVy > 0.0001) { - newVy = 0; - String newExprY = String.format(Locale.US, "-%.4f*t*t", GRAVITY * 0.5); - projectile.getEntityData().set(TextureProjectile.EXPRESSION_Y, newExprY); - projectile.exprY = new ExpressionBuilder(newExprY).variables("t").build(); - }else if(newVy >= 0.1) { - String newExprY = String.format(Locale.US, "%.3f*t - %.4f*t*t", newVy, GRAVITY * 0.5); - projectile.getEntityData().set(TextureProjectile.EXPRESSION_Y, newExprY); - projectile.exprY = new ExpressionBuilder(newExprY).variables("t").build(); - } - if(Math.abs(normal.y) >= 0.999 && newVy >= 0.1) isBounced = true; - - - //水平弹射时 - if(newVz < 0.1 && newVz > 0.0001) { - newVz = 0; - projectile.getEntityData().set(TextureProjectile.EXPRESSION_Z, "0"); - projectile.exprZ = new ExpressionBuilder("0").variables("t").build(); - Vec3 reflectedH = new Vec3(reflected.x, 0, reflected.z).normalize(); - Vector3f[] newDirs = MathUtil.computeProjectileDir(MathUtil.toVector3f(reflectedH)); - projectile.getEntityData().set(TextureProjectile.DIRECTION, newDirs[0]); - projectile.getEntityData().set(TextureProjectile.RIGHT, newDirs[2]); - }else if(newVz >= 0.1) { - String newExprZ = String.format(Locale.US, "%.3f*t", newVz); - projectile.getEntityData().set(TextureProjectile.EXPRESSION_Z, newExprZ); - projectile.exprZ = new ExpressionBuilder(newExprZ).variables("t").build(); - Vec3 reflectedH = new Vec3(reflected.x, 0, reflected.z).normalize(); - Vector3f[] newDirs = MathUtil.computeProjectileDir(MathUtil.toVector3f(reflectedH)); - projectile.getEntityData().set(TextureProjectile.DIRECTION, newDirs[0]); - projectile.getEntityData().set(TextureProjectile.RIGHT, newDirs[2]); - } - if((Math.abs(normal.x) >= 0.999 || Math.abs(normal.z) >= 0.999) && newVz >= 0.1) isBounced = true; - - Vec3 hitPos = result.getLocation(); - Vec3 offsetPos = hitPos.add(normal.scale(isBounced ? 0.1 : 0)); - - projectile.getEntityData().set(TextureProjectile.ORIGIN, MathUtil.toVector3f(offsetPos)); - projectile.getEntityData().set(TextureProjectile.AGE, 0); - projectile.getEntityData().set(TextureProjectile.LIFETIME, remainingLifetime); - - customData.putDouble("vz", newVz); - customData.putDouble("vy", newVy); - projectile.getEntityData().set(TextureProjectile.CUSTOM_DATA, customData); - - projectile.setPos(offsetPos); - projectile.positionOverridden = true; + summon.setDeltaMovement(motion); } @Override - public void onDied(TextureProjectile projectile) { - if(!projectile.level().isClientSide()) { - Vec3 pos = projectile.position(); - Level level = projectile.level(); - - ((ServerLevel) level).sendParticles( - ModParticles.EXPLODE_PARTICLE.get(), - pos.x, pos.y, pos.z, 1, 0.2, 0.2, 0.2, 0.2 - ); - ((ServerLevel) level).sendParticles( - ModParticles.EXPLODE_FLAME_PARTICLE, - pos.x, pos.y, pos.z, 10, 0.2, 0.2, 0.2, 0.2 - ); - ((ServerLevel) level).sendParticles( - ModParticles.SMOKE_PARTICLE, - pos.x, pos.y, pos.z, 10, 0.2, 0.2, 0.2, 0.2 + public void onDied(StaticSummon summon) { + if(!summon.level().isClientSide()) { + List targets = summon.level().getEntitiesOfClass( + Monster.class, + AABB.ofSize(summon.position(), 64, 64, 64), + FilterUtil.createMonsterFilter(summon.getOwner()) ); + targets.sort(Comparator.comparingDouble(e -> e.distanceToSqr(summon.position()))); - level.playSound(null, pos.x, pos.y, pos.z, - ModSounds.BOOM.get(), SoundSource.PLAYERS, 4.0F, 1.0F); - - Entity owner = projectile.getOwner(); - List targets = level.getEntitiesOfClass( - LivingEntity.class, - AABB.ofSize(pos, 64, 64, 64), - e -> e.isAlive() && e != owner && !e.isSpectator() - ); - targets.sort(Comparator.comparingDouble(e -> e.distanceToSqr(pos))); - - int count = projectile.getRandom().nextInt(4) + 4; + int count = summon.getRandom().nextInt(4) + 4; for(int i = 0; i < count; i++) { - Vec3 dir; - if(i < targets.size()) { - Vec3 tPos = targets.get(i).getEyePosition(); - dir = new Vec3(tPos.x - pos.x, tPos.y - pos.y, tPos.z - pos.z).normalize(); - }else { - float yaw = projectile.getRandom().nextFloat() * (float)Math.PI * 2; - float pitch = (projectile.getRandom().nextFloat() - 0.5f) * 0.5f; - dir = new Vec3(-Math.sin(yaw) * Math.cos(pitch), Math.sin(pitch), - Math.cos(yaw) * Math.cos(pitch)); - } + Vec3 tPos = i < targets.size() ? new Vec3(targets.get(i).getX(), targets.get(i).getEyeY(), targets.get(i).getZ()) : MathUtil.getRandomPosInRadius(summon.position(), 4); + Vec3 dir = new Vec3(tPos.x - summon.getX(), tPos.y - summon.getY(), tPos.z - summon.getZ()).normalize(); - Vector3f[] dirs = MathUtil.computeProjectileDir(MathUtil.toVector3f(dir)); + Vector3f[] dirs = MathUtil.computeDir(MathUtil.toVector3f(dir)); - TextureProjectile proj = new TextureProjectile(ModEntities.TEXTURE_PROJECTILE.get(), level); - proj.setOwner(owner); - proj.setPos(pos); - proj.getEntityData().set(TextureProjectile.BEHAVIOR, ProjectileBehaviors.SEEDLER_THORN); - proj.getEntityData().set(TextureProjectile.ORIGIN, MathUtil.toVector3f(pos)); - proj.getEntityData().set(TextureProjectile.DIRECTION, dirs[0]); - proj.getEntityData().set(TextureProjectile.UP, dirs[1]); - proj.getEntityData().set(TextureProjectile.RIGHT, dirs[2]); - proj.getEntityData().set(TextureProjectile.ITEM, new ItemStack(ModItems.SEEDLER_THORN.get())); - proj.getEntityData().set(TextureProjectile.SCALE_X, 0.5f); - proj.getEntityData().set(TextureProjectile.SCALE_Y, 0.5f); - proj.getEntityData().set(TextureProjectile.RXP, 90); - proj.getEntityData().set(TextureProjectile.LIFETIME, 30); - proj.getEntityData().set(TextureProjectile.EXPRESSION_Z, "t*2"); + StaticProjectile proj = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), summon.level()); + proj.setOwner(summon.getOwner()); + proj.setPos(summon.position()); + proj.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.SEEDLER_THORN); + proj.getEntityData().set(StaticProjectile.RENDER_MODE, "item"); + proj.getEntityData().set(StaticProjectile.ORIGIN, MathUtil.toVector3f(summon.position())); + proj.getEntityData().set(StaticProjectile.DIRECTION, dirs[0]); + proj.getEntityData().set(StaticProjectile.UP, dirs[1]); + proj.getEntityData().set(StaticProjectile.RIGHT, dirs[2]); + proj.getEntityData().set(StaticProjectile.ITEM, new ItemStack(ModItems.SEEDLER_THORN.get())); + proj.getEntityData().set(StaticProjectile.SCALE_X, 0.5f); + proj.getEntityData().set(StaticProjectile.SCALE_Y, 0.5f); + proj.getEntityData().set(StaticProjectile.RXP, 90); + proj.getEntityData().set(StaticProjectile.LIFETIME, 30); + proj.getEntityData().set(StaticProjectile.EXPRESSION_Z, "t*2"); proj.setDeltaMovement(MathUtil.toVec3(dirs[0])); - level.addFreshEntity(proj); + summon.level().addFreshEntity(proj); } - projectile.discard(); - } - } - @Override - public void onHitEntity(TextureProjectile projectile, EntityHitResult result) { - if(!projectile.level().isClientSide()) { - if(result.getEntity() instanceof LivingEntity target) { - this.onDied(projectile); - } + ParticleUtil.addParticles( + (ServerLevel) summon.level(), ModParticles.EXPLODE_PARTICLE.get(), + summon.position(), new Vec3(0.2, 0.2, 0.2), + 0.05, 1 + ); + ParticleUtil.addParticles( + (ServerLevel) summon.level(), ModParticles.EXPLODE_FLAME_PARTICLE, + summon.position(), new Vec3(0.2, 0.2, 0.2), + 0.2, 25 + ); + ParticleUtil.addParticles( + (ServerLevel) summon.level(), ModParticles.SMOKE_PARTICLE, + summon.position(), new Vec3(0.2, 0.2, 0.2), + 0.2, 25 + ); + SoundUtil.playServerSound(summon.level(), ModSounds.BOOM.get(), summon.position()); + + summon.discard(); } } }; - public static final IProjectileBehavior THORN_PROJECTILE_BEHAVIOR = new IProjectileBehavior() { + public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileBehavior() { @Override - public void onMoving(TextureProjectile projectile) { - projectile.level().addParticle( - ModParticles.SEEDLER_THORN_PARTICLE.get(), - projectile.getX(), projectile.getY(), projectile.getZ(), - 0, 0, 0 + public void onMoving(StaticProjectile projectile) { + ParticleUtil.addParticle( + projectile.level(), ModParticles.SEEDLER_THORN_PARTICLE.get(), + projectile.position(), 0, + new Vec3(0, 0, 0), 0 ); } @Override - public void onHitEntity(TextureProjectile projectile, EntityHitResult result) { + public void onHitEntity(StaticProjectile projectile, EntityHitResult result) { if(!projectile.level().isClientSide()) { if(result.getEntity() instanceof LivingEntity target) { - if(target.hurt(projectile.damageSources().thrown(projectile, projectile.getOwner()), 7f)) projectile.discard(); + Entity owner = projectile.getOwner(); + if(owner == null) return; + if(!FilterUtil.createLivingTargetFilter(owner).test(target) || !(owner instanceof Player player)) return; + if(target.hurt(projectile.damageSources().playerAttack(player), 7f)) onDied(projectile); } } } @Override - public void onHitBlock(TextureProjectile projectile, BlockHitResult result) { + public void onHitBlock(StaticProjectile projectile, BlockHitResult result) { if(projectile.level().isClientSide()) return; if(!projectile.level().getBlockState(result.getBlockPos()).getCollisionShape(projectile.level(), result.getBlockPos()).isEmpty()) { - projectile.discard(); + onDied(projectile); } } }; @@ -254,47 +194,26 @@ public class Seedler extends SwordItem { ItemStack stack = player.getItemInHand(hand); if(!level.isClientSide()) { - Vec3 lookVec = player.getLookAngle(); - - float yaw = player.getYRot(); - Vec3 horizontalDir = new Vec3( - -Math.sin(yaw * Math.PI / 180), - 0, - Math.cos(yaw * Math.PI / 180) - ); - Vector3f[] dirs = MathUtil.computeProjectileDir( - MathUtil.toVector3f(horizontalDir) - ); - - double vz = Math.sqrt(lookVec.x * lookVec.x + lookVec.z * lookVec.z) * 1.5; - double vy = lookVec.y * 1.5; - String exprZ = String.format(Locale.US, "%.3f*t", vz); - String exprY = String.format(Locale.US, "%.3f*t - %.4f*t*t", vy, GRAVITY * 0.5); - - CompoundTag customData = new CompoundTag(); - customData.putDouble("vz", vz); - customData.putDouble("vy", vy); - - TextureProjectile projectile = new TextureProjectile(ModEntities.TEXTURE_PROJECTILE.get(), level); - projectile.setOwner(player); + StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level); + summon.setOwner(player); Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ()); - projectile.setPos(pos); - projectile.getEntityData().set(TextureProjectile.BEHAVIOR, ProjectileBehaviors.SEEDLER_NUT); - projectile.getEntityData().set(TextureProjectile.ORIGIN, MathUtil.toVector3f(pos)); - projectile.getEntityData().set(TextureProjectile.DIRECTION, dirs[0]); - projectile.getEntityData().set(TextureProjectile.UP, dirs[1]); - projectile.getEntityData().set(TextureProjectile.RIGHT, dirs[2]); - projectile.getEntityData().set(TextureProjectile.ITEM, new ItemStack(ModItems.SEEDLER_NUT.get())); - projectile.getEntityData().set(TextureProjectile.SCALE_X, 0.5f); - projectile.getEntityData().set(TextureProjectile.SCALE_Y, 0.5f); - projectile.getEntityData().set(TextureProjectile.RXPS, 10); - projectile.getEntityData().set(TextureProjectile.LIFETIME, (int) (7 + Math.random() * 36)); - projectile.getEntityData().set(TextureProjectile.EXPRESSION_Z, exprZ); - projectile.getEntityData().set(TextureProjectile.EXPRESSION_Y, exprY); - projectile.getEntityData().set(TextureProjectile.CUSTOM_DATA, customData); + summon.setPos(pos); + summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.SEEDLER_NUT); + summon.getEntityData().set(StaticSummon.RENDER_MODE, "item"); + summon.getEntityData().set(StaticSummon.ITEM, new ItemStack(ModItems.SEEDLER_NUT.get())); + summon.getEntityData().set(StaticSummon.SCALE_X, 0.5f); + summon.getEntityData().set(StaticSummon.SCALE_Y, 0.5f); + summon.getEntityData().set(StaticSummon.RXPS, 10); + summon.getEntityData().set(StaticSummon.LIFETIME, (int) (7 + Math.random() * 36)); - projectile.setDeltaMovement(MathUtil.toVec3(dirs[0])); - level.addFreshEntity(projectile); + summon.setNoGravity(true); + summon.noPhysics = true; + + float[] xyRot = MathUtil.computeXYRot(MathUtil.toVector3f(player.getLookAngle())); + summon.setXRot(xyRot[0]); + summon.setYRot(xyRot[1]); + summon.setDeltaMovement(player.getLookAngle().normalize().scale(VZ)); + level.addFreshEntity(summon); } player.getCooldowns().addCooldown(stack.getItem(), 10); diff --git a/src/main/java/com/lzxnone/terraria/item/weapon/melee/StarWrath.java b/src/main/java/com/lzxnone/terraria/item/weapon/melee/StarWrath.java new file mode 100644 index 0000000..91f20bf --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/item/weapon/melee/StarWrath.java @@ -0,0 +1,239 @@ +package com.lzxnone.terraria.item.weapon.melee; + +import com.lzxnone.terraria.LzxnoneTerraria; +import com.lzxnone.terraria.ModSounds; +import com.lzxnone.terraria.entity.ModEntities; +import com.lzxnone.terraria.entity.projectile.IStaticProjectileBehavior; +import com.lzxnone.terraria.entity.projectile.StaticProjectile; +import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors; +import com.lzxnone.terraria.item.ModItems; +import com.lzxnone.terraria.particle.DustParticleOptions; +import com.lzxnone.terraria.particle.ModParticles; +import com.lzxnone.terraria.utils.*; +import net.minecraft.core.component.DataComponents; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EquipmentSlotGroup; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.SwordItem; +import net.minecraft.world.item.Tiers; +import net.minecraft.world.item.component.CustomData; +import net.minecraft.world.item.component.ItemAttributeModifiers; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.*; +import org.joml.Vector3f; + +public class StarWrath extends SwordItem { + public StarWrath() { + super(Tiers.DIAMOND, new Item.Properties().attributes(ItemAttributeModifiers.builder() + .add(Attributes.ATTACK_DAMAGE, + new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_damage"), 15, AttributeModifier.Operation.ADD_VALUE), + EquipmentSlotGroup.MAINHAND) + .add(Attributes.ATTACK_SPEED, + new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_speed"), -2.4, AttributeModifier.Operation.ADD_VALUE), + EquipmentSlotGroup.MAINHAND) + .build() + )); + } + + public static final DustParticleOptions PARTICLE = new DustParticleOptions( + 0.05f, 0.5f, 40, true, new Vector3f[]{ + new Vector3f(1.0F, 0.8F, 0.5F), + new Vector3f(1.0F, 0.5F, 0.0F), + new Vector3f(1.0F, 0.9F, 0.0F) + } + ); + + public static final DustParticleOptions PARTICLE2 = new DustParticleOptions( + 0.2f, 0.5f, 40, true, new Vector3f[]{ + new Vector3f(1.0F, 0.0F, 1.0F), + new Vector3f(1.0F, 0.6F, 0.8F), + new Vector3f(0.7F, 0.7F, 0.7F) + } + ); + + public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileBehavior() { + @Override + public void onMoving(StaticProjectile projectile) { + if(projectile.tickCount % 3 == 0) { + ParticleUtil.addParticle( + projectile.level(), ModParticles.STAR_PARTICLE.get(), + projectile.position(), 1.0, + new Vec3(0, 0, 0), 0.1 + ); + } + ParticleUtil.addParticles( + projectile.level(), PARTICLE, + projectile.position(), 1.0, + new Vec3(0, 0, 0), 0.1, + 3 + ); + } + @Override + public void onHitEntity(StaticProjectile projectile, EntityHitResult result) { + if(!projectile.level().isClientSide()) { + if(result.getEntity() instanceof LivingEntity target) { + Entity owner = projectile.getOwner(); + if(!FilterUtil.createLivingTargetFilter(owner).test(target) || !(owner instanceof Player player)) return; + target.hurt(projectile.damageSources().playerAttack(player), 16f); + } + } + } + @Override + public void onHitBlock(StaticProjectile projectile, BlockHitResult result) { + CompoundTag customData = projectile.getEntityData().get(StaticProjectile.CUSTOM_DATA); + if(!customData.contains("targetLifetime")) return; + + int targetLifetime = customData.getInt("targetLifetime"); + int age = projectile.getEntityData().get(StaticProjectile.AGE); + + if(!projectile.level().isClientSide()) { + if(age < targetLifetime + 1) { + EntityHitResult entityHit = CollisionUtil.checkEntityHit(projectile); + if(entityHit != null) { + this.onHitEntity(projectile, entityHit); + } + }else { + if(!projectile.level().getBlockState(result.getBlockPos()).getCollisionShape(projectile.level(), result.getBlockPos()).isEmpty()) { + onDied(projectile); + } + } + } + } + + @Override + public void onDied(StaticProjectile projectile) { + if(!projectile.level().isClientSide()) { + ParticleUtil.addParticles( + (ServerLevel) projectile.level(), ModParticles.STAR_PARTICLE.get(), + projectile.position(), new Vec3(0.5, 0.5, 0.5), + 0.2, 10 + ); + ParticleUtil.addParticles( + (ServerLevel) projectile.level(), PARTICLE, + projectile.position(), new Vec3(0.5, 0.5, 0.5), + 0.2, 10 + ); + ParticleUtil.addParticles( + (ServerLevel) projectile.level(), PARTICLE2, + projectile.position(), new Vec3(0.5, 0.5, 0.5), + 0.2, 30 + ); + SoundUtil.playServerSound(projectile.level(), ModSounds.STAR_COLLIDE.get(), projectile.position()); + projectile.discard(); + } + } + }; + + public static final double MAX_RANGE = 48.0; + public static final double HEIGHT = 20.0; + public static final double DELTA_HEIGHT = 10.0; + public static final double SPAWN_OFFSET = 10.0; + public static final double HIT_OFFSET = 1.5; + public static final int SPAWN_COUNT = 3; + + @Override + public InteractionResultHolder use(Level level, Player player, InteractionHand hand) { + ItemStack itemstack = player.getItemInHand(hand); + if(!level.isClientSide()) { + for(int i = 0;i < SPAWN_COUNT;i++) { + Vec3 targetPos = MathUtil.getCrosshairPos(player, level, MAX_RANGE); + + Vec3 spawnPos = new Vec3( + targetPos.x + SPAWN_OFFSET * (Math.random() * 2 - 1), + targetPos.y + HEIGHT + i * DELTA_HEIGHT, + targetPos.z + SPAWN_OFFSET * (Math.random() * 2 - 1) + ); + + Vec3 hitPos = new Vec3( + targetPos.x + HIT_OFFSET * (Math.random() * 2 - 1), + targetPos.y, + targetPos.z + HIT_OFFSET * (Math.random() * 2 - 1) + ); + + Vector3f[] dirs = MathUtil.computeDir( + MathUtil.toVector3f(new Vec3(hitPos.x - spawnPos.x, hitPos.y - spawnPos.y, hitPos.z - spawnPos.z)) + ); + + StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level); + projectile.setOwner(player); + projectile.setPos(spawnPos); + projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.STAR_WRATH_STAR); + projectile.getEntityData().set(StaticProjectile.RENDER_MODE, "item"); + projectile.getEntityData().set(StaticProjectile.ORIGIN, MathUtil.toVector3f(spawnPos)); + projectile.getEntityData().set(StaticProjectile.ITEM, new ItemStack(ModItems.STAR_WRATH_STAR.get())); + projectile.getEntityData().set(StaticProjectile.LIFETIME, 300); + projectile.getEntityData().set(StaticProjectile.DIRECTION, dirs[0]); + projectile.getEntityData().set(StaticProjectile.UP, dirs[1]); + projectile.getEntityData().set(StaticProjectile.RIGHT, dirs[2]); + projectile.getEntityData().set(StaticProjectile.SCALE_X, 2f); + projectile.getEntityData().set(StaticProjectile.SCALE_Y, 1f); + projectile.getEntityData().set(StaticProjectile.GLOW, true); + projectile.getEntityData().set(StaticProjectile.RXP, 90); + projectile.getEntityData().set(StaticProjectile.RZP, 90); + projectile.getEntityData().set(StaticProjectile.EXPRESSION_Z, "t*2"); + + CompoundTag customData = new CompoundTag(); + customData.putInt("targetLifetime", (int) Math.round(targetPos.distanceTo(spawnPos) / 2.0D)); + projectile.getEntityData().set(StaticProjectile.CUSTOM_DATA, customData); + + projectile.setDeltaMovement(MathUtil.toVec3(dirs[0])); + level.addFreshEntity(projectile); + + CustomData.update(DataComponents.CUSTOM_DATA, itemstack, + tag -> tag.putInt("playSoundCount", 3 + player.level().random.nextInt(3))); + } + }else { + ParticleUtil.addParticles( + player.level(), ModParticles.STAR_PARTICLE.get(), + new Vec3(player.getX(), player.getY() + 0.5, player.getZ()), 0.2, + new Vec3(0, 0, 0), 0.2, + 10 + ); + ParticleUtil.addParticles( + player.level(), PARTICLE, + new Vec3(player.getX(), player.getY() + 0.5, player.getZ()), 0.2, + new Vec3(0, 0, 0), 0.2, + 10 + ); + SoundUtil.playClientSound(player, ModSounds.WAVE2.get()); + } + + player.getCooldowns().addCooldown(this, 3); + return InteractionResultHolder.sidedSuccess(itemstack, level.isClientSide()); + } + + @Override + public void inventoryTick(ItemStack stack, Level level, net.minecraft.world.entity.Entity entity, int slotId, boolean isSelected) { + super.inventoryTick(stack, level, entity, slotId, isSelected); + if(entity instanceof Player player) { + if(isSelected) { + if(player.tickCount % 4 == 0) { + int count = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY) + .copyTag().getInt("playSoundCount"); + if(count > 0) { + SoundUtil.playClientSound(player, ModSounds.STAR_FALL.get()); + CustomData.update(DataComponents.CUSTOM_DATA, stack, + tag -> tag.putInt("playSoundCount", count - 1)); + } + } + }else { + int count = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY) + .copyTag().getInt("playSoundCount"); + if(count > 0) { + CustomData.update(DataComponents.CUSTOM_DATA, stack, + tag -> tag.putInt("playSoundCount", 0)); + } + } + } + } +} diff --git a/src/main/java/com/lzxnone/terraria/item/weapon/melee/Starfury.java b/src/main/java/com/lzxnone/terraria/item/weapon/melee/Starfury.java index 7e7daa1..9695b5e 100644 --- a/src/main/java/com/lzxnone/terraria/item/weapon/melee/Starfury.java +++ b/src/main/java/com/lzxnone/terraria/item/weapon/melee/Starfury.java @@ -3,19 +3,21 @@ package com.lzxnone.terraria.item.weapon.melee; import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.ModSounds; import com.lzxnone.terraria.entity.ModEntities; -import com.lzxnone.terraria.entity.projectile.IProjectileBehavior; -import com.lzxnone.terraria.entity.projectile.ProjectileBehaviors; -import com.lzxnone.terraria.entity.projectile.TextureProjectile; +import com.lzxnone.terraria.entity.projectile.IStaticProjectileBehavior; +import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors; +import com.lzxnone.terraria.entity.projectile.StaticProjectile; import com.lzxnone.terraria.item.ModItems; import com.lzxnone.terraria.particle.ModParticles; -import com.lzxnone.terraria.utils.MathUtil; +import com.lzxnone.terraria.utils.*; import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlotGroup; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.AttributeModifier; @@ -46,179 +48,144 @@ public class Starfury extends SwordItem { )); } - public static final IProjectileBehavior PROJECTILE_BEHAVIOR = new IProjectileBehavior() { + public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileBehavior() { @Override - public void onMoving(TextureProjectile projectile) { - projectile.level().addParticle( - ModParticles.STAR_PARTICLE.get(), - projectile.getX(), projectile.getY(), projectile.getZ(), - (Math.random() * 2 - 1) * 0.1, (Math.random() * 2 - 1) * 0.1, (Math.random() * 2 - 1) * 0.1 + public void onMoving(StaticProjectile projectile) { + ParticleUtil.addParticle( + projectile.level(), ModParticles.STAR_PARTICLE.get(), + projectile.position(), 1.0, + new Vec3(0, 0, 0), 0.1 ); } @Override - public void onHitEntity(TextureProjectile projectile, EntityHitResult result) { + public void onHitEntity(StaticProjectile projectile, EntityHitResult result) { if(!projectile.level().isClientSide()) { if(result.getEntity() instanceof LivingEntity target) { - target.hurt(projectile.damageSources().thrown(projectile, projectile.getOwner()), 8f); + Entity owner = projectile.getOwner(); + if(owner == null) return; + if(!FilterUtil.createLivingTargetFilter(owner).test(target) || !(owner instanceof Player player)) return; + target.hurt(projectile.damageSources().playerAttack(player), 8f); } } } @Override - public void onHitBlock(TextureProjectile projectile, BlockHitResult result) { - if(projectile.level().isClientSide()) return; - - CompoundTag customData = projectile.getEntityData().get(TextureProjectile.CUSTOM_DATA); + public void onHitBlock(StaticProjectile projectile, BlockHitResult result) { + CompoundTag customData = projectile.getEntityData().get(StaticProjectile.CUSTOM_DATA); if(!customData.contains("targetLifetime")) return; int targetLifetime = customData.getInt("targetLifetime"); - int age = projectile.getEntityData().get(TextureProjectile.AGE); - if(age < targetLifetime + 1) { - EntityHitResult entityHit = ProjectileUtil.getEntityHitResult( - projectile.level(), - projectile, - projectile.position(), - projectile.position().add(projectile.getDeltaMovement()), - projectile.getBoundingBox() - .expandTowards(projectile.getDeltaMovement()) - .inflate(1.0), - entity -> !entity.isSpectator() && entity.isPickable() && entity != projectile.getOwner() - ); - if(entityHit != null) { - this.onHitEntity(projectile, entityHit); - } - return; - } + int age = projectile.getEntityData().get(StaticProjectile.AGE); - if(!projectile.level().getBlockState(result.getBlockPos()).getCollisionShape(projectile.level(), result.getBlockPos()).isEmpty()) { - ((ServerLevel) projectile.level()).sendParticles( - ModParticles.STAR_PARTICLE.get(), - projectile.getX(), projectile.getY(), projectile.getZ(), - 25, - 0.2, 0.2, 0.2, - 0.2 - ); - projectile.level().playSound(null, projectile, ModSounds.STAR_COLLIDE.get(), SoundSource.PLAYERS, 4.0F, 1.0F); - projectile.discard(); + if(!projectile.level().isClientSide()) { + if(age < targetLifetime + 1) { + EntityHitResult entityHit = CollisionUtil.checkEntityHit(projectile); + if(entityHit != null) { + this.onHitEntity(projectile, entityHit); + } + }else { + if(!projectile.level().getBlockState(result.getBlockPos()).getCollisionShape(projectile.level(), result.getBlockPos()).isEmpty()) { + onDied(projectile); + } + } } } @Override - public void onDied(TextureProjectile projectile) { + public void onDied(StaticProjectile projectile) { if(!projectile.level().isClientSide()) { - projectile.level().playSound(null, projectile, ModSounds.STAR_COLLIDE.get(), SoundSource.PLAYERS, 4.0F, 1.0F); + ParticleUtil.addParticles( + (ServerLevel) projectile.level(), ModParticles.STAR_PARTICLE.get(), + projectile.position(), new Vec3(0.5, 0.5, 0.5), + 0.2, 25 + ); + SoundUtil.playServerSound(projectile.level(), ModSounds.STAR_COLLIDE.get(), projectile.position()); projectile.discard(); } } }; + public static final double MAX_RANGE = 24.0; + public static final double HEIGHT = 20.0; + public static final double SPAWN_OFFSET = 5.0; + @Override public InteractionResultHolder use(Level level, Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); - if(!level.isClientSide() && level instanceof ServerLevel serverLevel) { - Vec3 targetPos = getTargetPosition(player, serverLevel, 24.0D); - double spawnHeight = 20.0D; - double slantOffset = 2.0D; + if(!level.isClientSide()) { + Vec3 targetPos = MathUtil.getCrosshairPos(player, level, MAX_RANGE); Vec3 spawnPos = new Vec3( - targetPos.x + slantOffset * (Math.random() * 2 - 1), - targetPos.y + spawnHeight, - targetPos.z + slantOffset * (Math.random() * 2 - 1) + targetPos.x + SPAWN_OFFSET * (Math.random() * 2 - 1), + targetPos.y + HEIGHT, + targetPos.z + SPAWN_OFFSET * (Math.random() * 2 - 1) ); - Vector3f[] dirs = MathUtil.computeProjectileDir( + + Vector3f[] dirs = MathUtil.computeDir( MathUtil.toVector3f(new Vec3(targetPos.x - spawnPos.x, targetPos.y - spawnPos.y, targetPos.z - spawnPos.z)) ); - TextureProjectile projectile = new TextureProjectile(ModEntities.TEXTURE_PROJECTILE.get(), level); + StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level); projectile.setOwner(player); projectile.setPos(spawnPos); - projectile.getEntityData().set(TextureProjectile.BEHAVIOR, ProjectileBehaviors.STARFURY_STAR); - projectile.getEntityData().set(TextureProjectile.ORIGIN, MathUtil.toVector3f(spawnPos)); - projectile.getEntityData().set(TextureProjectile.ITEM, new ItemStack(ModItems.STARFURY_STAR.get())); - projectile.getEntityData().set(TextureProjectile.LIFETIME, 300); - projectile.getEntityData().set(TextureProjectile.DIRECTION, dirs[0]); - projectile.getEntityData().set(TextureProjectile.UP, dirs[1]); - projectile.getEntityData().set(TextureProjectile.RIGHT, dirs[2]); - projectile.getEntityData().set(TextureProjectile.SCALE_X, 1f); - projectile.getEntityData().set(TextureProjectile.SCALE_Y, 2f); - projectile.getEntityData().set(TextureProjectile.GLOW, true); - projectile.getEntityData().set(TextureProjectile.RXP, 90); - projectile.getEntityData().set(TextureProjectile.RZP, 90); - projectile.getEntityData().set(TextureProjectile.EXPRESSION_Z, "t*2"); + projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.STARFURY_STAR); + projectile.getEntityData().set(StaticProjectile.RENDER_MODE, "item"); + projectile.getEntityData().set(StaticProjectile.ORIGIN, MathUtil.toVector3f(spawnPos)); + projectile.getEntityData().set(StaticProjectile.ITEM, new ItemStack(ModItems.STARFURY_STAR.get())); + projectile.getEntityData().set(StaticProjectile.LIFETIME, 300); + projectile.getEntityData().set(StaticProjectile.DIRECTION, dirs[0]); + projectile.getEntityData().set(StaticProjectile.UP, dirs[1]); + projectile.getEntityData().set(StaticProjectile.RIGHT, dirs[2]); + projectile.getEntityData().set(StaticProjectile.SCALE_X, 2f); + projectile.getEntityData().set(StaticProjectile.SCALE_Y, 1f); + projectile.getEntityData().set(StaticProjectile.GLOW, true); + projectile.getEntityData().set(StaticProjectile.RXP, 90); + projectile.getEntityData().set(StaticProjectile.RZP, 90); + projectile.getEntityData().set(StaticProjectile.EXPRESSION_Z, "t*2"); CompoundTag customData = new CompoundTag(); - customData.putInt("targetLifetime", (int) Math.floor(targetPos.distanceTo(spawnPos) / 2.0D)); - projectile.getEntityData().set(TextureProjectile.CUSTOM_DATA, customData); + customData.putInt("targetLifetime", (int) Math.round(targetPos.distanceTo(spawnPos) / 2.0D)); + projectile.getEntityData().set(StaticProjectile.CUSTOM_DATA, customData); projectile.setDeltaMovement(MathUtil.toVec3(dirs[0])); level.addFreshEntity(projectile); - - ((ServerLevel) player.level()).sendParticles( - ModParticles.STAR_PARTICLE.get(), - player.getX(), player.getY() + 0.5, player.getZ(), - 25, - 0.2, 0.2, 0.2, - 0.2 + }else { + ParticleUtil.addParticles( + player.level(), ModParticles.STAR_PARTICLE.get(), + new Vec3(player.getX(), player.getY() + 0.5, player.getZ()), 0.2, + new Vec3(0, 0, 0), 0.2, + 25 ); - player.level().playSound(null, player, ModSounds.STAR_FALL.get(), SoundSource.PLAYERS, 4.0F, 1.0F); + SoundUtil.playClientSound(player, ModSounds.STAR_FALL.get()); } player.getCooldowns().addCooldown(this, 13); return InteractionResultHolder.sidedSuccess(itemstack, level.isClientSide()); } - private Vec3 getTargetPosition(Player player, Level level, double maxRange) { - Vec3 eyePos = player.getEyePosition(1.0F); - Vec3 lookVec = player.getLookAngle(); - Vec3 maxRangeEnd = eyePos.add(lookVec.scale(maxRange)); - - BlockHitResult blockHit = level.clip(new ClipContext( - eyePos, maxRangeEnd, - ClipContext.Block.COLLIDER, - ClipContext.Fluid.NONE, - player - )); - - Vec3 finalTarget = maxRangeEnd; - if(blockHit.getType() != HitResult.Type.MISS) { - finalTarget = blockHit.getLocation(); - } - - AABB searchBox = player.getBoundingBox().expandTowards(lookVec.scale(maxRange)).inflate(1.0D); - EntityHitResult entityHit = ProjectileUtil.getEntityHitResult( - level, player, eyePos, finalTarget, searchBox, - entity -> !entity.isSpectator() && entity.isPickable() && entity != player - ); - - if(entityHit != null) { - finalTarget = entityHit.getLocation(); - } - - return finalTarget; - } - @Override public void inventoryTick(ItemStack stack, Level level, net.minecraft.world.entity.Entity entity, int slotId, boolean isSelected) { super.inventoryTick(stack, level, entity, slotId, isSelected); - if(isSelected && entity instanceof Player player) { - boolean currentlyOnCooldown = player.getCooldowns().isOnCooldown(this); - boolean wasOnCooldown = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY) - .copyTag().getBoolean("WasOnCooldown"); - - if(wasOnCooldown && !currentlyOnCooldown) { - if(level.isClientSide()) { - player.playSound(ModSounds.MAX_MANA.get(), 4.0F, 1.0F); - }else { - ((ServerLevel) player.level()).sendParticles( - ModParticles.MAX_MANA_PARTICLE, - player.getX(), player.getY() + 0.5, player.getZ(), - 5, - 0.2, 0.2, 0.2, - 0.2 - ); + if(entity instanceof Player player) { + if(isSelected) { + boolean current = player.getCooldowns().isOnCooldown(this); + boolean prev = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY) + .copyTag().getBoolean("onCooldown"); + if(prev && !current) { + if(level.isClientSide()) { + SoundUtil.playClientSound(player, ModSounds.MAX_MANA.get()); + ParticleUtil.addParticles( + player.level(), ModParticles.MAX_MANA_PARTICLE, + new Vec3(player.getX(), player.getY() + 1.0, player.getZ()), 0.05, + new Vec3(0, 0, 0), 0.05, + 5 + ); + } } + CustomData.update(DataComponents.CUSTOM_DATA, stack, + tag -> tag.putBoolean("onCooldown", current)); + }else { + CustomData.update(DataComponents.CUSTOM_DATA, stack, + tag -> tag.putBoolean("onCooldown", false)); } - - CustomData.update(DataComponents.CUSTOM_DATA, stack, - tag -> tag.putBoolean("WasOnCooldown", currentlyOnCooldown)); } } } diff --git a/src/main/java/com/lzxnone/terraria/item/weapon/melee/TerraBlade.java b/src/main/java/com/lzxnone/terraria/item/weapon/melee/TerraBlade.java new file mode 100644 index 0000000..fb8502f --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/item/weapon/melee/TerraBlade.java @@ -0,0 +1,524 @@ +package com.lzxnone.terraria.item.weapon.melee; + +import com.lzxnone.terraria.LzxnoneTerraria; +import com.lzxnone.terraria.ModSounds; +import com.lzxnone.terraria.entity.ModEntities; +import com.lzxnone.terraria.entity.beam.ISwordBeamBehavior; +import com.lzxnone.terraria.entity.beam.SwordBeam; +import com.lzxnone.terraria.entity.beam.SwordBeamBehaviors; +import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior; +import com.lzxnone.terraria.entity.summon.StaticSummon; +import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors; +import com.lzxnone.terraria.item.IItemWaveBehavior; +import com.lzxnone.terraria.network.payload.SwordBeamPayload; +import com.lzxnone.terraria.particle.DustParticleOptions; +import com.lzxnone.terraria.utils.*; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Axis; +import net.minecraft.Util; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EquipmentSlotGroup; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.SwordItem; +import net.minecraft.world.item.Tiers; +import net.minecraft.world.item.component.ItemAttributeModifiers; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.phys.*; +import net.neoforged.neoforge.event.entity.player.AttackEntityEvent; +import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; +import net.neoforged.neoforge.network.PacketDistributor; +import org.joml.Matrix4f; +import org.joml.Quaternionf; +import org.joml.Vector3f; + +import java.util.List; + +public class TerraBlade extends SwordItem { + public TerraBlade() { + super(Tiers.DIAMOND, new Item.Properties().attributes(ItemAttributeModifiers.builder() + .add(Attributes.ATTACK_DAMAGE, + new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_damage"), 10, AttributeModifier.Operation.ADD_VALUE), + EquipmentSlotGroup.MAINHAND) + .add(Attributes.ATTACK_SPEED, + new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_speed"), -2.4, AttributeModifier.Operation.ADD_VALUE), + EquipmentSlotGroup.MAINHAND) + .build() + )); + } + + public static final CompoundTag BEAM_DATA = Util.make(new CompoundTag(), tag -> { + tag.putString("behavior", "terra_blade"); + tag.putInt("cooldown", 8); + tag.putFloat("color0R", 0.173f); + tag.putFloat("color0G", 0.482f); + tag.putFloat("color0B", 0.796f); + tag.putFloat("color1R", 0.431f); + tag.putFloat("color1G", 0.729f); + tag.putFloat("color1B", 0.396f); + tag.putFloat("color2R", 0.478f); + tag.putFloat("color2G", 0.663f); + tag.putFloat("color2B", 0.220f); + + CompoundTag customData = new CompoundTag(); + customData.putInt("hitEntityCount", 0); + tag.put("customData", customData); + }); + + public static final DustParticleOptions PARTICLE = new DustParticleOptions( + 0.075f, 0.5f, 40, true, new Vector3f[]{ + new Vector3f(0.5F, 1.0F, 0.5F), + new Vector3f(0.0F, 1.0F, 0.2F), + new Vector3f(0.7F, 0.7F, 0.7F) + } + ); + + public static final ISwordBeamBehavior SWORD_BEAM_BEHAVIOR = new ISwordBeamBehavior() { + public static final int MAX_HIT_ENTITY_COUNT = 3; + + @Override + public void onMoving(SwordBeam beam) { + if(beam.currentPosition == null) return; + ParticleUtil.addParticle( + beam.level(), PARTICLE, + beam.currentPosition, 0.2, + new Vec3(0, 0, 0), 0.2 + ); + } + + @Override + public void onHitEntity(SwordBeam beam, EntityHitResult result) { + if(!beam.level().isClientSide()) { + if(result.getEntity() instanceof LivingEntity target && beam.getOwner() instanceof Player player && FilterUtil.createLivingTargetFilter(player).test(target)) { + CompoundTag custom_data = beam.getEntityData().get(SwordBeam.CUSTOM_DATA); + if(custom_data.contains("hitEntityCount")) { + int count = custom_data.getInt("hitEntityCount"); + if(count < MAX_HIT_ENTITY_COUNT) { + if(target.hurt(beam.level().damageSources().playerAttack(player), 11.0f)) { + count++; + custom_data.putInt("hitEntityCount", count); + beam.getEntityData().set(SwordBeam.CUSTOM_DATA, custom_data); + } + } + } + } + } + } + + @Override + public void generate(Entity entity, CompoundTag beamData) { + ISwordBeamBehavior.super.generate(entity, beamData); + if(entity instanceof Player player) summon(player); + } + }; + + public static final Vector3f COLOR0 = new Vector3f(0.255f, 0.420f, 0.302f); + public static final Vector3f COLOR1 = new Vector3f(0.173f, 0.482f, 0.796f); + public static final Vector3f COLOR2 = new Vector3f(0.431f, 0.729f, 0.396f); + + public static final ResourceLocation RES0 = ResourceLocation.parse("lzxnoneterraria:textures/vfx/terra_beam0.png"); + public static final ResourceLocation RES1 = ResourceLocation.parse("lzxnoneterraria:textures/vfx/terra_beam3.png"); + public static final ResourceLocation RES2 = ResourceLocation.parse("lzxnoneterraria:textures/vfx/terra_beam4.png"); + public static final ResourceLocation RES3 = ResourceLocation.parse("lzxnoneterraria:textures/vfx/beam_sparkle.png"); + + public static final float FADE_IN = 0.33f; + public static final float FADE_OUT = 0.67f; + + public static final double SPEED = 1.5; + public static final float DAMAGE = 11; + public static final float DAMAGE_PUNISHMENT = 0.75f; + + + public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() { + @Override + public void render(Entity entity, float entityYaw, float partialTick, + PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { + if(!(entity instanceof StaticSummon summon)) return; + + VertexConsumer vertexConsumer0 = bufferSource.getBuffer(RenderType.entityTranslucentEmissive(RES0)); + VertexConsumer vertexConsumer1 = bufferSource.getBuffer(RenderType.entityTranslucentEmissive(RES1)); + VertexConsumer vertexConsumer2 = bufferSource.getBuffer(RenderType.entityTranslucentEmissive(RES2)); + VertexConsumer vertexConsumer3 = bufferSource.getBuffer(RenderType.entityTranslucentEmissive(RES3)); + + float halfWidth = SwordBeam.HALF_WIDTH * SwordBeam.SCALE; + float halfHeight = SwordBeam.HALF_HEIGHT * SwordBeam.SCALE; + + float progress = (summon.getEntityData().get(StaticSummon.AGE) + partialTick) / (float) summon.getEntityData().get(StaticSummon.LIFETIME); + + float alpha; + if(progress <= FADE_IN) { + alpha = 1 - (FADE_IN - progress) / FADE_IN; + }else if(progress >= FADE_OUT) { + alpha = 1 - (progress - FADE_OUT) / (1 - FADE_OUT); + }else { + alpha = 1.0f; + } + + if(alpha < 0.01f) return; + + Quaternionf rotationX = new Quaternionf().fromAxisAngleRad(MathUtil.toVector3f(summon.getLookAngle()), (float) Math.toRadians(summon.getEntityData().get(StaticSummon.RZP))); + Vector3f[] dirs = MathUtil.computeDir( + MathUtil.toVector3f(summon.getLookAngle()), + MathUtil.computeDir(MathUtil.toVector3f(summon.getLookAngle()))[2].rotate(rotationX) + ); + + poseStack.pushPose(); + + float size = 1.0f - 0.25f * progress; + poseStack.scale(size, size, size); + + //左边 + poseStack.pushPose(); + this.applyTranslate(poseStack, dirs[0], dirs[2], 90 - 18 * (1.0f - progress), SwordBeam.DIST); + this.applyRotate(summon, poseStack, dirs[0], dirs[1], 18 * (1.0f - progress)); + renderQuad(poseStack.last().pose(), vertexConsumer0, + COLOR0.x(), COLOR0.y(), COLOR0.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.01f); + poseStack.popPose(); + + //中间 + poseStack.pushPose(); + this.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST); + this.applyRotate(summon, poseStack, dirs[0], dirs[1], 0); + renderQuad(poseStack.last().pose(), vertexConsumer0, + COLOR1.x(), COLOR1.y(), COLOR1.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0f); + poseStack.popPose(); + + //右边 + poseStack.pushPose(); + this.applyTranslate(poseStack, dirs[0], dirs[2], 108, SwordBeam.DIST); + this.applyRotate(summon, poseStack, dirs[0], dirs[1], -9 * (1.0f - progress)); + renderQuad(poseStack.last().pose(), vertexConsumer0, + COLOR2.x(), COLOR2.y(), COLOR2.z(), alpha, halfWidth, halfHeight, 0f, 0, 0.01f); + poseStack.popPose(); + + //三线 + poseStack.pushPose(); + this.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST / 1.5f); + this.applyRotate(summon, poseStack, dirs[0], dirs[1], 0); + poseStack.scale(0.5f, 0.5f, 0.5f); + renderQuad(poseStack.last().pose(), vertexConsumer1, + 1.0f, 1.0f, 1.0f, alpha, halfWidth, halfHeight, 0f, 0f, 0.02f); + poseStack.popPose(); + + poseStack.pushPose(); + this.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST / 1.25f); + this.applyRotate(summon, poseStack, dirs[0], dirs[1], 0); + poseStack.scale(0.75f, 0.75f, 0.75f); + renderQuad(poseStack.last().pose(), vertexConsumer1, + 1.0f, 1.0f, 1.0f, alpha, halfWidth, halfHeight, 0f, 0f, 0.02f); + poseStack.popPose(); + + poseStack.pushPose(); + this.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST * 1.15f); + this.applyRotate(summon, poseStack, dirs[0], dirs[1], 0); + poseStack.scale(0.95f, 0.95f, 0.95f); + renderQuad(poseStack.last().pose(), vertexConsumer1, + 1.0f, 1.0f, 1.0f, alpha, halfWidth, halfHeight, 0f, 0f, 0.02f); + poseStack.popPose(); + + //边缘高光 + poseStack.pushPose(); + this.applyTranslate(poseStack, dirs[0], dirs[2], 100, SwordBeam.DIST * 1.15f); + this.applyRotate(summon, poseStack, dirs[0], dirs[1], 0); + poseStack.scale(1.0f, 1.0f, 1.0f); + for(int i = 0;i < 5;i++) { + renderQuad(poseStack.last().pose(), vertexConsumer2, + COLOR2.x(), COLOR2.y(), COLOR2.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.03f); + } + poseStack.popPose(); + + float sparkleAlpha; + if(progress < FADE_IN) { + sparkleAlpha = 0; + }else if(progress > FADE_OUT) { + sparkleAlpha = 1.0f - (progress - FADE_OUT) / (1.0f - FADE_OUT); + }else { + sparkleAlpha = (progress - FADE_IN) / (FADE_OUT - FADE_IN); + } + + //闪烁(外层) + poseStack.pushPose(); + for(int k = 0;k < 2;k++) { + poseStack.pushPose(); + if(k == 0) { + this.applyTranslate(poseStack, dirs[0], dirs[2], 90 - 60.0 * progress, SwordBeam.DIST * 2f); + this.applyRotate(summon, poseStack, dirs[0], dirs[1], 60 * progress); + }else { + this.applyTranslate(poseStack, dirs[0], dirs[2], 90 + 60.0 * progress, SwordBeam.DIST * 2f + 0.5f * progress); + this.applyRotate(summon, poseStack, dirs[0], dirs[1], -60 * progress); + } + for(int j = 0; j < 2; j++) { + poseStack.pushPose(); + if(j == 0) poseStack.mulPose(Axis.ZP.rotationDegrees(0.0F)); + else poseStack.mulPose(Axis.ZP.rotationDegrees(45.0F)); + poseStack.scale(0.5f, 0.5f, 0.5f); + for(int i = 0; i < 5; i++) { + renderQuad(poseStack.last().pose(), vertexConsumer3, + COLOR2.x(), COLOR2.y(), COLOR2.z(), sparkleAlpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.03f); + } + poseStack.popPose(); + } + poseStack.popPose(); + } + poseStack.popPose(); + + //闪烁(中层) + poseStack.pushPose(); + for(int k = 0;k < 2;k++) { + poseStack.pushPose(); + if(k == 0) { + this.applyTranslate(poseStack, dirs[0], dirs[2], 90 - 30.0 * progress, SwordBeam.DIST * 2f); + this.applyRotate(summon, poseStack, dirs[0], dirs[1], 30 * progress); + }else { + this.applyTranslate(poseStack, dirs[0], dirs[2], 90 + 30.0 * progress, SwordBeam.DIST * 2.1f); + this.applyRotate(summon, poseStack, dirs[0], dirs[1], -30 * progress); + } + for(int j = 0; j < 2; j++) { + poseStack.pushPose(); + if(j == 0) poseStack.mulPose(Axis.ZP.rotationDegrees(0.0F)); + else poseStack.mulPose(Axis.ZP.rotationDegrees(45.0F)); + poseStack.scale(0.75f, 0.75f, 0.75f); + for(int i = 0; i < 5; i++) { + renderQuad(poseStack.last().pose(), vertexConsumer3, + COLOR2.x(), COLOR2.y(), COLOR2.z(), sparkleAlpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.03f); + } + poseStack.popPose(); + } + poseStack.popPose(); + } + poseStack.popPose(); + + //闪烁(内层) + poseStack.pushPose(); + this.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST * 2f); + this.applyRotate(summon, poseStack, dirs[0], dirs[1], 0); + for(int j = 0; j < 2; j++) { + poseStack.pushPose(); + if(j == 0) poseStack.mulPose(Axis.ZP.rotationDegrees(0.0F)); + else poseStack.mulPose(Axis.ZP.rotationDegrees(45.0F)); + poseStack.scale(1.0f, 1.0f, 1.0f); + for(int i = 0; i < 5; i++) { + renderQuad(poseStack.last().pose(), vertexConsumer3, + COLOR2.x(), COLOR2.y(), COLOR2.z(), sparkleAlpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.03f); + } + poseStack.popPose(); + } + poseStack.popPose(); + + + poseStack.popPose(); + } + + public void applyRotate(StaticSummon summon, PoseStack poseStack, Vector3f dir, Vector3f up, double angle) { + Quaternionf rotation = new Quaternionf().fromAxisAngleRad(up, (float) Math.toRadians(angle)); + poseStack.mulPose(rotation); + + float[] xyRot = MathUtil.computeXYRot(dir); + poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1])); + poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0])); + + poseStack.mulPose(Axis.ZP.rotationDegrees(summon.getEntityData().get(StaticSummon.RZP))); + poseStack.mulPose(Axis.XP.rotationDegrees(-90.0F)); + poseStack.mulPose(Axis.ZP.rotationDegrees(-90.0F)); + } + + public void applyTranslate(PoseStack poseStack, Vector3f dir, Vector3f right, double angle, double dist) { + float cos = (float) Math.cos(Math.toRadians(angle)); + float sin = (float) Math.sin(Math.toRadians(angle)); + Vector3f current = new Vector3f( + cos * right.x + sin * dir.x, + cos * right.y + sin * dir.y, + cos * right.z + sin * dir.z + ); + poseStack.translate(current.x * dist, current.y * dist, current.z * dist); + } + + public void renderQuad(Matrix4f matrix, VertexConsumer consumer, float r, float g, float b, float a, float halfWidth, float halfHeight, float offsetX, float offsetY, float offsetZ) { + int ir = (int) (r * 255.0F); + int ig = (int) (g * 255.0F); + int ib = (int) (b * 255.0F); + int ia = (int) (a * 255.0F); + + consumer.addVertex(matrix, -halfWidth, -halfHeight + offsetY, offsetZ) + .setColor(ir, ig, ib, ia).setUv(0.0f, 1.0f) + .setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f); + consumer.addVertex(matrix, halfWidth, -halfHeight + offsetY, offsetZ) + .setColor(ir, ig, ib, ia).setUv(1.0f, 1.0f) + .setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f); + consumer.addVertex(matrix, halfWidth, halfHeight + offsetY, offsetZ) + .setColor(ir, ig, ib, ia).setUv(1.0f, 0.0f) + .setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f); + consumer.addVertex(matrix, -halfWidth, halfHeight + offsetY, offsetZ) + .setColor(ir, ig, ib, ia).setUv(0.0f, 0.0f) + .setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f); + } + + + @Override + public void tick(StaticSummon summon) { + this.checkBeforeTick(summon); + CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA); + + //运动逻辑 + if(!customData.contains("dead")) { + float progress = summon.getEntityData().get(StaticSummon.AGE) / (float) summon.getEntityData().get(StaticSummon.LIFETIME); + if(progress > FADE_IN) { + summon.setDeltaMovement(summon.getLookAngle().normalize().scale(SPEED - SPEED * (progress - FADE_IN) / (1.0f - FADE_IN))); + }else { + summon.setDeltaMovement(summon.getLookAngle().normalize().scale(SPEED)); + } + }else { + summon.setDeltaMovement(summon.getLookAngle().normalize().scale(0.5)); + return; + } + + //碰撞箱计算 + Vec3 center = summon.position().add(summon.getLookAngle().normalize().scale(SwordBeam.DIST)); + if(customData.contains("extX") && customData.contains("extY") && customData.contains("extZ")) { + summon.setBoundingBox(new AABB( + center.x - customData.getInt("extX"), center.y - customData.getInt("extY"), center.z - customData.getInt("extZ"), + center.x + customData.getInt("extX"), center.y + customData.getInt("extY"), center.z + customData.getInt("extZ") + )); + } + + //碰撞计算 + if(!summon.level().isClientSide() && customData.contains("hitCount") && summon.getOwner() instanceof Player player) { + int count = customData.getInt("hitCount"); + LzxnoneTerraria.LOGGER.info("11w111"); + List targets = summon.level().getEntitiesOfClass(LivingEntity.class, summon.getBoundingBox(), FilterUtil.createTargetFilter(summon, summon.getOwner())); + for(LivingEntity target : targets) { + if(target.hurt(summon.damageSources().playerAttack(player), DAMAGE * (float) Math.pow(DAMAGE_PUNISHMENT, count))) { + count++; + //粒子效果 + } + } + if(!targets.isEmpty()) customData.putInt("hitCount", count); + } + + ClipContext context = new ClipContext( + summon.position(), + summon.position().add(summon.getDeltaMovement()), + ClipContext.Block.COLLIDER, + ClipContext.Fluid.NONE, + summon + ); + BlockHitResult blockHit = summon.level().clip(context); + if(blockHit.getType() != HitResult.Type.MISS) { + customData.putBoolean("dead", true); + } + + //粒子 + if(summon.level().isClientSide() && summon.tickCount % 4 == 0) { + Quaternionf rotationX = new Quaternionf().fromAxisAngleRad(MathUtil.toVector3f(summon.getLookAngle()), (float) Math.toRadians(summon.getEntityData().get(StaticSummon.RZP))); + Vector3f[] dirs = MathUtil.computeDir( + MathUtil.toVector3f(summon.getLookAngle()), + MathUtil.computeDir(MathUtil.toVector3f(summon.getLookAngle()))[2].rotate(rotationX) + ); + Vec3 right = MathUtil.toVec3(dirs[2]).normalize(); + Vec3 speed = MathUtil.toVec3(dirs[0]).normalize().scale(summon.getDeltaMovement().length() / 2); + for(int i = 0;i < 5;i++) { + Vec3 delta = right.scale((Math.random() - 0.5) * 4); + ParticleUtil.addParticle( + summon.level(), PARTICLE, + summon.position().add(delta), 0.0, + speed, 0.0 + ); + } + } + + summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData); + + } + }; + + public static void summon(Player player) { + StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), player.level()); + summon.setOwner(player); + Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ()); + summon.setPos(pos); + + float[] xyRot = MathUtil.computeXYRot(MathUtil.toVector3f(player.getLookAngle())); + summon.setXRot(xyRot[0]); + summon.xRotO = xyRot[0]; + summon.setYRot(xyRot[1]); + summon.yRotO = xyRot[1]; + + int randomAngle = (int) ((Math.random() * 2 - 1) * 60); + + summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.TERRA_BLADE_BEAM); + summon.getEntityData().set(StaticSummon.RENDER_MODE, "custom"); + summon.getEntityData().set(StaticSummon.LIFETIME, 40); + summon.getEntityData().set(StaticSummon.RZP, randomAngle); + summon.getEntityData().set(StaticSummon.GLOW, true); + summon.setNoGravity(true); + summon.noPhysics = true; + + CompoundTag customData = new CompoundTag(); + + Quaternionf rotation = new Quaternionf() + .rotateY((float) Math.toRadians(-xyRot[1])) + .rotateX((float) Math.toRadians(xyRot[0])) + .rotateZ((float) Math.toRadians(randomAngle)) + .rotateX((float) Math.toRadians(-90.0)) + .rotateZ((float) Math.toRadians(-90.0)); + + Vector3f axisX = new Vector3f(1, 0, 0).rotate(rotation); + Vector3f axisY = new Vector3f(0, 1, 0).rotate(rotation); + Vector3f axisZ = new Vector3f(0, 0, 1).rotate(rotation); + + float extX = SwordBeam.HALF_WIDTH * SwordBeam.SCALE * Math.abs(axisX.x()) + SwordBeam.HALF_HEIGHT * SwordBeam.SCALE * Math.abs(axisY.x()) + SwordBeam.HALF_THICKNESS * SwordBeam.SCALE * Math.abs(axisZ.x()); + float extY = SwordBeam.HALF_WIDTH * SwordBeam.SCALE * Math.abs(axisX.y()) + SwordBeam.HALF_HEIGHT * SwordBeam.SCALE * Math.abs(axisY.y()) + SwordBeam.HALF_THICKNESS * SwordBeam.SCALE * Math.abs(axisZ.y()); + float extZ = SwordBeam.HALF_WIDTH * SwordBeam.SCALE * Math.abs(axisX.z()) + SwordBeam.HALF_HEIGHT * SwordBeam.SCALE * Math.abs(axisY.z()) + SwordBeam.HALF_THICKNESS * SwordBeam.SCALE * Math.abs(axisZ.z()); + + customData.putInt("hitCount", 0); + customData.putFloat("extX", extX); + customData.putFloat("extY", extY); + customData.putFloat("extZ", extZ); + summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData); + + summon.setDeltaMovement(player.getLookAngle().normalize().scale(SPEED)); + + player.level().addFreshEntity(summon); + } + + public static final IItemWaveBehavior ITEM_WAVE_BEHAVIOR = new IItemWaveBehavior() { + public void onLeftClickAir(PlayerInteractEvent.LeftClickEmpty event) { + Player player = event.getEntity(); + ItemStack itemStack = player.getMainHandItem(); + if(itemStack.isEmpty()) return; + Item item = itemStack.getItem(); + if(item instanceof TerraBlade && !player.getCooldowns().isOnCooldown(item)) { + PacketDistributor.sendToServer(new SwordBeamPayload("terra_blade", BEAM_DATA)); + SoundUtil.playClientSound(player, ModSounds.WAVE.get()); + summon(player); + } + } + public void onAttackEntity(AttackEntityEvent event) { + Player player = event.getEntity(); + ItemStack itemStack = player.getMainHandItem(); + if(itemStack.isEmpty()) return; + Item item = itemStack.getItem(); + if(item instanceof TerraBlade && !player.getCooldowns().isOnCooldown(item)) { + if(!player.level().isClientSide()) { + SwordBeamBehaviors.getBehavior("terra_blade").generate(player, BEAM_DATA); + summon(player); + }else { + SoundUtil.playClientSound(player, ModSounds.WAVE.get()); + } + } + event.setCanceled(true); + } + }; +} diff --git a/src/main/java/com/lzxnone/terraria/item/weapon/melee/TheHorsemansBlade.java b/src/main/java/com/lzxnone/terraria/item/weapon/melee/TheHorsemansBlade.java new file mode 100644 index 0000000..6db76c1 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/item/weapon/melee/TheHorsemansBlade.java @@ -0,0 +1,277 @@ +package com.lzxnone.terraria.item.weapon.melee; + +import com.lzxnone.terraria.LzxnoneTerraria; +import com.lzxnone.terraria.ModSounds; +import com.lzxnone.terraria.entity.ModEntities; +import com.lzxnone.terraria.entity.beam.ISwordBeamBehavior; +import com.lzxnone.terraria.entity.beam.SwordBeam; +import com.lzxnone.terraria.entity.beam.SwordBeamBehaviors; +import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior; +import com.lzxnone.terraria.entity.summon.StaticSummon; +import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors; +import com.lzxnone.terraria.item.IItemWaveBehavior; +import com.lzxnone.terraria.network.payload.SwordBeamPayload; +import com.lzxnone.terraria.particle.DustParticleOptions; +import com.lzxnone.terraria.particle.ModParticles; +import com.lzxnone.terraria.utils.FilterUtil; +import com.lzxnone.terraria.utils.MathUtil; +import com.lzxnone.terraria.utils.ParticleUtil; +import com.lzxnone.terraria.utils.SoundUtil; +import net.minecraft.Util; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.damagesource.DamageTypes; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EquipmentSlotGroup; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.ai.targeting.TargetingConditions; +import net.minecraft.world.entity.monster.Monster; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.SwordItem; +import net.minecraft.world.item.Tiers; +import net.minecraft.world.item.component.ItemAttributeModifiers; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.Vec3; +import net.neoforged.neoforge.event.entity.player.AttackEntityEvent; +import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; +import net.neoforged.neoforge.network.PacketDistributor; +import org.joml.Vector3f; + +import java.util.Comparator; +import java.util.List; + +public class TheHorsemansBlade extends SwordItem { + public TheHorsemansBlade() { + super(Tiers.DIAMOND, new Item.Properties().attributes(ItemAttributeModifiers.builder() + .add(Attributes.ATTACK_DAMAGE, + new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_damage"), 14, AttributeModifier.Operation.ADD_VALUE), + EquipmentSlotGroup.MAINHAND) + .add(Attributes.ATTACK_SPEED, + new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_speed"), -2.4, AttributeModifier.Operation.ADD_VALUE), + EquipmentSlotGroup.MAINHAND) + .build() + )); + } + + public static final CompoundTag BEAM_DATA = Util.make(new CompoundTag(), tag -> { + tag.putString("behavior", "the_horsemans_blade"); + tag.putInt("cooldown", 10); + tag.putFloat("color0R", 0.741f); + tag.putFloat("color0G", 0.133f); + tag.putFloat("color0B", 0.133f); + tag.putFloat("color1R", 0.937f); + tag.putFloat("color1G", 0.408f); + tag.putFloat("color1B", 0.149f); + tag.putFloat("color2R", 0.765f); + tag.putFloat("color2G", 0.471f); + tag.putFloat("color2B", 0.212f); + + CompoundTag customData = new CompoundTag(); + customData.putInt("hitEntityCount", 0); + tag.put("customData", customData); + }); + + public static final DustParticleOptions PARTICLE = new DustParticleOptions( + 0.075f, 0.5f, 40, true, new Vector3f[]{ + new Vector3f(1.0F, 0.8F, 0.5F), + new Vector3f(1.0F, 0.5F, 0.0F), + new Vector3f(1.0F, 0.9F, 0.0F) + } + ); + + public static final ISwordBeamBehavior SWORD_BEAM_BEHAVIOR = new ISwordBeamBehavior() { + public static final int MAX_HIT_ENTITY_COUNT = 3; + public static final float RANGE = 16.0f; + + @Override + public void onMoving(SwordBeam beam) { + if(beam.currentPosition == null) return; + ParticleUtil.addParticle( + beam.level(), PARTICLE, + beam.currentPosition, 0.2, + new Vec3(0, 0, 0), 0.2 + ); + } + + @Override + public void onHitEntity(SwordBeam beam, EntityHitResult result) { + if(!beam.level().isClientSide()) { + if(result.getEntity() instanceof LivingEntity target && beam.getOwner() instanceof Player player && FilterUtil.createLivingTargetFilter(player).test(target)) { + CompoundTag custom_data = beam.getEntityData().get(SwordBeam.CUSTOM_DATA); + if(custom_data.contains("hitEntityCount")) { + int count = custom_data.getInt("hitEntityCount"); + if(count < MAX_HIT_ENTITY_COUNT) { + if(target.hurt(beam.level().damageSources().playerAttack(player), 15.0f)) { + count++; + custom_data.putInt("hitEntityCount", count); + beam.getEntityData().set(SwordBeam.CUSTOM_DATA, custom_data); + + StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), beam.level()); + Entity entity = beam.getOwner(); + if(entity == null) return; + summon.setOwner(entity); + Vec3 pos = MathUtil.getRandomPosInRadius(entity.position(), RANGE); + summon.setPos(pos); + + float[] xyRot = MathUtil.computeXYRot(MathUtil.toVector3f(target.position().subtract(pos))); + summon.setXRot(xyRot[0]); + summon.xRotO = xyRot[0]; + summon.setYRot(xyRot[1]); + summon.yRotO = xyRot[1]; + + summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.THE_HORSEMANS_BLADE_JACK); + summon.getEntityData().set(StaticSummon.RENDER_MODE, "block"); + summon.getEntityData().set(StaticSummon.BLOCK, Blocks.JACK_O_LANTERN.defaultBlockState()); + summon.getEntityData().set(StaticSummon.LIFETIME, 300); + summon.getEntityData().set(StaticSummon.SCALE_X, 0.5f); + summon.getEntityData().set(StaticSummon.SCALE_Y, 0.5f); + summon.getEntityData().set(StaticSummon.SCALE_Z, 0.5f); + summon.getEntityData().set(StaticSummon.RYP, 180); + summon.getEntityData().set(StaticSummon.GLOW, true); + summon.setNoGravity(true); + summon.noPhysics = true; + + CompoundTag customData = new CompoundTag(); + customData.putInt("target", target.getId()); + summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData); + + beam.level().addFreshEntity(summon); + } + } + } + } + } + } + }; + + public static final IItemWaveBehavior ITEM_WAVE_BEHAVIOR = new IItemWaveBehavior() { + public void onLeftClickAir(PlayerInteractEvent.LeftClickEmpty event) { + Player player = event.getEntity(); + ItemStack itemStack = player.getMainHandItem(); + if(itemStack.isEmpty()) return; + Item item = itemStack.getItem(); + if(item instanceof TheHorsemansBlade && !player.getCooldowns().isOnCooldown(item)) { + PacketDistributor.sendToServer(new SwordBeamPayload("the_horsemans_blade", BEAM_DATA)); + SoundUtil.playClientSound(player, ModSounds.WAVE.get()); + } + } + public void onAttackEntity(AttackEntityEvent event) { + Player player = event.getEntity(); + ItemStack itemStack = player.getMainHandItem(); + if(itemStack.isEmpty()) return; + Item item = itemStack.getItem(); + if(item instanceof TheHorsemansBlade && !player.getCooldowns().isOnCooldown(item)) { + if(!player.level().isClientSide()) { + SwordBeamBehaviors.getBehavior("the_horsemans_blade").generate(player, BEAM_DATA); + }else { + SoundUtil.playClientSound(player, ModSounds.WAVE.get()); + } + } + event.setCanceled(true); + } + }; + + public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() { + public static final double SPEED = 0.5; + public static final float DAMAGE = 15.0f; + public static final float RANGE = 32.0f; + @Override + public void tick(StaticSummon summon) { + this.checkBeforeTick(summon); + + CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA); + LivingEntity target = null; + + if(customData.contains("target")) { + Entity entity = summon.level().getEntity(customData.getInt("target")); + if(entity instanceof LivingEntity le && le.isAlive()) { + target = le; + } + } + + if(!summon.level().isClientSide()) { + if(target == null) { + List targets = summon.level().getEntitiesOfClass( + Monster.class, + AABB.ofSize(summon.position(), RANGE * 2, RANGE * 2, RANGE * 2), + FilterUtil.createMonsterFilter(summon.getOwner()) + ); + targets.sort(Comparator.comparingDouble(e -> e.distanceToSqr(summon.position()))); + if(!targets.isEmpty()) target = targets.getFirst(); + if(target != null) { + customData.putInt("target", target.getId()); + summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData); + } + } + } + + if(target != null) { + Vec3 targetPos = target.position().add(0, target.getBbHeight() / 2.0D, 0); + Vec3 selfPos = summon.position(); + Vec3 dir = targetPos.subtract(selfPos).normalize(); + + summon.setDeltaMovement(dir.scale(SPEED)); + + float[] xyRot = MathUtil.computeXYRot(MathUtil.toVector3f(dir)); + summon.setXRot(xyRot[0]); + summon.setYRot(xyRot[1]); + + if(selfPos.distanceToSqr(targetPos) < 2.0D) { + if(summon.getOwner() instanceof Player player && FilterUtil.createLivingTargetFilter(player).test(target) && target.hurt(summon.damageSources().playerAttack(player), DAMAGE)) onDied(summon); + } + }else { + Vec3 dir = summon.getLookAngle().normalize(); + summon.setDeltaMovement(dir.scale(SPEED)); + } + + if(!summon.level().isClientSide()) { + Vec3 pos = summon.position(); + AABB box = new AABB( + pos.x - 0.25, pos.y - 0.25, pos.z - 0.25, + pos.x + 0.25, pos.y + 0.25, pos.z + 0.25 + ); + summon.setBoundingBox(box); + + List hitEntities = summon.level().getEntitiesOfClass( + Monster.class, + summon.getBoundingBox().inflate(0.2D), + FilterUtil.createMonsterFilter(summon.getOwner()) + ); + + if(!hitEntities.isEmpty()) { + for(Entity hitEntity : hitEntities) { + if(target != null && hitEntity.getUUID() == target.getUUID()) continue; + if(summon.getOwner() instanceof Player player) hitEntity.hurt(summon.damageSources().playerAttack(player), DAMAGE); + } + } + }else { + ParticleUtil.addParticles( + summon.level(), PARTICLE, + summon.position(), 0.1, + new Vec3(0, 0, 0), 0.1, + 2 + ); + } + } + + @Override + public void onDied(StaticSummon summon) { + if(!summon.level().isClientSide()) { + ParticleUtil.addParticles( + (ServerLevel) summon.level(), PARTICLE, + summon.position(), new Vec3(0.1, 0.1, 0.1), + 0.1, 50 + ); + summon.discard(); + } + } + }; +} diff --git a/src/main/java/com/lzxnone/terraria/network/ModNetwork.java b/src/main/java/com/lzxnone/terraria/network/ModNetwork.java new file mode 100644 index 0000000..7d30a73 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/network/ModNetwork.java @@ -0,0 +1,22 @@ +package com.lzxnone.terraria.network; + +import com.lzxnone.terraria.LzxnoneTerraria; +import com.lzxnone.terraria.network.handler.SwordBeamHandler; +import com.lzxnone.terraria.network.payload.SwordBeamPayload; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; +import net.neoforged.neoforge.network.registration.PayloadRegistrar; + +@EventBusSubscriber(modid = LzxnoneTerraria.MODID) +public class ModNetwork { + @SubscribeEvent + public static void register(final RegisterPayloadHandlersEvent event) { + final PayloadRegistrar registrar = event.registrar("1.0.0"); + registrar.playToServer( + SwordBeamPayload.TYPE, + SwordBeamPayload.CODEC, + SwordBeamHandler::handle + ); + } +} diff --git a/src/main/java/com/lzxnone/terraria/network/handler/SwordBeamHandler.java b/src/main/java/com/lzxnone/terraria/network/handler/SwordBeamHandler.java new file mode 100644 index 0000000..7a69bf8 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/network/handler/SwordBeamHandler.java @@ -0,0 +1,16 @@ +package com.lzxnone.terraria.network.handler; + +import com.lzxnone.terraria.entity.beam.SwordBeamBehaviors; +import com.lzxnone.terraria.network.payload.SwordBeamPayload; +import net.minecraft.world.level.Level; +import net.neoforged.neoforge.network.handling.IPayloadContext; + +public class SwordBeamHandler { + public static void handle(final SwordBeamPayload payload, final IPayloadContext context) { + context.enqueueWork(() -> { + Level level = context.player().level(); + if(level.isClientSide()) return; + SwordBeamBehaviors.getBehavior(payload.id()).generate(context.player(), payload.beamData()); + }); + } +} diff --git a/src/main/java/com/lzxnone/terraria/network/payload/SwordBeamPayload.java b/src/main/java/com/lzxnone/terraria/network/payload/SwordBeamPayload.java new file mode 100644 index 0000000..1cbb355 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/network/payload/SwordBeamPayload.java @@ -0,0 +1,26 @@ +package com.lzxnone.terraria.network.payload; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.resources.ResourceLocation; + +public record SwordBeamPayload (String id, CompoundTag beamData) implements CustomPacketPayload { + public static final Type TYPE = new Type<>( + ResourceLocation.fromNamespaceAndPath("lzxnoneterraria", "sword_beam_payload") + ); + + public static final StreamCodec CODEC = StreamCodec.composite( + ByteBufCodecs.STRING_UTF8, SwordBeamPayload::id, + ByteBufCodecs.COMPOUND_TAG, SwordBeamPayload::beamData, + SwordBeamPayload::new + ); + + @Override + public Type type() { + return TYPE; + } + +} diff --git a/src/main/java/com/lzxnone/terraria/particle/DustParticle.java b/src/main/java/com/lzxnone/terraria/particle/DustParticle.java index 288a306..de8410c 100644 --- a/src/main/java/com/lzxnone/terraria/particle/DustParticle.java +++ b/src/main/java/com/lzxnone/terraria/particle/DustParticle.java @@ -24,6 +24,8 @@ public class DustParticle extends TextureSheetParticle { double xSpeed, double ySpeed, double zSpeed, DustParticleOptions options, SpriteSet spriteSet) { super(level, x, y, z, xSpeed, ySpeed, zSpeed); + this.hasPhysics = false; + this.sprites = spriteSet; this.friction = 0.9F; diff --git a/src/main/java/com/lzxnone/terraria/particle/ExplodeParticle.java b/src/main/java/com/lzxnone/terraria/particle/ExplodeParticle.java index 6ee7405..cfdf5d8 100644 --- a/src/main/java/com/lzxnone/terraria/particle/ExplodeParticle.java +++ b/src/main/java/com/lzxnone/terraria/particle/ExplodeParticle.java @@ -2,7 +2,6 @@ package com.lzxnone.terraria.particle; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.particle.*; -import net.minecraft.client.renderer.LightTexture; import net.minecraft.core.particles.SimpleParticleType; public class ExplodeParticle extends TextureSheetParticle { @@ -12,6 +11,7 @@ public class ExplodeParticle extends TextureSheetParticle { protected ExplodeParticle(ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, SpriteSet spriteSet) { super(level, x, y, z, xSpeed, ySpeed, zSpeed); + this.hasPhysics = false; this.friction = 0.9F; this.gravity = 0.0F; diff --git a/src/main/java/com/lzxnone/terraria/particle/InfluxWaverDropParticle.java b/src/main/java/com/lzxnone/terraria/particle/InfluxWaverDropParticle.java new file mode 100644 index 0000000..e9cb0e2 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/particle/InfluxWaverDropParticle.java @@ -0,0 +1,152 @@ +package com.lzxnone.terraria.particle; + +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.Camera; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.particle.*; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.core.particles.SimpleParticleType; +import net.minecraft.util.Mth; +import org.joml.Quaternionf; +import org.joml.Vector3f; + +public class InfluxWaverDropParticle extends TextureSheetParticle { + private final float rotSpeed; + private final float baseSize; + private final double dropSpeed; + private final int canDrop; + + private static final double DROP_RADIO = 0.25; + private static final double ACCELERATION = -0.5; + + private static final double MAX_DIST = 0.1; + private static final int COUNT = 15; + + protected InfluxWaverDropParticle(ClientLevel level, double x, double y, double z, + double xSpeed, double ySpeed, double zSpeed, SpriteSet spriteSet) { + super(level, x, y, z, xSpeed, ySpeed, zSpeed); + this.hasPhysics = false; + + this.friction = 0.0F; + this.gravity = 0.0F; + this.dropSpeed = ySpeed; + + if(Math.abs(dropSpeed) < 0.001) this.canDrop = 1; + else this.canDrop = this.random.nextInt(5); + + this.baseSize = 0.05f + (this.random.nextFloat() * 0.05f); + this.quadSize = baseSize; + + this.roll = this.random.nextFloat() * ((float)Math.PI * 2F); + this.oRoll = this.roll; + this.rotSpeed = (this.random.nextFloat() - 0.5F) * 0.025f; + + this.lifetime = 40 + this.random.nextInt(40 / 2); + this.setSprite(spriteSet.get(this.random)); + } + + @Override + public void tick() { + super.tick(); + + this.oRoll = this.roll; + this.roll += this.rotSpeed; + + float lifeRatio = (float) this.age / (float) this.lifetime; + + if(this.canDrop == 0 && lifeRatio > DROP_RADIO) { + this.yd = dropSpeed + (lifeRatio - DROP_RADIO) / (1.0 - DROP_RADIO) * ACCELERATION; + } + + this.quadSize = this.baseSize * (1.0F - lifeRatio); + this.alpha = 1.0F - lifeRatio; + } + + @Override + public void render(VertexConsumer buffer, Camera camera, float partialTick) { + if (this.alpha <= 0.01F) return; + + float lifeRatio = (this.age + partialTick) / (float) this.lifetime; + double progress = (lifeRatio - DROP_RADIO) / (1.0 - DROP_RADIO); + + if(progress <= 0 || canDrop != 0) { + super.render(buffer, camera, partialTick); + return; + } + + float dist = (float) (progress * MAX_DIST); + + Quaternionf quaternion = new Quaternionf(); + this.getFacingCameraMode().setRotation(quaternion, camera, partialTick); + if(this.roll != 0.0F) { + quaternion.rotateZ(Mth.lerp(partialTick, this.oRoll, this.roll)); + } + + float baseX = (float) (Mth.lerp(partialTick, this.xo, this.x) - camera.getPosition().x); + float baseY = (float) (Mth.lerp(partialTick, this.yo, this.y) - camera.getPosition().y); + float baseZ = (float) (Mth.lerp(partialTick, this.zo, this.z) - camera.getPosition().z); + + float u0 = this.getU0(); + float u1 = this.getU1(); + float v0 = this.getV0(); + float v1 = this.getV1(); + + Vector3f[] baseVertices = new Vector3f[]{ + new Vector3f(1.0F, -1.0F, 0.0F), + new Vector3f(1.0F, 1.0F, 0.0F), + new Vector3f( -1.0F, 1.0F, 0.0F), + new Vector3f( -1.0F, -1.0F, 0.0F) + }; + + float[][] uvs = new float[][]{ + new float[]{u1, v1}, + new float[]{u1, v0}, + new float[]{u0, v0}, + new float[]{u0, v1} + }; + + for(int i = 0; i < COUNT; i++) { + float sizeRatio = 1.0F - ((float) i / (COUNT - 1)); + float currentQuadSize = this.quadSize * sizeRatio; + + if(currentQuadSize <= 0.001F) continue; + + float offsetY = i * dist; + + for(int j = 0; j < 4; j++) { + Vector3f vertex = new Vector3f(baseVertices[j]); + vertex.rotate(quaternion).mul(currentQuadSize).add(baseX, baseY + offsetY, baseZ); + + buffer.addVertex(vertex.x(), vertex.y(), vertex.z()) + .setUv(uvs[j][0], uvs[j][1]) + .setColor(this.rCol, this.gCol, this.bCol, this.alpha) + .setLight(LightTexture.FULL_BRIGHT); + } + } + } + + @Override + public int getLightColor(float partialTick) { + return LightTexture.FULL_BRIGHT; + } + + @Override + public ParticleRenderType getRenderType() { + return ModParticleRenderTypes.TRANSLUCENT_EMISSIVE; + } + + public static class Provider implements ParticleProvider { + private final SpriteSet spriteSet; + + public Provider(SpriteSet spriteSet) { + this.spriteSet = spriteSet; + } + + @Override + public Particle createParticle(SimpleParticleType type, ClientLevel level, + double x, double y, double z, + double xSpeed, double ySpeed, double zSpeed) { + return new InfluxWaverDropParticle(level, x, y, z, xSpeed, ySpeed, zSpeed, this.spriteSet); + } + } +} diff --git a/src/main/java/com/lzxnone/terraria/particle/ModParticles.java b/src/main/java/com/lzxnone/terraria/particle/ModParticles.java index 0182264..f798cc9 100644 --- a/src/main/java/com/lzxnone/terraria/particle/ModParticles.java +++ b/src/main/java/com/lzxnone/terraria/particle/ModParticles.java @@ -69,4 +69,6 @@ public class ModParticles { PARTICLE_TYPES.register("explode_particle", () -> new SimpleParticleType(true)); public static final Supplier SEEDLER_THORN_PARTICLE = PARTICLE_TYPES.register("seedler_thorn_particle", () -> new SimpleParticleType(true)); + public static final Supplier INFLUX_WAVER_DROP_PARTICLE = + PARTICLE_TYPES.register("influx_waver_drop_particle", () -> new SimpleParticleType(true)); } \ No newline at end of file diff --git a/src/main/java/com/lzxnone/terraria/particle/SeedlerThornParticle.java b/src/main/java/com/lzxnone/terraria/particle/SeedlerThornParticle.java index e9b5ee7..62cbec8 100644 --- a/src/main/java/com/lzxnone/terraria/particle/SeedlerThornParticle.java +++ b/src/main/java/com/lzxnone/terraria/particle/SeedlerThornParticle.java @@ -10,6 +10,7 @@ public class SeedlerThornParticle extends TextureSheetParticle { protected SeedlerThornParticle(ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, SpriteSet spriteSet) { super(level, x, y, z, xSpeed, ySpeed, zSpeed); + this.hasPhysics = false; this.friction = 0.9F; this.gravity = 0.0F; diff --git a/src/main/java/com/lzxnone/terraria/particle/StarParticle.java b/src/main/java/com/lzxnone/terraria/particle/StarParticle.java index 2a470df..d62e29a 100644 --- a/src/main/java/com/lzxnone/terraria/particle/StarParticle.java +++ b/src/main/java/com/lzxnone/terraria/particle/StarParticle.java @@ -19,6 +19,7 @@ public class StarParticle extends TextureSheetParticle { protected StarParticle(ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, SpriteSet spriteSet) { super(level, x, y, z, xSpeed, ySpeed, zSpeed); + this.hasPhysics = false; this.friction = 0.9F; this.gravity = 0.0F; diff --git a/src/main/java/com/lzxnone/terraria/utils/CollisionUtil.java b/src/main/java/com/lzxnone/terraria/utils/CollisionUtil.java new file mode 100644 index 0000000..a7c5758 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/utils/CollisionUtil.java @@ -0,0 +1,67 @@ +package com.lzxnone.terraria.utils; + +import com.lzxnone.terraria.entity.projectile.StaticProjectile; +import com.lzxnone.terraria.entity.summon.StaticSummon; +import net.minecraft.world.entity.projectile.ProjectileUtil; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.Vec3; + +public class CollisionUtil { + public static EntityHitResult checkEntityHit(StaticProjectile projectile, double inflate) { + EntityHitResult result = ProjectileUtil.getEntityHitResult( + projectile.level(), + projectile, + projectile.position(), + projectile.position().add(projectile.getDeltaMovement()), + projectile.getBoundingBox() + .expandTowards(projectile.getDeltaMovement()) + .inflate(inflate), + FilterUtil.createTargetFilter(projectile, projectile.getOwner()) + ); + return result; + } + + public static EntityHitResult checkEntityHit(StaticProjectile projectile) { + return checkEntityHit(projectile, 1.0); + } + + public static BlockHitResult checkBlockHit(StaticProjectile projectile) { + BlockHitResult result = projectile.level().clip(new ClipContext( + projectile.position(), projectile.position().add(projectile.getDeltaMovement()), + ClipContext.Block.COLLIDER, + ClipContext.Fluid.NONE, + projectile + )); + return result; + } + + public static EntityHitResult checkEntityHit(StaticSummon summon, Vec3 nextPos, double inflate) { + EntityHitResult result = ProjectileUtil.getEntityHitResult( + summon.level(), + summon, + summon.position(), + nextPos, + summon.getBoundingBox() + .expandTowards(nextPos) + .inflate(inflate), + FilterUtil.createTargetFilter(summon, summon.getOwner()) + ); + return result; + } + + public static EntityHitResult checkEntityHit(StaticSummon summon, Vec3 nextPos) { + return checkEntityHit(summon, nextPos, 1.0); + } + + public static BlockHitResult checkBlockHit(StaticSummon summon, Vec3 nextPos) { + BlockHitResult result = summon.level().clip(new ClipContext( + summon.position(), nextPos, + ClipContext.Block.COLLIDER, + ClipContext.Fluid.NONE, + summon + )); + return result; + } +} diff --git a/src/main/java/com/lzxnone/terraria/utils/FilterUtil.java b/src/main/java/com/lzxnone/terraria/utils/FilterUtil.java new file mode 100644 index 0000000..119b4c1 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/utils/FilterUtil.java @@ -0,0 +1,48 @@ +package com.lzxnone.terraria.utils; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.monster.Monster; + +import javax.annotation.Nullable; +import java.util.function.Predicate; + +public class FilterUtil { + public static final Predicate BASE_FILTER = entity -> + entity != null + && entity.isAlive() + && entity.isPickable() + && !entity.isInvulnerable() + && !entity.isSpectator(); + + + public static Predicate createLivingTargetFilter(@Nullable Entity owner) { + return target -> + BASE_FILTER.test(target) + && (owner == null || (target != owner && !target.isAlliedTo(owner))); + } + + public static Predicate createLivingTargetFilter(Entity attacker, @Nullable Entity owner) { + return target -> + createLivingTargetFilter(owner).test(target) + && target != attacker; + } + + public static Predicate createTargetFilter(@Nullable Entity owner) { + return target -> + BASE_FILTER.test(target) + && (owner == null || (target != owner && !target.isAlliedTo(owner))); + } + + public static Predicate createTargetFilter(Entity attacker, @Nullable Entity owner) { + return target -> + createTargetFilter(owner).test(target) + && target != attacker; + } + + public static Predicate createMonsterFilter(@Nullable Entity owner) { + return monster -> + BASE_FILTER.test(monster) + && (owner == null || (monster != owner && !monster.isAlliedTo(owner))); + } +} diff --git a/src/main/java/com/lzxnone/terraria/utils/MathUtil.java b/src/main/java/com/lzxnone/terraria/utils/MathUtil.java index 7815b0d..c2be520 100644 --- a/src/main/java/com/lzxnone/terraria/utils/MathUtil.java +++ b/src/main/java/com/lzxnone/terraria/utils/MathUtil.java @@ -1,10 +1,14 @@ package com.lzxnone.terraria.utils; -import net.minecraft.world.phys.Vec3; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.ProjectileUtil; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.*; import org.joml.Vector3f; public class MathUtil { - public static Vector3f[] computeProjectileDir(Vector3f tempDir) { + public static Vector3f[] computeDir(Vector3f tempDir) { Vector3f dir = new Vector3f(tempDir.x, tempDir.y, tempDir.z).normalize(); // 方向接近垂直时用 X 轴,否则用 Y 轴做参考向量 @@ -19,6 +23,88 @@ public class MathUtil { return new Vector3f[]{dir, up, right}; } + public static Vector3f[] computeDir(Vector3f tempDir, Vector3f tempRight) { + Vector3f dir = new Vector3f(tempDir.x, tempDir.y, tempDir.z).normalize(); + Vector3f right = new Vector3f(tempRight.x, tempRight.y, tempRight.z).normalize(); + + Vector3f up = new Vector3f(); + dir.cross(right, up).normalize(); + + up.cross(dir, right).normalize(); + + return new Vector3f[]{dir, up, right}; + } + + public static float[] computeXYRot(Vector3f dir) { + float xzLen = (float) Math.sqrt(dir.x() * dir.x() + dir.z() * dir.z()); + float pitch = (float) (Math.atan2(-dir.y(), xzLen) * (180.0 / Math.PI)); + float yaw = (float) (Math.atan2(-dir.x(), dir.z()) * (180.0 / Math.PI)); + return new float[]{pitch, yaw}; + } + + public static Vec3 getRandomPosForRadius(Vec3 pos, double radius, boolean on) { + double u = Math.random(); + double v = Math.random(); + double w = Math.random(); + + double r = on ? radius : radius * Math.cbrt(u); + double cosPhi = 2.0 * v - 1.0; + double sinPhi = Math.sqrt(1.0 - cosPhi * cosPhi); + double theta = w * Math.PI * 2.0; + + double offsetX = r * sinPhi * Math.cos(theta); + double offsetY = r * cosPhi; + double offsetZ = r * sinPhi * Math.sin(theta); + + return new Vec3(pos.x + offsetX, pos.y + offsetY, pos.z + offsetZ); + } + + public static Vec3 getRandomPosOnRadius(Vec3 pos, double radius) { + return getRandomPosForRadius(pos, radius, true); + } + + public static Vec3 getRandomPosInRadius(Vec3 pos, double radius) { + return getRandomPosForRadius(pos, radius, false); + } + + public static Vec3 getCrosshairPos(Player player, Level level, double range, boolean checkBlock, boolean checkEntity) { + Vec3 eyePos = player.getEyePosition(1.0F); + Vec3 lookVec = player.getLookAngle().normalize(); + Vec3 maxRangeEnd = eyePos.add(lookVec.scale(range)); + Vec3 finalTarget = maxRangeEnd; + + if(checkBlock) { + BlockHitResult blockHit = level.clip(new ClipContext( + eyePos, maxRangeEnd, + ClipContext.Block.COLLIDER, + ClipContext.Fluid.NONE, + player + )); + + if(blockHit.getType() != HitResult.Type.MISS) { + finalTarget = blockHit.getLocation(); + } + } + + if(checkEntity) { + AABB searchBox = player.getBoundingBox().expandTowards(lookVec.scale(range)).inflate(1.0D); + EntityHitResult entityHit = ProjectileUtil.getEntityHitResult( + level, player, eyePos, finalTarget, searchBox, + entity -> !entity.isSpectator() && entity.isPickable() && entity != player + ); + + if(entityHit != null) { + finalTarget = entityHit.getLocation(); + } + } + + return finalTarget; + } + + public static Vec3 getCrosshairPos(Player player, Level level, double range) { + return getCrosshairPos(player, level, range, true, true); + } + public static Vector3f toVector3f(Vec3 vec3) { return new Vector3f((float) vec3.x, (float) vec3.y, (float) vec3.z); } diff --git a/src/main/java/com/lzxnone/terraria/utils/ParticleUtil.java b/src/main/java/com/lzxnone/terraria/utils/ParticleUtil.java new file mode 100644 index 0000000..894eea0 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/utils/ParticleUtil.java @@ -0,0 +1,27 @@ +package com.lzxnone.terraria.utils; + +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.Vec3; + + +public class ParticleUtil { + public static void addParticle(Level level, ParticleOptions particleData, Vec3 pos, double randomRadius, Vec3 speed, double randomSpeed) { + if(level.isClientSide()) { + level.addParticle(particleData, true, + pos.x + (Math.random() * 2 - 1) * randomRadius, pos.y + (Math.random() * 2 - 1) * randomRadius, pos.z + (Math.random() * 2 - 1) * randomRadius, + speed.x + (Math.random() * 2 - 1) * randomSpeed, speed.y + (Math.random() * 2 - 1) * randomSpeed, speed.z + (Math.random() * 2 - 1) * randomSpeed); + } + } + + public static void addParticles(Level level, ParticleOptions particleData, Vec3 pos, double randomRadius, Vec3 speed, double randomSpeed, int count) { + if(level.isClientSide()) { + while(count-- > 0) addParticle(level, particleData, pos, randomRadius, speed, randomSpeed); + } + } + + public static void addParticles(ServerLevel level, ParticleOptions particleData, Vec3 pos, Vec3 offset, double speed, int count) { + level.sendParticles(particleData, pos.x, pos.y, pos.z, count, offset.x, offset.y, offset.z, speed); + } +} diff --git a/src/main/java/com/lzxnone/terraria/utils/SoundUtil.java b/src/main/java/com/lzxnone/terraria/utils/SoundUtil.java new file mode 100644 index 0000000..fa726c4 --- /dev/null +++ b/src/main/java/com/lzxnone/terraria/utils/SoundUtil.java @@ -0,0 +1,61 @@ +package com.lzxnone.terraria.utils; + +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.Vec3; + +public class SoundUtil { + public static void playClientSound(Player player, SoundEvent event) { + if(player.level().isClientSide()) { + player.playSound(event, 4.0f, 1.0f); + } + } + + public static void playClientSound(Player player, SoundEvent event, float volume, float pitch) { + if(player.level().isClientSide()) { + player.playSound(event, volume, pitch); + } + } + + public static void playServerSound(Level level, SoundEvent event, Vec3 pos) { + if(!level.isClientSide()) { + level.playSound( + null, + pos.x, pos.y, pos.z, + event, + SoundSource.PLAYERS, + 4.0f, + 1.0f + ); + } + } + + public static void playServerSound(Level level, SoundEvent event, Vec3 pos, float volume, float pitch) { + if(!level.isClientSide()) { + level.playSound( + null, + pos.x, pos.y, pos.z, + event, + SoundSource.PLAYERS, + volume, + pitch + ); + } + } + + public static void playServerSound(Entity entity, SoundEvent event, float volume, float pitch) { + if(!entity.level().isClientSide()) { + entity.level().playSound( + null, + entity, + event, + SoundSource.PLAYERS, + volume, + pitch + ); + } + } +} diff --git a/src/main/resources/assets/lzxnoneterraria/lang/en_us.json b/src/main/resources/assets/lzxnoneterraria/lang/en_us.json index cb7ca61..35809eb 100644 --- a/src/main/resources/assets/lzxnoneterraria/lang/en_us.json +++ b/src/main/resources/assets/lzxnoneterraria/lang/en_us.json @@ -14,6 +14,8 @@ "item.lzxnoneterraria.the_horsemans_blade": "The Horseman's Blade", "item.lzxnoneterraria.zenith": "Zenith", + "entity.lzxnoneterraria.static_projectile": "Projectile", + "entity.lzxnoneterraria.static_summon": "Summon", "entity.lzxnoneterraria.bee_summon": "Bee", "effect.lzxnoneterraria.confused": "Confused" diff --git a/src/main/resources/assets/lzxnoneterraria/lang/zh_cn.json b/src/main/resources/assets/lzxnoneterraria/lang/zh_cn.json index 3af2d81..276a98f 100644 --- a/src/main/resources/assets/lzxnoneterraria/lang/zh_cn.json +++ b/src/main/resources/assets/lzxnoneterraria/lang/zh_cn.json @@ -14,6 +14,8 @@ "item.lzxnoneterraria.the_horsemans_blade": "无头骑士剑", "item.lzxnoneterraria.zenith": "天顶剑", + "entity.lzxnoneterraria.static_projectile": "弹射物", + "entity.lzxnoneterraria.static_summon": "召唤物", "entity.lzxnoneterraria.bee_summon": "蜜蜂", "effect.lzxnoneterraria.confused": "困惑" diff --git a/src/main/resources/assets/lzxnoneterraria/models/item/influx_waver_beam.json b/src/main/resources/assets/lzxnoneterraria/models/item/influx_waver_beam.json new file mode 100644 index 0000000..951bae0 --- /dev/null +++ b/src/main/resources/assets/lzxnoneterraria/models/item/influx_waver_beam.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "lzxnoneterraria:item/influx_waver_beam" + } +} diff --git a/src/main/resources/assets/lzxnoneterraria/models/item/meowmere_projectile.json b/src/main/resources/assets/lzxnoneterraria/models/item/meowmere_projectile.json new file mode 100644 index 0000000..f547415 --- /dev/null +++ b/src/main/resources/assets/lzxnoneterraria/models/item/meowmere_projectile.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "lzxnoneterraria:item/meowmere_projectile" + } +} diff --git a/src/main/resources/assets/lzxnoneterraria/models/item/star_wrath_star.json b/src/main/resources/assets/lzxnoneterraria/models/item/star_wrath_star.json new file mode 100644 index 0000000..41dd821 --- /dev/null +++ b/src/main/resources/assets/lzxnoneterraria/models/item/star_wrath_star.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "lzxnoneterraria:item/star_wrath_star" + } +} diff --git a/src/main/resources/assets/lzxnoneterraria/models/item/weapon.json b/src/main/resources/assets/lzxnoneterraria/models/item/weapon.json index 89e1470..cc3d1ae 100644 --- a/src/main/resources/assets/lzxnoneterraria/models/item/weapon.json +++ b/src/main/resources/assets/lzxnoneterraria/models/item/weapon.json @@ -18,7 +18,7 @@ }, "firstperson_lefthand": { "rotation": [0, -90, -25], - "translation": [1.13, 3.2, 3.0], + "translation": [1.13, 6.2, 0.0], "scale": [0.68, 0.68, 0.68] } } diff --git a/src/main/resources/assets/lzxnoneterraria/particles/influx_waver_drop_particle.json b/src/main/resources/assets/lzxnoneterraria/particles/influx_waver_drop_particle.json new file mode 100644 index 0000000..65cf15b --- /dev/null +++ b/src/main/resources/assets/lzxnoneterraria/particles/influx_waver_drop_particle.json @@ -0,0 +1,7 @@ +{ + "textures": [ + "lzxnoneterraria:influx_waver_particle0", + "lzxnoneterraria:influx_waver_particle1", + "lzxnoneterraria:influx_waver_particle2" + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/lzxnoneterraria/sounds.json b/src/main/resources/assets/lzxnoneterraria/sounds.json index 4b35374..fe4f996 100644 --- a/src/main/resources/assets/lzxnoneterraria/sounds.json +++ b/src/main/resources/assets/lzxnoneterraria/sounds.json @@ -2,6 +2,9 @@ "wave": { "sounds": ["lzxnoneterraria:wave"] }, + "wave2": { + "sounds": ["lzxnoneterraria:wave2"] + }, "max_mana": { "sounds": ["lzxnoneterraria:max_mana"] }, @@ -16,5 +19,11 @@ }, "boom": { "sounds": ["lzxnoneterraria:boom"] + }, + "cat": { + "sounds": ["lzxnoneterraria:cat"] + }, + "cat2": { + "sounds": ["lzxnoneterraria:cat2"] } } diff --git a/src/main/resources/assets/lzxnoneterraria/sounds/cat.ogg b/src/main/resources/assets/lzxnoneterraria/sounds/cat.ogg new file mode 100644 index 0000000..fd369d6 Binary files /dev/null and b/src/main/resources/assets/lzxnoneterraria/sounds/cat.ogg differ diff --git a/src/main/resources/assets/lzxnoneterraria/sounds/cat2.ogg b/src/main/resources/assets/lzxnoneterraria/sounds/cat2.ogg new file mode 100644 index 0000000..e40bf8e Binary files /dev/null and b/src/main/resources/assets/lzxnoneterraria/sounds/cat2.ogg differ diff --git a/src/main/resources/assets/lzxnoneterraria/sounds/wave2.ogg b/src/main/resources/assets/lzxnoneterraria/sounds/wave2.ogg new file mode 100644 index 0000000..d7b43c4 Binary files /dev/null and b/src/main/resources/assets/lzxnoneterraria/sounds/wave2.ogg differ diff --git a/src/main/resources/assets/lzxnoneterraria/textures/item/influx_waver_beam.png b/src/main/resources/assets/lzxnoneterraria/textures/item/influx_waver_beam.png new file mode 100644 index 0000000..b0ab5da Binary files /dev/null and b/src/main/resources/assets/lzxnoneterraria/textures/item/influx_waver_beam.png differ diff --git a/src/main/resources/assets/lzxnoneterraria/textures/item/meowmere_projectile.png b/src/main/resources/assets/lzxnoneterraria/textures/item/meowmere_projectile.png new file mode 100644 index 0000000..75e3a85 Binary files /dev/null and b/src/main/resources/assets/lzxnoneterraria/textures/item/meowmere_projectile.png differ diff --git a/src/main/resources/assets/lzxnoneterraria/textures/item/star_wrath_projectile.png b/src/main/resources/assets/lzxnoneterraria/textures/item/star_wrath_star.png similarity index 100% rename from src/main/resources/assets/lzxnoneterraria/textures/item/star_wrath_projectile.png rename to src/main/resources/assets/lzxnoneterraria/textures/item/star_wrath_star.png diff --git a/src/main/resources/assets/lzxnoneterraria/textures/particle/enchanted_sword_beam_particle_arms.png b/src/main/resources/assets/lzxnoneterraria/textures/particle/enchanted_sword_beam_particle_arms.png deleted file mode 100644 index 3715172..0000000 Binary files a/src/main/resources/assets/lzxnoneterraria/textures/particle/enchanted_sword_beam_particle_arms.png and /dev/null differ diff --git a/src/main/resources/assets/lzxnoneterraria/textures/particle/enchanted_sword_beam_particle_center.png b/src/main/resources/assets/lzxnoneterraria/textures/particle/enchanted_sword_beam_particle_center.png deleted file mode 100644 index 67a264b..0000000 Binary files a/src/main/resources/assets/lzxnoneterraria/textures/particle/enchanted_sword_beam_particle_center.png and /dev/null differ diff --git a/src/main/resources/assets/lzxnoneterraria/textures/particle/influx_waver_particle0.png b/src/main/resources/assets/lzxnoneterraria/textures/particle/influx_waver_particle0.png new file mode 100644 index 0000000..e01bab2 Binary files /dev/null and b/src/main/resources/assets/lzxnoneterraria/textures/particle/influx_waver_particle0.png differ diff --git a/src/main/resources/assets/lzxnoneterraria/textures/particle/influx_waver_particle1.png b/src/main/resources/assets/lzxnoneterraria/textures/particle/influx_waver_particle1.png new file mode 100644 index 0000000..8367ecd Binary files /dev/null and b/src/main/resources/assets/lzxnoneterraria/textures/particle/influx_waver_particle1.png differ diff --git a/src/main/resources/assets/lzxnoneterraria/textures/particle/influx_waver_particle2.png b/src/main/resources/assets/lzxnoneterraria/textures/particle/influx_waver_particle2.png new file mode 100644 index 0000000..9794a85 Binary files /dev/null and b/src/main/resources/assets/lzxnoneterraria/textures/particle/influx_waver_particle2.png differ diff --git a/src/main/resources/assets/lzxnoneterraria/textures/vfx/beam_sparkle.png b/src/main/resources/assets/lzxnoneterraria/textures/vfx/beam_sparkle.png new file mode 100644 index 0000000..b7441c4 Binary files /dev/null and b/src/main/resources/assets/lzxnoneterraria/textures/vfx/beam_sparkle.png differ diff --git a/src/main/resources/assets/lzxnoneterraria/textures/vfx/rainbow.png b/src/main/resources/assets/lzxnoneterraria/textures/vfx/rainbow.png new file mode 100644 index 0000000..dbfeb03 Binary files /dev/null and b/src/main/resources/assets/lzxnoneterraria/textures/vfx/rainbow.png differ diff --git a/src/main/resources/assets/lzxnoneterraria/textures/vfx/terra_beam0.png b/src/main/resources/assets/lzxnoneterraria/textures/vfx/terra_beam0.png new file mode 100644 index 0000000..b64da9b Binary files /dev/null and b/src/main/resources/assets/lzxnoneterraria/textures/vfx/terra_beam0.png differ diff --git a/src/main/resources/assets/lzxnoneterraria/textures/vfx/terra_beam1.png b/src/main/resources/assets/lzxnoneterraria/textures/vfx/terra_beam1.png new file mode 100644 index 0000000..29b39c3 Binary files /dev/null and b/src/main/resources/assets/lzxnoneterraria/textures/vfx/terra_beam1.png differ diff --git a/src/main/resources/assets/lzxnoneterraria/textures/vfx/terra_beam2.png b/src/main/resources/assets/lzxnoneterraria/textures/vfx/terra_beam2.png new file mode 100644 index 0000000..e8e7844 Binary files /dev/null and b/src/main/resources/assets/lzxnoneterraria/textures/vfx/terra_beam2.png differ diff --git a/src/main/resources/assets/lzxnoneterraria/textures/vfx/terra_beam3.png b/src/main/resources/assets/lzxnoneterraria/textures/vfx/terra_beam3.png new file mode 100644 index 0000000..76c159b Binary files /dev/null and b/src/main/resources/assets/lzxnoneterraria/textures/vfx/terra_beam3.png differ diff --git a/src/main/resources/assets/lzxnoneterraria/textures/vfx/terra_beam4.png b/src/main/resources/assets/lzxnoneterraria/textures/vfx/terra_beam4.png new file mode 100644 index 0000000..cf9a745 Binary files /dev/null and b/src/main/resources/assets/lzxnoneterraria/textures/vfx/terra_beam4.png differ