This commit is contained in:
LZX committed 2026-07-27 00:08:36 +08:00
1 parent 0e66621a04
commit 2a568f7952
94 files changed
+4314 -3181

No files matched your search

@@ -4,6 +4,7 @@ import com.lzxnone.terraria.attachment.ModAttachments;
import com.lzxnone.terraria.block.ModBlocks; import com.lzxnone.terraria.block.ModBlocks;
import com.lzxnone.terraria.creative_mode_tab.ModCreativeModeTabs; import com.lzxnone.terraria.creative_mode_tab.ModCreativeModeTabs;
import com.lzxnone.terraria.effect.ModEffects; import com.lzxnone.terraria.effect.ModEffects;
import com.lzxnone.terraria.effect.ModPotions;
import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.summon.BeeSummon; import com.lzxnone.terraria.entity.summon.BeeSummon;
import com.lzxnone.terraria.item.ModItems; import com.lzxnone.terraria.item.ModItems;
@@ -26,6 +27,7 @@ public class LzxnoneTerraria {
ModBlocks.BLOCKS.register(modEventBus); ModBlocks.BLOCKS.register(modEventBus);
ModItems.ITEMS.register(modEventBus); ModItems.ITEMS.register(modEventBus);
ModEffects.MOB_EFFECTS.register(modEventBus); ModEffects.MOB_EFFECTS.register(modEventBus);
ModPotions.POTIONS.register(modEventBus);
ModEntities.ENTITY_TYPES.register(modEventBus); ModEntities.ENTITY_TYPES.register(modEventBus);
ModParticles.PARTICLE_TYPES.register(modEventBus); ModParticles.PARTICLE_TYPES.register(modEventBus);
ModSounds.SOUND_EVENTS.register(modEventBus); ModSounds.SOUND_EVENTS.register(modEventBus);
@@ -2,9 +2,9 @@ package com.lzxnone.terraria;
import com.lzxnone.terraria.ui.config.ConfigScreen; import com.lzxnone.terraria.ui.config.ConfigScreen;
import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.beam.SwordBeamRenderer; import com.lzxnone.terraria.client.entity.beam.SwordBeamRenderer;
import com.lzxnone.terraria.entity.projectile.StaticProjectileRenderer; import com.lzxnone.terraria.client.entity.projectile.StaticProjectileRenderer;
import com.lzxnone.terraria.entity.summon.StaticSummonRenderer; import com.lzxnone.terraria.client.entity.summon.StaticSummonRenderer;
import com.lzxnone.terraria.particle.*; import com.lzxnone.terraria.particle.*;
import net.minecraft.client.renderer.entity.BeeRenderer; import net.minecraft.client.renderer.entity.BeeRenderer;
import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.Dist;
@@ -0,0 +1,28 @@
package com.lzxnone.terraria.client.entity.beam;
import com.lzxnone.terraria.client.item.melee.ClientNightsEdge;
import com.lzxnone.terraria.client.item.melee.ClientTrueExcalibur;
import com.lzxnone.terraria.client.item.melee.ClientTrueNightsEdge;
import com.lzxnone.terraria.entity.beam.SwordBeamBehaviors;
import java.util.HashMap;
import java.util.Map;
public class ClientSwordBeamRenderBehaviors {
private static final Map<String, ISwordBeamRenderBehavior> BEHAVIORS = new HashMap<>();
private static final ISwordBeamRenderBehavior DEFAULT_BEHAVIOR = new ISwordBeamRenderBehavior() {};
static {
BEHAVIORS.put(SwordBeamBehaviors.DEFAULT, DEFAULT_BEHAVIOR);
BEHAVIORS.put(SwordBeamBehaviors.THE_HORSEMANS_BLADE, DEFAULT_BEHAVIOR);
BEHAVIORS.put(SwordBeamBehaviors.TERRA_BLADE, DEFAULT_BEHAVIOR);
BEHAVIORS.put(SwordBeamBehaviors.TRUE_EXCALIBUR, ClientTrueExcalibur.SWORD_BEAM_BEHAVIOR);
BEHAVIORS.put(SwordBeamBehaviors.TRUE_NIGHTS_EDGE, ClientTrueNightsEdge.SWORD_BEAM_BEHAVIOR);
BEHAVIORS.put(SwordBeamBehaviors.EXCALIBUR, DEFAULT_BEHAVIOR);
BEHAVIORS.put(SwordBeamBehaviors.NIGHTS_EDGE, ClientNightsEdge.SWORD_BEAM_BEHAVIOR);
}
public static ISwordBeamRenderBehavior getBehavior(String id) {
return BEHAVIORS.getOrDefault(id, BEHAVIORS.get(SwordBeamBehaviors.DEFAULT));
}
}
@@ -0,0 +1,157 @@
package com.lzxnone.terraria.client.entity.beam;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.beam.SwordBeam;
import com.lzxnone.terraria.utils.MathUtil;
import com.lzxnone.terraria.utils.RenderUtil;
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.texture.OverlayTexture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import org.joml.Matrix4f;
import org.joml.Vector3f;
public interface ISwordBeamRenderBehavior {
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) return;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(beam.getOwner());
dirs = MathUtil.rotateCoordinateSystem(dirs[0], dirs[2], beam.getEntityData().get(SwordBeam.ROTATE));
float rotate = beam.getEntityData().get(SwordBeam.ROTATE);
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;
}
if(beam.getEntityData().get(SwordBeam.RIGHT)) progress = 1.0f - progress;
float halfWidth = SwordBeam.HALF_WIDTH * SwordBeam.SCALE;
float halfHeight = SwordBeam.HALF_HEIGHT * SwordBeam.SCALE;
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES0));
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress - 0.1f * (1.0f - progress)) * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress - 0.1f * (1.0f - progress))) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color0.x(), color0.y(), color0.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.01f);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.1f) * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress + 0.05f)) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color2.x(), color2.y(), color2.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.02f);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], progress * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color1.x(), color1.y(), color1.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0f);
poseStack.popPose();
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES3));
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.05f) * 180, SwordBeam.DIST / 1.5f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(0.5f, 0.5f, 0.5f);
renderQuad(poseStack.last().pose(), vertexConsumer1,
color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.02f);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.05f) * 180, SwordBeam.DIST / 1.25f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(0.75f, 0.75f, 0.75f);
renderQuad(poseStack.last().pose(), vertexConsumer1,
color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.02f);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], progress * 180, SwordBeam.DIST * 1.15f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(0.95f, 0.95f, 0.95f);
renderQuad(poseStack.last().pose(), vertexConsumer1,
color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.02f);
poseStack.popPose();
VertexConsumer vertexConsumer2 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES4));
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.05f) * 180, SwordBeam.DIST * 1.15f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress - 0.05f) * 180, rotate);
poseStack.scale(1.0f, 1.0f, 1.0f);
for(int i = 0;i < 20;i++) {
renderQuad(poseStack.last().pose(), vertexConsumer2,
color1.x(), color1.y(), color1.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.03f);
}
poseStack.popPose();
VertexConsumer vertexConsumer3 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES5));
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.25f) * 180, SwordBeam.DIST * 2.25f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress - 0.25f) * 180, rotate);
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(), vertexConsumer3,
color1.x(), color1.y(), color1.z(), alpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.03f);
}
poseStack.popPose();
}
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);
}
}
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.entity.beam; package com.lzxnone.terraria.client.entity.beam;
import com.lzxnone.terraria.entity.beam.SwordBeam;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRenderer;
@@ -16,7 +17,7 @@ public class SwordBeamRenderer extends EntityRenderer<Entity> {
public void render(Entity entity, float entityYaw, float partialTick, public void render(Entity entity, float entityYaw, float partialTick,
PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof SwordBeam beam)) return; if(!(entity instanceof SwordBeam beam)) return;
SwordBeamBehaviors.getBehavior(beam.getEntityData().get(SwordBeam.BEHAVIOR)).render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientSwordBeamRenderBehaviors.getBehavior(beam.getEntityData().get(SwordBeam.BEHAVIOR)).render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight);
super.render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); super.render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight);
} }
@@ -0,0 +1,35 @@
package com.lzxnone.terraria.client.entity.projectile;
import com.lzxnone.terraria.client.item.melee.ClientBladeOfGrass;
import com.lzxnone.terraria.client.item.melee.ClientDevilsDevastation;
import com.lzxnone.terraria.client.item.melee.ClientMace;
import com.lzxnone.terraria.client.item.melee.ClientMuramasa;
import com.lzxnone.terraria.client.item.melee.ClientZenith;
import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors;
import java.util.HashMap;
import java.util.Map;
public class ClientStaticProjectileRenderBehaviors {
private static final Map<String, IStaticProjectileRenderBehavior> BEHAVIORS = new HashMap<>();
private static final IStaticProjectileRenderBehavior DEFAULT_BEHAVIOR = new IStaticProjectileRenderBehavior() {};
static {
BEHAVIORS.put(StaticProjectileBehaviors.DEFAULT, DEFAULT_BEHAVIOR);
BEHAVIORS.put(StaticProjectileBehaviors.ENCHANTED_SWORD_BEAM, DEFAULT_BEHAVIOR);
BEHAVIORS.put(StaticProjectileBehaviors.STARFURY_STAR, DEFAULT_BEHAVIOR);
BEHAVIORS.put(StaticProjectileBehaviors.SEEDLER_THORN, DEFAULT_BEHAVIOR);
BEHAVIORS.put(StaticProjectileBehaviors.STAR_WRATH_STAR, DEFAULT_BEHAVIOR);
BEHAVIORS.put(StaticProjectileBehaviors.ZENITH_PROJECTILE, ClientZenith.PROJECTILE_BEHAVIOR);
BEHAVIORS.put(StaticProjectileBehaviors.MURAMASA_PROJECTILE, ClientMuramasa.PROJECTILE_BEHAVIOR);
BEHAVIORS.put(StaticProjectileBehaviors.LEAF_PROJECTILE, ClientBladeOfGrass.PROJECTILE_BEHAVIOR);
BEHAVIORS.put(StaticProjectileBehaviors.MACE_PROJECTILE, ClientMace.PROJECTILE_BEHAVIOR);
BEHAVIORS.put(StaticProjectileBehaviors.DEVILS_DEVASTATION_PROJECTILE, ClientDevilsDevastation.PROJECTILE_BEHAVIOR);
BEHAVIORS.put(StaticProjectileBehaviors.DEVILS_DEVASTATION_PROJECTILE2, ClientDevilsDevastation.PROJECTILE_BEHAVIOR2);
BEHAVIORS.put(StaticProjectileBehaviors.DEVILS_DEVASTATION_PROJECTILE3, ClientDevilsDevastation.PROJECTILE_BEHAVIOR3);
}
public static IStaticProjectileRenderBehavior getBehavior(String id) {
return BEHAVIORS.getOrDefault(id, BEHAVIORS.get(StaticProjectileBehaviors.DEFAULT));
}
}
@@ -0,0 +1,137 @@
package com.lzxnone.terraria.client.entity.projectile;
import com.lzxnone.terraria.entity.TintedVertexConsumer;
import com.lzxnone.terraria.entity.projectile.StaticProjectile;
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.Vec3;
import org.joml.Matrix3f;
import org.joml.Quaternionf;
import org.joml.Vector3f;
public interface IStaticProjectileRenderBehavior {
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.computeCoordinateSystem(velForRot, 0);
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.computeCoordinateSystem(velForRot, 0);
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
);
}
default void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {}
}
@@ -0,0 +1,39 @@
package com.lzxnone.terraria.client.entity.projectile;
import com.lzxnone.terraria.entity.projectile.StaticProjectile;
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<Entity> {
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) {
ClientStaticProjectileRenderBehaviors.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()) {
ClientStaticProjectileRenderBehaviors.getBehavior(proj.getEntityData().get(StaticProjectile.BEHAVIOR)).renderBlock(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight);
}else if(proj.getEntityData().get(StaticProjectile.RENDER_MODE).equals("custom")) {
ClientStaticProjectileRenderBehaviors.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;
}
}
@@ -0,0 +1,49 @@
package com.lzxnone.terraria.client.entity.summon;
import com.lzxnone.terraria.client.item.magic.ClientLastPrism;
import com.lzxnone.terraria.client.item.melee.ClientDevilsDevastation;
import com.lzxnone.terraria.client.item.melee.ClientFirstFractal;
import com.lzxnone.terraria.client.item.melee.ClientLightsBane;
import com.lzxnone.terraria.client.item.melee.ClientMace;
import com.lzxnone.terraria.client.item.melee.ClientMeowmere;
import com.lzxnone.terraria.client.item.melee.ClientNightsEdge;
import com.lzxnone.terraria.client.item.melee.ClientTerraBlade;
import com.lzxnone.terraria.client.item.melee.ClientTerragrim;
import com.lzxnone.terraria.client.item.melee.ClientTrueNightsEdge;
import com.lzxnone.terraria.client.item.summon.ClientTerraprisma;
import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors;
import java.util.HashMap;
import java.util.Map;
public class ClientStaticSummonRenderBehaviors {
private static final Map<String, IStaticSummonRenderBehavior> BEHAVIORS = new HashMap<>();
private static final IStaticSummonRenderBehavior DEFAULT_BEHAVIOR = new IStaticSummonRenderBehavior() {};
static {
BEHAVIORS.put(StaticSummonBehaviors.DEFAULT, DEFAULT_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.SEEDLER_NUT, DEFAULT_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.THE_HORSEMANS_BLADE_JACK, DEFAULT_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.INFLUX_WAVER_BEAM, DEFAULT_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.MEOWMERE_PROJECTILE, ClientMeowmere.SUMMON_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.TERRA_BLADE_BEAM, ClientTerraBlade.SUMMON_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.TRUE_NIGHTS_EDGE_BEAM, ClientTrueNightsEdge.SUMMON_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.NIGHTS_EDGE_BEAM, ClientNightsEdge.SUMMON_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.LIGHTS_BANE_SLASH, ClientLightsBane.SUMMON_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.VOLCANO_LIGHT, DEFAULT_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.TERRAGRIM_BEAM, ClientTerragrim.SUMMON_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.FIRST_FRACTAL_PROJECTILE, ClientFirstFractal.SUMMON_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.MACE_PROJECTILE, ClientMace.SUMMON_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.DEVILS_DEVASTATION_STUCK_PROJECTILE, DEFAULT_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.DEVILS_DEVASTATION_LIGHTNING, ClientDevilsDevastation.SUMMON_BEHAVIOR2);
BEHAVIORS.put(StaticSummonBehaviors.DEVILS_DEVASTATION_MARK, ClientDevilsDevastation.SUMMON_BEHAVIOR3);
BEHAVIORS.put(StaticSummonBehaviors.DEVILS_DEVASTATION_MARK_LIGHTNING, ClientDevilsDevastation.SUMMON_BEHAVIOR4);
BEHAVIORS.put(StaticSummonBehaviors.LAST_PRISM_TRI, ClientLastPrism.SUMMON_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.LAST_PRISM_BEAM, ClientLastPrism.SUMMON_BEHAVIOR2);
BEHAVIORS.put(StaticSummonBehaviors.TERRAPRISMA, ClientTerraprisma.SUMMON_BEHAVIOR);
}
public static IStaticSummonRenderBehavior getBehavior(String id) {
return BEHAVIORS.getOrDefault(id, BEHAVIORS.get(StaticSummonBehaviors.DEFAULT));
}
}
@@ -0,0 +1,102 @@
package com.lzxnone.terraria.client.entity.summon;
import com.lzxnone.terraria.entity.TintedVertexConsumer;
import com.lzxnone.terraria.entity.summon.StaticSummon;
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;
public interface IStaticSummonRenderBehavior {
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) {}
}
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.entity.summon; package com.lzxnone.terraria.client.entity.summon;
import com.lzxnone.terraria.entity.summon.StaticSummon;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.model.PlayerModel; import net.minecraft.client.model.PlayerModel;
@@ -10,7 +11,6 @@ import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.inventory.InventoryMenu; import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
@@ -43,21 +43,12 @@ public class StaticSummonRenderer extends EntityRenderer<Entity> {
public void render(Entity entity, float entityYaw, float partialTick, public void render(Entity entity, float entityYaw, float partialTick,
PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon)) return; 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);
}
*/
if(summon.getEntityData().get(StaticSummon.RENDER_MODE).equals("item") && summon.getEntityData().get(StaticSummon.ITEM) != ItemStack.EMPTY) { 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); ClientStaticSummonRenderBehaviors.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()) { }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); ClientStaticSummonRenderBehaviors.getBehavior(summon.getEntityData().get(StaticSummon.BEHAVIOR)).renderBlock(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight);
}else if(summon.getEntityData().get(StaticSummon.RENDER_MODE).equals("custom")) { }else if(summon.getEntityData().get(StaticSummon.RENDER_MODE).equals("custom")) {
StaticSummonBehaviors.getBehavior(summon.getEntityData().get(StaticSummon.BEHAVIOR)).render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientStaticSummonRenderBehaviors.getBehavior(summon.getEntityData().get(StaticSummon.BEHAVIOR)).render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight);
} }
super.render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); super.render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight);
} }
@@ -1,7 +1,6 @@
package com.lzxnone.terraria.event; package com.lzxnone.terraria.client.event;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.attachment.ModAttachments;
import com.lzxnone.terraria.effect.ModEffects; import com.lzxnone.terraria.effect.ModEffects;
import com.lzxnone.terraria.item.ModItems; import com.lzxnone.terraria.item.ModItems;
import net.minecraft.Util; import net.minecraft.Util;
@@ -1,4 +1,4 @@
package com.lzxnone.terraria.event; package com.lzxnone.terraria.client.event;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModKeyBindings; import com.lzxnone.terraria.ModKeyBindings;
@@ -1,4 +1,4 @@
package com.lzxnone.terraria.event; package com.lzxnone.terraria.client.event;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.Dist;
@@ -1,4 +1,4 @@
package com.lzxnone.terraria.event; package com.lzxnone.terraria.client.event;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.DefaultVertexFormat;
@@ -0,0 +1,296 @@
package com.lzxnone.terraria.client.item.magic;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.summon.StaticSummon;
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.texture.OverlayTexture;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import java.util.List;
import com.lzxnone.terraria.client.entity.summon.IStaticSummonRenderBehavior;
import static com.lzxnone.terraria.item.weapon.magic.LastPrism.*;
public class ClientLastPrism {
private static final Vector3f[] BEAM_COLORS = {
new Vector3f(1.0f, 0.0f, 0.0f),
new Vector3f(1.0f, 1.0f, 0.0f),
new Vector3f(0.5f, 0.0f, 0.5f),
new Vector3f(0.0f, 1.0f, 0.0f),
new Vector3f(0.0f, 1.0f, 1.0f),
new Vector3f(1.0f, 0.0f, 0.5f)
};
public static final IStaticSummonRenderBehavior SUMMON_BEHAVIOR = new IStaticSummonRenderBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon)) return;
Entity owner = summon.getOwner();
if(owner == null) return;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(owner);
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
float time = summon.getEntityData().get(StaticSummon.AGE) + partialTick;
float size = 0.35F;
float hue = (time * 0.02F) % 1.0F;
float baseZ = -size / 3.0F;
float baseRadius = size * 2.0F * Mth.sqrt(2.0F) / 3.0F;
Vec3 v0 = new Vec3(0.0D, 0.0D, size);
Vec3 v1 = new Vec3(baseRadius, 0.0D, baseZ);
Vec3 v2 = new Vec3(baseRadius * Math.cos(Math.toRadians(120.0D)), baseRadius * Math.sin(Math.toRadians(120.0D)), baseZ);
Vec3 v3 = new Vec3(baseRadius * Math.cos(Math.toRadians(240.0D)), baseRadius * Math.sin(Math.toRadians(240.0D)), baseZ);
poseStack.pushPose();
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.ZP.rotationDegrees(computePrismAngle(time)));
Matrix4f matrix = poseStack.last().pose();
VertexConsumer innerConsumer = bufferSource.getBuffer(ModRenderTypes.entitySolidEmissiveTriangles(RES));
renderTetrahedronFace(innerConsumer, matrix, v0, v1, v2, 1.0F, 1.0F, 1.0F, 0.5f);
renderTetrahedronFace(innerConsumer, matrix, v0, v3, v1, 1.0F, 1.0F, 1.0F, 0.5f);
renderTetrahedronFace(innerConsumer, matrix, v0, v2, v3, 1.0F, 1.0F, 1.0F, 0.5f);
renderTetrahedronFace(innerConsumer, matrix, v1, v3, v2, 1.0F, 1.0F, 1.0F, 0.5f);
float outerScale = 1.2F;
VertexConsumer outerConsumer = bufferSource.getBuffer(ModRenderTypes.entitySolidEmissiveTriangles(RES));
renderTetrahedronFace(outerConsumer, matrix, v0.scale(outerScale), v1.scale(outerScale), v2.scale(outerScale), hue);
renderTetrahedronFace(outerConsumer, matrix, v0.scale(outerScale), v3.scale(outerScale), v1.scale(outerScale), hue + 0.25F);
renderTetrahedronFace(outerConsumer, matrix, v0.scale(outerScale), v2.scale(outerScale), v3.scale(outerScale), hue + 0.50F);
renderTetrahedronFace(outerConsumer, matrix, v1.scale(outerScale), v3.scale(outerScale), v2.scale(outerScale), hue + 0.75F);
poseStack.popPose();
}
};
public static final IStaticSummonRenderBehavior SUMMON_BEHAVIOR2 = new IStaticSummonRenderBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon beam)) return;
if(!(beam.getOwner() instanceof StaticSummon tri)) return;
BeamData beamData = computeBeamData(tri, getBeamIndex(beam), partialTick);
if (beamData == null) return;
VertexConsumer consumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES));
Matrix4f matrix = poseStack.last().pose();
List<Vec3> points = List.of(beamData.start(), beamData.end());
renderTube(consumer, matrix, beam.position(),
points, beamData.radius() * 0.8f, 1.0f, 1.0f, 1.0f, 1.0f, false);
renderTube(consumer, matrix, beam.position(),
points, beamData.radius(), beam.getEntityData().get(StaticSummon.COLOR_A),
beam.getEntityData().get(StaticSummon.COLOR_R),
beam.getEntityData().get(StaticSummon.COLOR_G),
beam.getEntityData().get(StaticSummon.COLOR_B), false);
}
};
private record BeamData(Vec3 start, Vec3 end, float radius, float ratio, boolean blocked) {}
private static int getBeamIndex(StaticSummon beam) {
CompoundTag customData = beam.getEntityData().get(StaticSummon.CUSTOM_DATA);
return Mth.clamp(customData.getInt("idx"), 0, BEAM_COLORS.length - 1);
}
private static BeamData computeBeamData(StaticSummon tri, int idx, float partialTick) {
Entity owner = tri.getOwner();
if(owner == null) return null;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(owner);
float time = tri.getEntityData().get(StaticSummon.AGE) + partialTick;
float angle = computePrismAngle(time);
float ratio = Math.min(1.0f, time / getChargeTime());
double maxRange = getMaxRange();
double dy = maxRange / 2;
Vec3 basePos = tri.position().add(MathUtil.toVec3(dirs[0]).scale(0.5f));
Vector3f baseDir = MathUtil.toVec3(dirs[0])
.scale(maxRange)
.add(MathUtil.toVec3(dirs[1]).scale(dy * (1.0f - ratio)))
.toVector3f();
Vector3f deltaDir = MathUtil.toVec3(dirs[1])
.scale(DELTA_DIST * (1.0f - ratio) + MIN_DIST)
.toVector3f();
Quaternionf rotation = new Quaternionf().fromAxisAngleRad(dirs[0], (float) Math.toRadians(angle + 60.0 * idx));
Vec3 shootDir = MathUtil.toVec3(baseDir.rotate(rotation));
Vec3 shootPos = basePos.add(MathUtil.toVec3(deltaDir.rotate(rotation)));
Vec3 endPos = shootPos.add(shootDir);
boolean blocked = false;
BlockHitResult blockHit = tri.level().clip(new ClipContext(
shootPos,
endPos,
ClipContext.Block.COLLIDER,
ClipContext.Fluid.NONE,
tri
));
if(blockHit.getType() != HitResult.Type.MISS) {
endPos = blockHit.getLocation();
blocked = true;
}
return new BeamData(shootPos, endPos, MAX_RADIUS * ratio, ratio, blocked);
}
private static float computePrismAngle(float time) {
int chargeTime = getChargeTime();
float a = MAX_ROTATE / chargeTime;
float v = Math.min(a * time, MAX_ROTATE);
if(v < MAX_ROTATE) {
return 0.5f * a * time * time;
}
return 0.5f * a * chargeTime * chargeTime + v * time;
}
private static void renderTetrahedronFace(
VertexConsumer buffer,
Matrix4f matrix,
Vec3 v0,
Vec3 v1,
Vec3 v2,
float hue
) {
float[] color0 = computeSoftPrismColor(hue);
float[] color1 = computeSoftPrismColor(hue + 0.10F);
float[] color2 = computeSoftPrismColor(hue + 0.20F);
renderTetrahedronVertex(buffer, matrix, v0, color0[0], color0[1], color0[2]);
renderTetrahedronVertex(buffer, matrix, v1, color1[0], color1[1], color1[2]);
renderTetrahedronVertex(buffer, matrix, v2, color2[0], color2[1], color2[2]);
}
private static void renderTetrahedronFace(
VertexConsumer buffer,
Matrix4f matrix,
Vec3 v0,
Vec3 v1,
Vec3 v2,
float r,
float g,
float b,
float alpha
) {
renderTetrahedronVertex(buffer, matrix, v0, r, g, b, alpha);
renderTetrahedronVertex(buffer, matrix, v1, r, g, b, alpha);
renderTetrahedronVertex(buffer, matrix, v2, r, g, b, alpha);
}
private static void renderTetrahedronVertex(
VertexConsumer buffer,
Matrix4f matrix,
Vec3 vertex,
float r,
float g,
float b
) {
renderTetrahedronVertex(buffer, matrix, vertex, r, g, b, 1.0F);
}
private static void renderTetrahedronVertex(
VertexConsumer buffer,
Matrix4f matrix,
Vec3 vertex,
float r,
float g,
float b,
float alpha
) {
buffer.addVertex(matrix, (float)vertex.x, (float)vertex.y, (float)vertex.z)
.setColor(r, g, b, alpha)
.setUv(0.5F, 0.5F)
.setOverlay(OverlayTexture.NO_OVERLAY)
.setLight(LightTexture.FULL_BRIGHT)
.setNormal(0.0F, 1.0F, 0.0F);
}
private static float[] computeSoftPrismColor(float hue) {
float normalizedHue = Math.floorMod((int)(hue * 1000.0F), 1000) / 1000.0F;
int color = Mth.hsvToRgb(normalizedHue, 0.85F, 1.0F);
float rainbowR = ((color >> 16) & 255) / 255.0F;
float rainbowG = ((color >> 8) & 255) / 255.0F;
float rainbowB = (color & 255) / 255.0F;
float tint = 0.75F;
return new float[]{
1.0F * (1.0F - tint) + rainbowR * tint,
1.0F * (1.0F - tint) + rainbowG * tint,
1.0F * (1.0F - tint) + rainbowB * tint
};
}
public static void renderTube(VertexConsumer buffer, Matrix4f matrix, Vec3 entityWorldPos,
List<Vec3> points, float radius, float alpha, float colorR, float colorG, float colorB, boolean linear) {
int n = points.size();
if(n < 2) return;
Vector3f[][] oriDirs = new Vector3f[n][3];
Vec3[] dir = new Vec3[n], up = new Vec3[n], right = new Vec3[n];
for(int i = 0;i < n;i++) {
if(i == n - 1) oriDirs[i] = MathUtil.computeCoordinateSystem(points.get(n - 1).subtract(points.get(n - 2)).toVector3f(), 0);
else oriDirs[i] = MathUtil.computeCoordinateSystem(points.get(i + 1).subtract(points.get(i)).toVector3f(), 0);
dir[i] = MathUtil.toVec3(oriDirs[i][0]);
up[i] = MathUtil.toVec3(oriDirs[i][1]);
right[i] = MathUtil.toVec3(oriDirs[i][2]);
}
for(int i = 0;i < n - 1;i++) {
float r0 = linear ? radius * (1.0F - (float) i / (float) (n - 1)) : radius;
float r1 = linear ? radius * (1.0F - (float) (i + 1) / (float) (n - 1)) : radius;
if(r0 <= 0.001F && r1 <= 0.001F) continue;
Vec3 N = right[i], B = up[i], N1 = right[i + 1], B1 = up[i + 1];
Vec3 P = points.get(i), P1 = points.get(i + 1);
for(int j = 0;j < RING;j++) {
float a0 = (float) (2.0 * Math.PI * j / RING);
float a1 = (float) (2.0 * Math.PI * (j + 1) / RING);
Vec3 d0 = computeRingDir(N, B, a0);
Vec3 d1 = computeRingDir(N1, B1, a0);
Vec3 d0b = computeRingDir(N, B, a1);
Vec3 d1b = computeRingDir(N1, B1, a1);
Vec3 v0 = P.add(d0.scale(r0));
Vec3 v1 = P1.add(d1.scale(r1));
Vec3 v2 = P1.add(d1b.scale(r1));
Vec3 v3 = P.add(d0b.scale(r0));
for(int k = 0;k < 3;k++) {
writeVert(buffer, matrix, entityWorldPos, v0, 0.5f, 0.5f, alpha, colorR, colorG, colorB);
writeVert(buffer, matrix, entityWorldPos, v1, 0.5f, 0.5f, alpha, colorR, colorG, colorB);
writeVert(buffer, matrix, entityWorldPos, v2, 0.5f, 0.5f, alpha, colorR, colorG, colorB);
writeVert(buffer, matrix, entityWorldPos, v3, 0.5f, 0.5f, alpha, colorR, colorG, colorB);
}
}
}
}
public static Vec3 computeRingDir(Vec3 n, Vec3 b, float ang) {
return n.scale(Math.cos(ang)).add(b.scale(Math.sin(ang)));
}
public static void writeVert(VertexConsumer buffer, Matrix4f matrix, Vec3 entityWorldPos,
Vec3 worldPos, float u, float v, float alpha, float colorR, float colorG, float colorB) {
double lx = worldPos.x - entityWorldPos.x;
double ly = worldPos.y - entityWorldPos.y;
double lz = worldPos.z - entityWorldPos.z;
buffer.addVertex(matrix, (float)lx, (float)ly, (float)lz)
.setColor(colorR, colorG, colorB, alpha)
.setUv(u, v)
.setOverlay(OverlayTexture.NO_OVERLAY)
.setLight(LightTexture.FULL_BRIGHT)
.setNormal(0.0F, 1.0F, 0.0F);
}
}
@@ -0,0 +1,74 @@
package com.lzxnone.terraria.client.item.melee;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.projectile.StaticProjectile;
import com.lzxnone.terraria.utils.*;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.Vec3;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import com.lzxnone.terraria.client.entity.projectile.IStaticProjectileRenderBehavior;
public class ClientBladeOfGrass {
public static final IStaticProjectileRenderBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileRenderBehavior() {
public static final ResourceLocation RES = ResourceLocation.parse("lzxnoneterraria:textures/vfx/normal_trail.png");
public static final Vector3f TRAIL_COLOR = new Vector3f(0.271f, 0.486f, 0.016f);
public static final float TRAIL_ALPHA = 0.25f;
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticProjectile projectile)) return;
this.renderItem(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight);
Vec3 currentPos = projectile.getPosition(partialTick);
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucent(RES));
Matrix4f matrix = poseStack.last().pose();
int quadCount = projectile.trailPositions.size() / 2 - 1;
for(int i = 1; i < quadCount;i++) {
Vec3 currentPoint1 = projectile.trailPositions.get(i * 2);
Vec3 currentPoint2 = projectile.trailPositions.get(i * 2 + 1);
Vec3 nextPoint1 = projectile.trailPositions.get(i * 2 + 3);
Vec3 nextPoint2 = projectile.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 radio1 = (float) i / quadCount;
float radio2 = (float) (i + 1) / quadCount;
vertexConsumer.addVertex(matrix, (float)x1, (float)y1, (float)z1)
.setColor(TRAIL_COLOR.x, TRAIL_COLOR.y, TRAIL_COLOR.z, TRAIL_ALPHA).setUv(radio1, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(matrix, (float)x2, (float)y2, (float)z2)
.setColor(TRAIL_COLOR.x, TRAIL_COLOR.y, TRAIL_COLOR.z, TRAIL_ALPHA).setUv(radio1, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(matrix, (float)x3, (float)y3, (float)z3)
.setColor(TRAIL_COLOR.x, TRAIL_COLOR.y, TRAIL_COLOR.z, TRAIL_ALPHA).setUv(radio2, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(matrix, (float)x4, (float)y4, (float)z4)
.setColor(TRAIL_COLOR.x, TRAIL_COLOR.y, TRAIL_COLOR.z, TRAIL_ALPHA).setUv(radio2, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
}
}
};
}
@@ -0,0 +1,553 @@
package com.lzxnone.terraria.client.item.melee;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.projectile.StaticProjectile;
import com.lzxnone.terraria.entity.summon.StaticSummon;
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.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.nbt.CompoundTag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.*;
import net.minecraft.world.phys.Vec3;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import net.minecraft.client.Camera;
import java.util.*;
import com.lzxnone.terraria.client.entity.projectile.IStaticProjectileRenderBehavior;
import com.lzxnone.terraria.client.entity.summon.IStaticSummonRenderBehavior;
import static com.lzxnone.terraria.item.weapon.melee.DevilsDevastation.*;
public class ClientDevilsDevastation {
public static final IStaticProjectileRenderBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileRenderBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticProjectile projectile)) return;
renderItem(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight);
VertexConsumer buffer = bufferSource.getBuffer(ModRenderTypes.entityAdditiveEmissive(RES));
Vec3 entWorldPos = new Vec3(
Mth.lerp(partialTick, projectile.xo, projectile.getX()),
Mth.lerp(partialTick, projectile.yo, projectile.getY()),
Mth.lerp(partialTick, projectile.zo, projectile.getZ())
);
Matrix4f matrix = poseStack.last().pose();
renderTube(buffer, matrix, entWorldPos, projectile.trailPositions, PROJECTILE_TRAIL_RADIUS * 1.0F, 1.0f, 1,1,1, true);
renderTube(buffer, matrix, entWorldPos, projectile.trailPositions, PROJECTILE_TRAIL_RADIUS * 1.25F, 1.0f * 0.5F, 0.7F,0.15F,0.55F, true);
renderTube(buffer, matrix, entWorldPos, projectile.trailPositions, PROJECTILE_TRAIL_RADIUS * 1.5F, 1.0f * 0.2F, 0.5F,0.1F,0.4F, true);
renderTube(buffer, matrix, entWorldPos, projectile.trailPositions2, PROJECTILE_TRAIL_RADIUS * 1.0F, 1.0f, 1,1,1, true);
renderTube(buffer, matrix, entWorldPos, projectile.trailPositions2, PROJECTILE_TRAIL_RADIUS * 1.25F, 1.0f * 0.5F, 0.7F,0.15F,0.55F, true);
renderTube(buffer, matrix, entWorldPos, projectile.trailPositions2, PROJECTILE_TRAIL_RADIUS * 1.5F, 1.0f * 0.2F, 0.5F,0.1F,0.4F, true);
}
};
public static final IStaticProjectileRenderBehavior PROJECTILE_BEHAVIOR2 = new IStaticProjectileRenderBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticProjectile projectile)) return;
ItemStack stack = projectile.getEntityData().get(StaticProjectile.ITEM);
if(stack.isEmpty()) return;
float scaleX = 0.05f;
float scaleY = 0.05f;
float scaleZ = 0.05f;
float age = projectile.getEntityData().get(StaticProjectile.AGE) + partialTick;
Vector3f dir = projectile.getEntityData().get(StaticProjectile.DIRECTION);
Vector3f up = projectile.getEntityData().get(StaticProjectile.UP);
int rotate = projectile.getEntityData().get(StaticProjectile.RZP);
poseStack.pushPose();
RenderUtil.applyRotate(poseStack, dir, up, age * 30 + 60, rotate);
poseStack.scale(4.0f, 4.0f, 4.0f);
Minecraft.getInstance().getItemRenderer().renderStatic(
stack,
ItemDisplayContext.NONE,
LightTexture.FULL_BRIGHT,
OverlayTexture.NO_OVERLAY,
poseStack,
bufferSource,
entity.level(),
0
);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyRotate(poseStack, dir, up, age * 30 + 180, rotate);
poseStack.scale(scaleX, scaleY, scaleZ);
VertexConsumer buffer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES2));
RenderUtil.renderQuad(poseStack.last().pose(), buffer0, 0.729f, 0.396f, 0.345f, 1.0f, 78, 78, 0, 0, 0);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyRotate(poseStack, dir, up, age * 30, rotate);
poseStack.scale(scaleX, scaleY, scaleZ);
VertexConsumer buffer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES3));
RenderUtil.renderQuad(poseStack.last().pose(), buffer1, 0.8f, 0.176f, 0.78f, 1.0f, 78, 78, 0, 0, 0);
poseStack.popPose();
}
};
public static final IStaticProjectileRenderBehavior PROJECTILE_BEHAVIOR3 = new IStaticProjectileRenderBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticProjectile projectile)) return;
ItemStack itemStack = projectile.getEntityData().get(StaticProjectile.ITEM);
if(itemStack == ItemStack.EMPTY) return;
CompoundTag customData = projectile.getEntityData().get(StaticProjectile.CUSTOM_DATA);
if(!customData.contains("w")) return;
float w = customData.getFloat("w");
float t = projectile.getEntityData().get(StaticProjectile.AGE) + partialTick;
Vec3 dir = MathUtil.toVec3(projectile.getEntityData().get(StaticProjectile.DIRECTION)).normalize();
Vec3 up = MathUtil.toVec3(projectile.getEntityData().get(StaticProjectile.UP)).normalize();
Quaternionf rotationDir = new Quaternionf()
.fromAxisAngleRad(dir.toVector3f(), (float) Math.toRadians(projectile.getEntityData().get(StaticProjectile.RZP)));
Quaternionf rotationUp;
Quaternionf rotationUp2;
if(w > 0) {
rotationUp = new Quaternionf().fromAxisAngleRad(up.toVector3f(), (float) Math.PI - w * t);
rotationUp2 = new Quaternionf().fromAxisAngleRad(up.toVector3f(), (float) Math.PI * 0.75f - w * t);
}else {
rotationUp = new Quaternionf().fromAxisAngleRad(up.toVector3f(), (float) -Math.PI - w * t);
rotationUp2 = new Quaternionf().fromAxisAngleRad(up.toVector3f(), (float) -Math.PI * 1.25f - w * t);
}
float[] xyRot = MathUtil.computeXYRot(dir.toVector3f(), up.toVector3f());
poseStack.pushPose();
//旋转
poseStack.mulPose(rotationUp);
poseStack.mulPose(rotationDir);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.XP.rotationDegrees(-90));
poseStack.mulPose(Axis.ZP.rotationDegrees(-135));
//缩放
poseStack.scale(4.0f, 4.0f, 4.0f);
Minecraft.getInstance().getItemRenderer().renderStatic(
itemStack,
ItemDisplayContext.NONE,
LightTexture.FULL_BRIGHT,
OverlayTexture.NO_OVERLAY,
poseStack,
bufferSource,
entity.level(),
0
);
poseStack.popPose();
poseStack.pushPose();
Vector3f tipDir = dir.toVector3f().rotate(rotationUp);
poseStack.translate(-tipDir.x * 2, -tipDir.y * 2, -tipDir.z * 2);
poseStack.translate(-up.x * 0.5, -up.y * 0.5, -up.z * 0.5);
poseStack.mulPose(rotationUp2);
poseStack.mulPose(rotationDir);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.XP.rotationDegrees(-90));
poseStack.mulPose(Axis.ZP.rotationDegrees(-135));
renderEnergyWave(bufferSource, poseStack, projectile);
poseStack.popPose();
float radio = t / projectile.getEntityData().get(StaticProjectile.LIFETIME);
float alpha = 1.0f - radio;
if(alpha > 0.001f) {
poseStack.pushPose();
poseStack.mulPose(rotationUp);
poseStack.mulPose(rotationDir);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.XP.rotationDegrees(-90));
if(w > 0) poseStack.mulPose(Axis.ZP.rotationDegrees(-105));
else poseStack.mulPose(Axis.ZP.rotationDegrees(75));
float halfWidth = 78;
float halfHeight = 78;
VertexConsumer consumer = bufferSource.getBuffer(ModRenderTypes.entityAdditiveEmissive(RES5));
Vector3f[] sizes = new Vector3f[]{
new Vector3f(0.2f, 0.2f, 0.2f),
new Vector3f(0.3f, 0.3f, 0.3f),
new Vector3f(0.4f, 0.4f, 0.4f),
};
Vector3f[] colors = new Vector3f[]{
new Vector3f(0.725f, 0.345f, 1.0f),
new Vector3f(0.847f, 0.247f, 0.745f),
new Vector3f(0.882f, 0.345f, 0.247f),
};
for(int i = 0;i < 3;i++) {
poseStack.pushPose();
poseStack.scale(sizes[i].x, sizes[i].y, sizes[i].z);
for(int j = 0;j < 3;j++) {
consumer.addVertex(poseStack.last().pose(), -halfWidth, halfHeight, 0.01f * i)
.setColor(colors[i].x, colors[i].y, colors[i].z, alpha).setUv(0.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
consumer.addVertex(poseStack.last().pose(), -halfWidth, -halfHeight, 0.01f * i)
.setColor(colors[i].x, colors[i].y, colors[i].z, alpha).setUv(0.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
consumer.addVertex(poseStack.last().pose(), halfWidth, -halfHeight, 0.01f * i)
.setColor(colors[i].x, colors[i].y, colors[i].z, alpha).setUv(1.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
consumer.addVertex(poseStack.last().pose(), halfWidth, halfHeight, 0.01f * i)
.setColor(colors[i].x, colors[i].y, colors[i].z, alpha).setUv(1.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
}
poseStack.popPose();
}
poseStack.popPose();
}
}
};
public static final IStaticSummonRenderBehavior SUMMON_BEHAVIOR2 = new IStaticSummonRenderBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon)) return;
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
if(!customData.contains("dirX") || !customData.contains("dirY") || !customData.contains("dirZ") || !customData.contains("seed")) return;
Vec3 dir = new Vec3(customData.getDouble("dirX"), customData.getDouble("dirY"), customData.getDouble("dirZ")).normalize();
long seed = customData.getLong("seed");
int age = summon.getEntityData().get(StaticSummon.AGE);
int lifetime = summon.getEntityData().get(StaticSummon.LIFETIME);
if(lifetime <= 0) return;
float lifeRatio = Mth.clamp((age + partialTick) / (float) lifetime, 0.0F, 1.0F);
if(lifeRatio > 0.999f) return;
float radius = PROJECTILE_HIT_LIGHTNING_RADIUS * (1.0f - lifeRatio);
float alpha = 1.0f - lifeRatio;
Vec3 entWorldPos = new Vec3(
Mth.lerp(partialTick, summon.xo, summon.getX()),
Mth.lerp(partialTick, summon.yo, summon.getY()),
Mth.lerp(partialTick, summon.zo, summon.getZ())
);
VertexConsumer buffer = bufferSource.getBuffer(ModRenderTypes.entityAdditiveEmissive(RES));
Matrix4f matrix = poseStack.last().pose();
Random rand0 = new Random(seed);
Vec3 start0 = entWorldPos.add(dir.scale(4.0));
Vec3 end0 = start0.add(dir.scale(PROJECTILE_HIT_LIGHTNING_LENGTH));
List<Vec3> branch0 = generateBranch(start0, end0, rand0, PROJECTILE_HIT_LIGHTNING_DEPTH, PROJECTILE_HIT_LIGHTNING_JITTER);
Random rand1 = new Random(seed + 1);
Vec3 end1 = start0.add(spreadDir(dir, rand1, 0.4F).scale(PROJECTILE_HIT_LIGHTNING_LENGTH * 0.7F));
List<Vec3> branch1 = generateBranch(start0, end1, rand1, PROJECTILE_HIT_LIGHTNING_DEPTH, PROJECTILE_HIT_LIGHTNING_JITTER);
Random rand2 = new Random(seed + 2);
Vec3 start2 = branch0.get(1);
Vec3 end2 = start2.add(spreadDir(dir, rand2, 0.4F).scale(PROJECTILE_HIT_LIGHTNING_LENGTH * 0.5F));
List<Vec3> branch2 = generateBranch(start2, end2, rand2, PROJECTILE_HIT_LIGHTNING_DEPTH, PROJECTILE_HIT_LIGHTNING_JITTER);
for(List<Vec3> branch : List.of(branch0, branch1, branch2)) {
renderTube(buffer, matrix, entWorldPos, branch, radius * 1.0F, alpha, 1,1,1, true);
renderTube(buffer, matrix, entWorldPos, branch, radius * 1.25F, alpha * 0.5F, 0.7F,0.15F,0.55F, true);
renderTube(buffer, matrix, entWorldPos, branch, radius * 0.75F, alpha * 0.2F, 0.5F,0.1F,0.4F, true);
}
}
};
public static final IStaticSummonRenderBehavior SUMMON_BEHAVIOR3 = new IStaticSummonRenderBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon)) return;
Vec3 entWorldPos = new Vec3(
Mth.lerp(partialTick, entity.xo, entity.getX()),
Mth.lerp(partialTick, entity.yo, entity.getY()),
Mth.lerp(partialTick, entity.zo, entity.getZ())
);
// 公告板:根据相机计算平面基向量
Camera camera = Minecraft.getInstance().gameRenderer.getMainCamera();
Vec3 toCamera = camera.getPosition().subtract(entWorldPos).normalize();
Vec3 up = new Vec3(0, 1, 0);
Vec3 right = toCamera.cross(up).normalize();
if(right.lengthSqr() < 0.01) right = new Vec3(1, 0, 0);
Vec3 realUp = right.cross(toCamera).normalize();
// 十字交叉的4个方向
Vec3[] dirs = {
realUp.add(right).normalize(),
realUp.subtract(right).normalize(),
realUp.scale(-1.0).add(right).normalize(),
realUp.scale(-1.0).subtract(right).normalize()
};
float age = summon.getEntityData().get(StaticSummon.AGE) + partialTick;
float lifetime = summon.getEntityData().get(StaticSummon.LIFETIME);
float progress = age / lifetime;
float alpha = 1.0f;
float length = MARK_LENGTH + progress * MARK_LENGTH * 2;
float radius = MARK_RADIUS + progress * MARK_RADIUS * 2;
VertexConsumer buffer = bufferSource.getBuffer(ModRenderTypes.entityAdditiveEmissive(RES));
Matrix4f matrix = poseStack.last().pose();
for(Vec3 dir : dirs) {
List<Vec3> points = new ArrayList<>();
points.add(entWorldPos);
points.add(entWorldPos.add(dir.scale(length)));
renderTube(buffer, matrix, entWorldPos, points, radius * 0.5f, alpha * 0.8f, 1.0f, 1.0f, 1.0f, true);
renderTube(buffer, matrix, entWorldPos, points, radius, alpha, 0.8f, 0.176f, 0.78f, true);
}
}
};
public static final IStaticSummonRenderBehavior SUMMON_BEHAVIOR4 = new IStaticSummonRenderBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon)) return;
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
if(!customData.contains("seed")) return;
long seed = customData.getLong("seed");
int ageInt = summon.getEntityData().get(StaticSummon.AGE);
int lifetime = summon.getEntityData().get(StaticSummon.LIFETIME);
if(lifetime <= 0) return;
float lifeRatio = Mth.clamp((ageInt + partialTick) / (float) lifetime, 0.0F, 1.0F);
float lengthScale = Math.min(1.0F, lifeRatio * 2.0F);
float length = MARK_LIGHTNING_LENGTH * lengthScale;
if(length < 0.5F) return;
float radius = MARK_LIGHTNING_RADIUS * (1.0F - lifeRatio);
float alpha = 1.0F - lifeRatio;
Vec3 entWorldPos = new Vec3(
Mth.lerp(partialTick, summon.xo, summon.getX()),
Mth.lerp(partialTick, summon.yo, summon.getY()),
Mth.lerp(partialTick, summon.zo, summon.getZ())
);
VertexConsumer buffer = bufferSource.getBuffer(ModRenderTypes.entityAdditiveEmissive(RES));
Matrix4f matrix = poseStack.last().pose();
Random rand = new Random(seed);
float baseAngle = rand.nextFloat() * (float)Math.PI * 2;
Vec3[] dirs = {
new Vec3(Math.cos(baseAngle), 0, Math.sin(baseAngle)),
new Vec3(Math.cos(baseAngle + Math.PI / 2), 0, Math.sin(baseAngle + Math.PI / 2)),
new Vec3(Math.cos(baseAngle + Math.PI), 0, Math.sin(baseAngle + Math.PI)),
new Vec3(Math.cos(baseAngle + Math.PI * 3 / 2), 0, Math.sin(baseAngle + Math.PI * 3 / 2))
};
for(int d = 0; d < 4; d++) {
Random mainRand = new Random(seed + d);
Vec3 dir = dirs[d];
Vec3 start = entWorldPos;
Vec3 end = start.add(dir.scale(length));
List<Vec3> mainBranch = generateBranch(start, end, mainRand, MARK_LIGHTNING_DEPTH, MARK_LIGHTNING_JITTER);
renderTube(buffer, matrix, entWorldPos, mainBranch, radius, alpha, 0.8f, 0.176f, 0.78f, true);
renderTube(buffer, matrix, entWorldPos, mainBranch, radius * 0.5f, alpha * 0.8f, 1.0f, 1.0f, 1.0f, true);
for(int s = 0; s < MARK_LIGHTNING_SUB_COUNT; s++) {
Random subRand = new Random(seed + d * 10 + s);
int idx = subRand.nextInt(mainBranch.size());
Vec3 branchPos = mainBranch.get(idx);
Vec3 subEnd = branchPos.add(spreadDir(dir, subRand, MARK_LIGHTNING_SUB_SPREAD).scale(length * MARK_LIGHTNING_SUB_LENGTH));
List<Vec3> subBranch = generateBranch(branchPos, subEnd, subRand, MARK_LIGHTNING_DEPTH, MARK_LIGHTNING_JITTER);
renderTube(buffer, matrix, entWorldPos, subBranch, radius, alpha, 0.8f, 0.176f, 0.78f, true);
renderTube(buffer, matrix, entWorldPos, subBranch, radius * 0.5f, alpha * 0.8f, 1.0f, 1.0f, 1.0f, true);
}
}
}
};
public static void renderTube(VertexConsumer buffer, Matrix4f matrix, Vec3 entityWorldPos,
List<Vec3> points, float radius, float alpha, float colorR, float colorG, float colorB, boolean linear) {
int n = points.size();
if(n < 2) return;
Vector3f[][] oriDirs = new Vector3f[n][3];
Vec3[] up = new Vec3[n], right = new Vec3[n];
for(int i = 0;i < n;i++) {
if(i == n - 1) oriDirs[i] = MathUtil.computeCoordinateSystem(points.get(n - 1).subtract(points.get(n - 2)).toVector3f(), 0);
else oriDirs[i] = MathUtil.computeCoordinateSystem(points.get(i + 1).subtract(points.get(i)).toVector3f(), 0);
up[i] = MathUtil.toVec3(oriDirs[i][1]);
right[i] = MathUtil.toVec3(oriDirs[i][2]);
}
for(int i = 0;i < n - 1;i++) {
float r0 = linear ? radius * (1.0F - (float) i / (float) (n - 1)) : radius;
float r1 = linear ? radius * (1.0F - (float) (i + 1) / (float) (n - 1)) : radius;
if(r0 <= 0.001F && r1 <= 0.001F) continue;
Vec3 N = right[i], B = up[i], N1 = right[i + 1], B1 = up[i + 1];
Vec3 P = points.get(i), P1 = points.get(i + 1);
for(int j = 0;j < RING;j++) {
float a0 = (float) (2.0 * Math.PI * j / RING);
float a1 = (float) (2.0 * Math.PI * (j + 1) / RING);
Vec3 d0 = computeRingDir(N, B, a0);
Vec3 d1 = computeRingDir(N1, B1, a0);
Vec3 d0b = computeRingDir(N, B, a1);
Vec3 d1b = computeRingDir(N1, B1, a1);
Vec3 v0 = P.add(d0.scale(r0));
Vec3 v1 = P1.add(d1.scale(r1));
Vec3 v2 = P1.add(d1b.scale(r1));
Vec3 v3 = P.add(d0b.scale(r0));
for(int k = 0;k < 3;k++) {
writeVert(buffer, matrix, entityWorldPos, v0, 0.5f, 0.5f, alpha, colorR, colorG, colorB);
writeVert(buffer, matrix, entityWorldPos, v1, 0.5f, 0.5f, alpha, colorR, colorG, colorB);
writeVert(buffer, matrix, entityWorldPos, v2, 0.5f, 0.5f, alpha, colorR, colorG, colorB);
writeVert(buffer, matrix, entityWorldPos, v3, 0.5f, 0.5f, alpha, colorR, colorG, colorB);
}
}
}
}
public static void renderTubeSegmented(VertexConsumer buffer, Matrix4f matrix, Vec3 entityWorldPos,
List<Vec3> points, float[] radii,
Vector3f[] colors, float alpha,
float uvOffsetU, float uvOffsetV, float uvScaleU, float uvScaleV) {
int n = points.size();
if(n < 2 || radii.length < n || colors.length < n) return;
Vector3f[][] oriDirs = new Vector3f[n][3];
Vec3[] up = new Vec3[n], right = new Vec3[n];
for(int i = 0;i < n;i++) {
if(i == n - 1) oriDirs[i] = MathUtil.computeCoordinateSystem(points.get(n - 1).subtract(points.get(n - 2)).toVector3f(), 0);
else oriDirs[i] = MathUtil.computeCoordinateSystem(points.get(i + 1).subtract(points.get(i)).toVector3f(), 0);
up[i] = MathUtil.toVec3(oriDirs[i][1]);
right[i] = MathUtil.toVec3(oriDirs[i][2]);
}
for(int i = 0;i < n - 1;i++) {
float r0 = radii[i];
float r1 = radii[i + 1];
if(r0 <= 0.001F && r1 <= 0.001F) continue;
Vec3 N = right[i], B = up[i], N1 = right[i + 1], B1 = up[i + 1];
Vec3 P = points.get(i), P1 = points.get(i + 1);
Vector3f c0 = colors[i], c1 = colors[i + 1];
float u0 = uvOffsetU + uvScaleU * ((float)i / (float)(n - 1));
float u1 = uvOffsetU + uvScaleU * ((float)(i + 1) / (float)(n - 1));
for(int j = 0;j < RING;j++) {
float a0 = (float) (2.0 * Math.PI * j / RING);
float a1 = (float) (2.0 * Math.PI * (j + 1) / RING);
float v0 = (float) j / (float)RING + uvOffsetV;
float v1 = (float) (j + 1) / (float)RING + uvOffsetV;
Vec3 d0 = computeRingDir(N, B, a0);
Vec3 d1 = computeRingDir(N1, B1, a0);
Vec3 d0b = computeRingDir(N, B, a1);
Vec3 d1b = computeRingDir(N1, B1, a1);
Vec3 v00 = P.add(d0.scale(r0));
Vec3 v01 = P1.add(d1.scale(r1));
Vec3 v02 = P1.add(d1b.scale(r1));
Vec3 v03 = P.add(d0b.scale(r0));
for(int k = 0;k < 10;k++) {
writeVert(buffer, matrix, entityWorldPos, v00, u0, v0, alpha, c0.x(), c0.y(), c0.z());
writeVert(buffer, matrix, entityWorldPos, v01, u1, v0, alpha, c1.x(), c1.y(), c1.z());
writeVert(buffer, matrix, entityWorldPos, v02, u1, v1, alpha, c1.x(), c1.y(), c1.z());
writeVert(buffer, matrix, entityWorldPos, v03, u0, v1, alpha, c0.x(), c0.y(), c0.z());
}
}
}
}
public static Vec3 computeRingDir(Vec3 n, Vec3 b, float ang) {
return n.scale(Math.cos(ang)).add(b.scale(Math.sin(ang)));
}
public static void writeVert(VertexConsumer buffer, Matrix4f matrix, Vec3 entityWorldPos,
Vec3 worldPos, float u, float v, float alpha, float colorR, float colorG, float colorB) {
double lx = worldPos.x - entityWorldPos.x;
double ly = worldPos.y - entityWorldPos.y;
double lz = worldPos.z - entityWorldPos.z;
buffer.addVertex(matrix, (float)lx, (float)ly, (float)lz)
.setColor(colorR, colorG, colorB, alpha)
.setUv(u, v)
.setOverlay(OverlayTexture.NO_OVERLAY)
.setLight(LightTexture.FULL_BRIGHT)
.setNormal(0.0F, 1.0F, 0.0F);
}
public static void renderEnergyWave(MultiBufferSource buffer, PoseStack poseStack, Entity entity) {
Matrix4f matrix = poseStack.last().pose();
int time = entity.tickCount;
poseStack.translate(0, 1.4, 0.6);
float baseRadius = 1.0f;
float speed = 0.25f;
Vector3f colorA = new Vector3f(0.729f, 0.396f, 0.345f);
Vector3f colorB = new Vector3f(0.8f, 0.176f, 0.78f);
List<Vec3> points = new ArrayList<>();
float[] outRadius = new float[ENERGY_WAVE_SEG + 1];
Vector3f[] outColors = new Vector3f[ENERGY_WAVE_SEG + 1];
for(int i = 0; i <= ENERGY_WAVE_SEG; i++) {
float t = (float) i / ENERGY_WAVE_SEG;
float y = t * ENERGY_WAVE_LENGTH;
float phase = time * speed * 6f - t * (float) Math.PI * 5;
float wave = (float) Math.sin(phase);
points.add(new Vec3(0, y, 0));
float taper = (float) Math.cos(t * Math.PI * 0.5f);
float pulse = 0.7f + 0.3f * (0.5f + 0.5f * wave);
outRadius[i] = baseRadius * taper * pulse;
float blend = 0.5f + 0.5f * (float) Math.sin(time * 0.3f * speed - t * (float) Math.PI * 2);
outColors[i] = new Vector3f(
colorA.x + (colorB.x - colorA.x) * blend,
colorA.y + (colorB.y - colorA.y) * blend,
colorA.z + (colorB.z - colorA.z) * blend
);
}
float[] inRadius = new float[ENERGY_WAVE_SEG + 1];
Vector3f[] inColors = new Vector3f[ENERGY_WAVE_SEG + 1];
for(int i = 0; i <= ENERGY_WAVE_SEG; i++) {
inRadius[i] = outRadius[i] * 0.1f;
inColors[i] = new Vector3f(1.0f, 1.0f, 1.0f);
}
VertexConsumer consumer2 = buffer.getBuffer(ModRenderTypes.entityAdditiveEmissive(RES));
renderTubeSegmented(consumer2, matrix, new Vec3(0, 0, 0), points, inRadius, inColors, 1.0f,
0, 0, 1.0f, 0.0f);
float uOffset = time * 0.125f;
float vOffset = time * 0.125f;
VertexConsumer consumer = buffer.getBuffer(ModRenderTypes.entityAdditiveEmissive(RES4));
for(int i = 0;i < 1;i++) {
renderTubeSegmented(consumer, matrix, new Vec3(0, 0, 0), points, outRadius, outColors, 1.0f,
uOffset, 0 + vOffset, 2.0f, 0.0f);
renderTubeSegmented(consumer, matrix, new Vec3(0, 0, 0), points, outRadius, outColors, 1.0f,
uOffset, 0.5f + vOffset, 2.0f, 0.0f);
}
}
}
@@ -0,0 +1,224 @@
package com.lzxnone.terraria.client.item.melee;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.TintedVertexConsumer;
import com.lzxnone.terraria.entity.summon.*;
import com.lzxnone.terraria.network.SkinFetch;
import com.lzxnone.terraria.utils.*;
import com.mojang.authlib.GameProfile;
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.model.PlayerModel;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.resources.PlayerSkin;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FastColor;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import org.joml.Vector3f;
import java.util.UUID;
import com.lzxnone.terraria.client.entity.summon.IStaticSummonRenderBehavior;
import com.lzxnone.terraria.client.entity.summon.StaticSummonRenderer;
public class ClientFirstFractal {
public static final IStaticSummonRenderBehavior SUMMON_BEHAVIOR = new IStaticSummonRenderBehavior() {
public static final ResourceLocation RES = ResourceLocation.parse("lzxnoneterraria:textures/vfx/beam_sparkle.png");
public static final ResourceLocation RES2 = ResourceLocation.parse("lzxnoneterraria:textures/vfx/first_fractal_star.png");
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon)) return;
UUID uuid = summon.getEntityData().get(StaticSummon.OWNER).orElse(null);
if(uuid == null) return;
ItemStack item = summon.getEntityData().get(StaticSummon.ITEM);
if(item == ItemStack.EMPTY) return;
GameProfile profile = SkinFetch.getCachedProfile(uuid);
PlayerSkin playerSkin = Minecraft.getInstance().getSkinManager().getInsecureSkin(profile);
boolean isSlim = playerSkin.model() == PlayerSkin.Model.SLIM;
PlayerModel<LivingEntity> activeModel = isSlim ? StaticSummonRenderer.getSlimModel() : StaticSummonRenderer.getWideModel();
activeModel.rightArm.resetPose();
activeModel.leftArm.resetPose();
activeModel.rightLeg.resetPose();
activeModel.leftLeg.resetPose();
activeModel.rightSleeve.resetPose();
activeModel.leftSleeve.resetPose();
activeModel.rightPants.resetPose();
activeModel.leftPants.resetPose();
activeModel.young = false;
//确定模型方向
activeModel.rightArm.xRot = (float) Math.toRadians(-90);
activeModel.leftArm.xRot = (float) Math.toRadians(-90);
activeModel.rightArm.yRot = (float) Math.toRadians(-30);
activeModel.leftArm.yRot = (float) Math.toRadians(30);
activeModel.rightLeg.xRot = (float) Math.toRadians(-30);
activeModel.leftLeg.xRot = (float) Math.toRadians(30);
activeModel.rightSleeve.xRot = activeModel.rightArm.xRot;
activeModel.rightSleeve.yRot = activeModel.rightArm.yRot;
activeModel.leftSleeve.xRot = activeModel.leftArm.xRot;
activeModel.leftSleeve.yRot = activeModel.leftArm.yRot;
activeModel.rightPants.xRot = activeModel.rightLeg.xRot;
activeModel.leftPants.xRot = activeModel.leftLeg.xRot;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(summon.getLookAngle().toVector3f(), 0);
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
Vector3f color = new Vector3f(
summon.getEntityData().get(StaticSummon.COLOR_R),
summon.getEntityData().get(StaticSummon.COLOR_G),
summon.getEntityData().get(StaticSummon.COLOR_B)
);
float radio = (float) (summon.getEntityData().get(StaticSummon.AGE) + partialTick) / (float) summon.getEntityData().get(StaticSummon.LIFETIME);
float alpha;
if(radio < 0.25f) {
alpha = radio / 0.25f;
}else if(radio > 0.75f) {
alpha = 1.0f - (radio - 0.75f) / 0.25f;
}else {
alpha = 1.0f;
}
if(alpha < 0.001f) return;
//流星
poseStack.pushPose();
float starHalfWidth = 45 * 0.06f;
float starHalfHeight = 17 * 0.06f;
VertexConsumer starConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES2));
poseStack.translate(
dirs[0].x * 0 + dirs[1].x * 1.3,
dirs[0].y * 0 + dirs[1].y * 1.3,
dirs[0].z * 0 + dirs[1].z * 1.3
);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.YP.rotationDegrees(270));
poseStack.scale(0.75f + alpha * 0.25f, 0.75f + alpha * 0.25f , 0.75f + alpha * 0.25f);
for(int i = 0; i < 3; i++) {
starConsumer.addVertex(poseStack.last().pose(), -starHalfWidth, -starHalfHeight, 0f)
.setColor(color.x, color.y, color.z, alpha * 0.5f).setUv(0.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
starConsumer.addVertex(poseStack.last().pose(), starHalfWidth, -starHalfHeight, 0f)
.setColor(color.x, color.y, color.z, alpha * 0.5f).setUv(1.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
starConsumer.addVertex(poseStack.last().pose(), starHalfWidth, starHalfHeight, 0f)
.setColor(color.x, color.y, color.z, alpha * 0.5f).setUv(1.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
starConsumer.addVertex(poseStack.last().pose(), -starHalfWidth, starHalfHeight, 0f)
.setColor(color.x, color.y, color.z, alpha * 0.5f).setUv(0.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
}
poseStack.popPose();
//闪烁
poseStack.pushPose();
float sparkleHalfWidth = 32 * 0.12f;
float sparkleHalfHeight = 32 * 0.03f;
VertexConsumer sparkleConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES));
poseStack.translate(
dirs[0].x * 2 + dirs[1].x * 1.3,
dirs[0].y * 2 + dirs[1].y * 1.3,
dirs[0].z * 2 + dirs[1].z * 1.3
);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.YP.rotationDegrees(270));
poseStack.scale(alpha, alpha , alpha);
for(int i = 0; i < 3; i++) {
sparkleConsumer.addVertex(poseStack.last().pose(), -sparkleHalfWidth, -sparkleHalfHeight, 0.01f)
.setColor(color.x, color.y, color.z, alpha).setUv(0.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
sparkleConsumer.addVertex(poseStack.last().pose(), sparkleHalfWidth, -sparkleHalfHeight, 0.01f)
.setColor(color.x, color.y, color.z, alpha).setUv(1.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
sparkleConsumer.addVertex(poseStack.last().pose(), sparkleHalfWidth, sparkleHalfHeight, 0.01f)
.setColor(color.x, color.y, color.z, alpha).setUv(1.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
sparkleConsumer.addVertex(poseStack.last().pose(), -sparkleHalfWidth, sparkleHalfHeight, 0.01f)
.setColor(color.x, color.y, color.z, alpha).setUv(0.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
}
poseStack.popPose();
//剑
poseStack.pushPose();
poseStack.translate(
dirs[0].x * 2.2 + dirs[1].x * 1.5,
dirs[0].y * 2.2 + dirs[1].y * 1.5,
dirs[0].z * 2.2 + dirs[1].z * 1.5
);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.YP.rotationDegrees(270));
poseStack.mulPose(Axis.ZP.rotationDegrees(-45));
poseStack.scale(4.0f, 4.0f , 4.0f);
Minecraft.getInstance().getItemRenderer().renderStatic(
item,
ItemDisplayContext.NONE,
LightTexture.FULL_BRIGHT,
OverlayTexture.NO_OVERLAY,
poseStack,
renderType -> {
VertexConsumer vertexConsumer = bufferSource.getBuffer(renderType);
return new TintedVertexConsumer(vertexConsumer, 1.0f, 1.0f, 1.0f, alpha);
},
summon.level(),
0
);
poseStack.popPose();
//模型
poseStack.pushPose();
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.YP.rotationDegrees(180));
poseStack.scale(-1.0F, -1.0F, 1.0F);
poseStack.translate(0.0F, -1.501F, 0.0F);
VertexConsumer modelConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucent(playerSkin.texture()));
int packedColor = FastColor.ARGB32.color(Math.min((int)(alpha * 255), 255), 255, 255, 255);
activeModel.renderToBuffer(poseStack, modelConsumer, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, packedColor);
poseStack.popPose();
//恢复模型
activeModel.rightArm.resetPose();
activeModel.leftArm.resetPose();
activeModel.rightLeg.resetPose();
activeModel.leftLeg.resetPose();
activeModel.rightSleeve.resetPose();
activeModel.leftSleeve.resetPose();
activeModel.rightPants.resetPose();
activeModel.leftPants.resetPose();
activeModel.young = false;
}
};
}
@@ -0,0 +1,59 @@
package com.lzxnone.terraria.client.item.melee;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.summon.StaticSummon;
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.nbt.CompoundTag;
import net.minecraft.world.entity.Entity;
import org.joml.Matrix4f;
import com.lzxnone.terraria.client.entity.summon.IStaticSummonRenderBehavior;
import static com.lzxnone.terraria.item.weapon.melee.LightsBane.*;
public class ClientLightsBane {
public static final IStaticSummonRenderBehavior SUMMON_BEHAVIOR = new IStaticSummonRenderBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick,
PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon)) return;
float lifeRatio = (summon.getEntityData().get(StaticSummon.AGE) + partialTick) / summon.getEntityData().get(StaticSummon.LIFETIME);
if(lifeRatio > 1.0f) return;
int frame = Math.min((int) (lifeRatio * 12.0f), 11);
poseStack.pushPose();
poseStack.mulPose(Minecraft.getInstance().getEntityRenderDispatcher().cameraOrientation());
VertexConsumer consumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES[frame]));
Matrix4f matrix = poseStack.last().pose();
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
float scale;
if(customData.contains("big") && customData.getBoolean("big")) scale = SCALE_BIG;
else scale = SCALE_SMALL;
poseStack.mulPose(Axis.ZP.rotationDegrees(summon.getEntityData().get(StaticSummon.RZP)));
consumer.addVertex(matrix, -HALF_WIDTH * scale, -HALF_HEIGHT * scale, 0)
.setColor(255, 255, 255, 255).setUv(0.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
consumer.addVertex(matrix, HALF_WIDTH * scale, -HALF_HEIGHT * scale, 0)
.setColor(255, 255, 255, 255).setUv(1.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
consumer.addVertex(matrix, HALF_WIDTH * scale, HALF_HEIGHT * scale, 0)
.setColor(255, 255, 255, 255).setUv(1.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
consumer.addVertex(matrix, -HALF_WIDTH * scale, HALF_HEIGHT * scale, 0)
.setColor(255, 255, 255, 255).setUv(0.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
poseStack.popPose();
}
};
}
@@ -0,0 +1,235 @@
package com.lzxnone.terraria.client.item.melee;
import com.lzxnone.terraria.entity.projectile.StaticProjectile;
import com.lzxnone.terraria.entity.summon.StaticSummon;
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.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.*;
import net.minecraft.world.phys.*;
import org.joml.Vector3f;
import com.lzxnone.terraria.client.entity.projectile.IStaticProjectileRenderBehavior;
import com.lzxnone.terraria.client.entity.summon.IStaticSummonRenderBehavior;
import static com.lzxnone.terraria.item.weapon.melee.Mace.*;
public class ClientMace {
public static final IStaticProjectileRenderBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileRenderBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticProjectile projectile)) return;
if(projectile.getOwner() == null) return;
ItemStack itemStack = projectile.getEntityData().get(StaticProjectile.ITEM);
if(itemStack == ItemStack.EMPTY) return;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(projectile.getOwner());
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
poseStack.pushPose();
//旋转(方向修正)
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
Minecraft.getInstance().getItemRenderer().renderStatic(
itemStack,
ItemDisplayContext.NONE,
packedLight,
OverlayTexture.NO_OVERLAY,
poseStack,
bufferSource,
entity.level(),
0
);
poseStack.popPose();
poseStack.pushPose();
//旋转(方向修正)
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0] + 90));
Minecraft.getInstance().getItemRenderer().renderStatic(
itemStack,
ItemDisplayContext.NONE,
packedLight,
OverlayTexture.NO_OVERLAY,
poseStack,
bufferSource,
entity.level(),
0
);
poseStack.popPose();
if(projectile.getOwner() == null) return;
Vec3 eyePos = projectile.getOwner().getEyePosition();
Vec3 start = eyePos.add(new Vec3(
dirs[0].x * DIRECTION_OFFSET + dirs[1].x * UP_OFFSET + dirs[2].x * RIGHT_OFFSET,
dirs[0].y * DIRECTION_OFFSET + dirs[1].y * UP_OFFSET + dirs[2].y * RIGHT_OFFSET,
dirs[0].z * DIRECTION_OFFSET + dirs[1].z * UP_OFFSET + dirs[2].z * RIGHT_OFFSET
));
Vec3 end = projectile.getPosition(partialTick);
double dist = end.subtract(start).length();
Vector3f[] dirs2 = MathUtil.computeCoordinateSystem(end.subtract(start).toVector3f(), 0);
Vec3 dir = MathUtil.toVec3(dirs2[0]);
Vec3 right = MathUtil.toVec3(dirs2[2]);
Vec3 up = MathUtil.toVec3(dirs2[1]);
VertexConsumer vertexConsumer = bufferSource.getBuffer(RenderType.entityCutoutNoCull(RES));
int count = (int) (dist / CHAIN_LENGTH);
for(int j = 0;j < 2;j++) {
for(int i = 0; i < count; i++) {
Vec3 current = start.add(new Vec3(
dir.x * i * CHAIN_LENGTH,
dir.y * i * CHAIN_LENGTH,
dir.z * i * CHAIN_LENGTH
)).subtract(projectile.getPosition(partialTick));
Vec3 next = start.add(new Vec3(
dir.x * (i + 1) * CHAIN_LENGTH,
dir.y * (i + 1) * CHAIN_LENGTH,
dir.z * (i + 1) * CHAIN_LENGTH
)).subtract(projectile.getPosition(partialTick));
Vec3 p1, p2, p3, p4;
if(j == 0) {
p1 = current.add(right.scale(0.125));
p2 = current.add(right.scale(-0.125));
p3 = next.add(right.scale(-0.125));
p4 = next.add(right.scale(0.125));
}else {
p1 = current.add(up.scale(0.125));
p2 = current.add(up.scale(-0.125));
p3 = next.add(up.scale(-0.125));
p4 = next.add(up.scale(0.125));
}
vertexConsumer.addVertex(poseStack.last().pose(), (float) p1.x, (float) p1.y, (float) p1.z)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(0.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float) p2.x, (float) p2.y, (float) p2.z)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(0.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float) p3.x, (float) p3.y, (float) p3.z)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(1.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float) p4.x, (float) p4.y, (float) p4.z)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(1.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
}
}
}
};
public static final IStaticSummonRenderBehavior SUMMON_BEHAVIOR = new IStaticSummonRenderBehavior() {
@Override
public void render(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())));
Minecraft.getInstance().getItemRenderer().renderStatic(
itemStack,
ItemDisplayContext.NONE,
packedLight,
OverlayTexture.NO_OVERLAY,
poseStack,
bufferSource,
entity.level(),
0
);
poseStack.popPose();
poseStack.pushPose();
//旋转(方向修正)
poseStack.mulPose(Axis.YP.rotationDegrees(-Mth.lerp(partialTick, summon.yRotO, summon.getYRot())));
poseStack.mulPose(Axis.XP.rotationDegrees(Mth.lerp(partialTick, summon.xRotO + 90, summon.getXRot() + 90)));
Minecraft.getInstance().getItemRenderer().renderStatic(
itemStack,
ItemDisplayContext.NONE,
packedLight,
OverlayTexture.NO_OVERLAY,
poseStack,
bufferSource,
entity.level(),
0
);
poseStack.popPose();
if(summon.getOwner() == null) return;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(summon.getOwner());
Vec3 eyePos = summon.getOwner().getEyePosition();
Vec3 start = eyePos.add(new Vec3(
dirs[0].x * DIRECTION_OFFSET + dirs[1].x * UP_OFFSET + dirs[2].x * RIGHT_OFFSET,
dirs[0].y * DIRECTION_OFFSET + dirs[1].y * UP_OFFSET + dirs[2].y * RIGHT_OFFSET,
dirs[0].z * DIRECTION_OFFSET + dirs[1].z * UP_OFFSET + dirs[2].z * RIGHT_OFFSET
));
Vec3 end = summon.getPosition(partialTick);
double dist = end.subtract(start).length();
Vector3f[] dirs2 = MathUtil.computeCoordinateSystem(end.subtract(start).toVector3f(), 0);
Vec3 dir = MathUtil.toVec3(dirs2[0]);
Vec3 right = MathUtil.toVec3(dirs2[2]);
Vec3 up = MathUtil.toVec3(dirs2[1]);
VertexConsumer vertexConsumer = bufferSource.getBuffer(RenderType.entityCutoutNoCull(RES));
int count = (int) (dist / CHAIN_LENGTH);
for(int j = 0;j < 2;j++) {
for(int i = 0; i < count; i++) {
Vec3 current = start.add(new Vec3(
dir.x * i * CHAIN_LENGTH,
dir.y * i * CHAIN_LENGTH,
dir.z * i * CHAIN_LENGTH
)).subtract(summon.getPosition(partialTick));
Vec3 next = start.add(new Vec3(
dir.x * (i + 1) * CHAIN_LENGTH,
dir.y * (i + 1) * CHAIN_LENGTH,
dir.z * (i + 1) * CHAIN_LENGTH
)).subtract(summon.getPosition(partialTick));
Vec3 p1, p2, p3, p4;
if(j == 0) {
p1 = current.add(right.scale(0.125));
p2 = current.add(right.scale(-0.125));
p3 = next.add(right.scale(-0.125));
p4 = next.add(right.scale(0.125));
}else {
p1 = current.add(up.scale(0.125));
p2 = current.add(up.scale(-0.125));
p3 = next.add(up.scale(-0.125));
p4 = next.add(up.scale(0.125));
}
vertexConsumer.addVertex(poseStack.last().pose(), (float) p1.x, (float) p1.y, (float) p1.z)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(0.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float) p2.x, (float) p2.y, (float) p2.z)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(0.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float) p3.x, (float) p3.y, (float) p3.z)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(1.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float) p4.x, (float) p4.y, (float) p4.z)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(1.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
}
}
}
};
}
@@ -0,0 +1,77 @@
package com.lzxnone.terraria.client.item.melee;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.summon.StaticSummon;
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.texture.OverlayTexture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.*;
import net.minecraft.world.phys.*;
import org.joml.Matrix4f;
import com.lzxnone.terraria.client.entity.summon.IStaticSummonRenderBehavior;
public class ClientMeowmere {
public static final IStaticSummonRenderBehavior SUMMON_BEHAVIOR = new IStaticSummonRenderBehavior() {
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));
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.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);
}
}
};
}
@@ -0,0 +1,71 @@
package com.lzxnone.terraria.client.item.melee;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.projectile.StaticProjectile;
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.texture.OverlayTexture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.Vec3;
import org.joml.Matrix4f;
import com.lzxnone.terraria.client.entity.projectile.IStaticProjectileRenderBehavior;
public class ClientMuramasa {
public static final IStaticProjectileRenderBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileRenderBehavior() {
public static final ResourceLocation RES = ResourceLocation.parse("lzxnoneterraria:textures/vfx/muramasa_trail.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 StaticProjectile projectile)) return;
Vec3 currentPos = projectile.getPosition(partialTick);
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES));
Matrix4f matrix = poseStack.last().pose();
int quadCount = projectile.trailPositions.size() / 2 - 1;
for(int i = 0; i < quadCount;i++) {
Vec3 currentPoint1 = projectile.trailPositions.get(i * 2);
Vec3 currentPoint2 = projectile.trailPositions.get(i * 2 + 1);
Vec3 nextPoint1 = projectile.trailPositions.get(i * 2 + 3);
Vec3 nextPoint2 = projectile.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 radio1 = (float) i / quadCount;
float radio2 = (float) (i + 1) / quadCount;
vertexConsumer.addVertex(matrix, (float)x1, (float)y1, (float)z1)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(radio1, 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, 1.0f).setUv(radio1, 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, 1.0f).setUv(radio2, 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, 1.0f).setUv(radio2, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
}
}
};
}
@@ -0,0 +1,196 @@
package com.lzxnone.terraria.client.item.melee;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.beam.SwordBeam;
import com.lzxnone.terraria.entity.summon.StaticSummon;
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.client.renderer.MultiBufferSource;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.*;
import net.minecraft.world.phys.*;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import com.lzxnone.terraria.client.entity.summon.IStaticSummonRenderBehavior;
import com.lzxnone.terraria.client.entity.beam.ISwordBeamRenderBehavior;
import static com.lzxnone.terraria.item.weapon.melee.NightsEdge.*;
public class ClientNightsEdge {
public static final ISwordBeamRenderBehavior SWORD_BEAM_BEHAVIOR = new ISwordBeamRenderBehavior() {
@Override
public 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) return;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(beam.getOwner());
dirs = MathUtil.rotateCoordinateSystem(dirs[0], dirs[2], beam.getEntityData().get(SwordBeam.ROTATE));
float rotate = beam.getEntityData().get(SwordBeam.ROTATE);
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;
}
if (beam.getEntityData().get(SwordBeam.RIGHT)) progress = 1.0f - progress;
float halfWidth = SwordBeam.HALF_WIDTH * SwordBeam.SCALE;
float halfHeight = SwordBeam.HALF_HEIGHT * SwordBeam.SCALE;
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES0));
//左边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress - 0.1f * (1.0f - progress)) * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress - 0.1f * (1.0f - progress))) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color0.x(), color0.y(), color0.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.01f);
poseStack.popPose();
//右边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.1f) * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress + 0.05f)) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color2.x(), color2.y(), color2.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.02f);
poseStack.popPose();
//中间
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], progress * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color1.x(), color1.y(), color1.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0f);
poseStack.popPose();
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES3));
//外线
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], progress * 180, SwordBeam.DIST * 1.15f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(0.95f, 0.95f, 0.95f);
renderQuad(poseStack.last().pose(), vertexConsumer1,
color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.02f);
poseStack.popPose();
VertexConsumer vertexConsumer2 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES5));
//闪烁
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.25f) * 180, SwordBeam.DIST * 2.25f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress - 0.25f) * 180, rotate);
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(), vertexConsumer2,
color1.x(), color1.y(), color1.z(), alpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.03f);
}
poseStack.popPose();
}
};
public static final IStaticSummonRenderBehavior SUMMON_BEHAVIOR = new IStaticSummonRenderBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick,
PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon)) return;
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;
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
Vector3f dir = new Vector3f();
if (customData.contains("dirX")) dir.x = customData.getFloat("dirX");
if (customData.contains("dirY")) dir.y = customData.getFloat("dirY");
if (customData.contains("dirZ")) dir.z = customData.getFloat("dirZ");
Vector3f up = new Vector3f();
if (customData.contains("upX")) up.x = customData.getFloat("upX");
if (customData.contains("upY")) up.y = customData.getFloat("upY");
if (customData.contains("upZ")) up.z = customData.getFloat("upZ");
Vector3f right = new Vector3f();
if (customData.contains("rightX")) right.x = customData.getFloat("rightX");
if (customData.contains("rightY")) right.y = customData.getFloat("rightY");
if (customData.contains("rightZ")) right.z = customData.getFloat("rightZ");
Vector3f[] dirs = new Vector3f[]{dir, up, right};
double rotate = summon.getEntityData().get(StaticSummon.RZP);
double rotateSpeed = summon.getEntityData().get(StaticSummon.RZPS);
float rotateAngle = (float) ((summon.getEntityData().get(StaticSummon.AGE) + partialTick) * rotateSpeed);
Quaternionf rotation = new Quaternionf().fromAxisAngleRad(
up, (float) Math.toRadians(-rotateAngle)
);
poseStack.mulPose(rotation);
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES0));
//外层(亮)
poseStack.pushPose();
poseStack.mulPose(rotation);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
//poseStack.scale(1.0f + progress, 1.0f + progress, 1.0f + progress);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR0.x(), COLOR0.y(), COLOR0.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0f);
poseStack.popPose();
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES1));
//外线
poseStack.pushPose();
poseStack.mulPose(rotation);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST * 1.15f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
//poseStack.scale(0.95f * (1 + progress), 0.95f * (1 + progress), 0.95f * (1 + progress));
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer1,
1.0f, 1.0f, 1.0f, alpha, halfWidth, halfHeight, 0f, 0f, 0.02f);
poseStack.popPose();
VertexConsumer vertexConsumer2 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES2));
//闪烁
poseStack.pushPose();
poseStack.mulPose(rotation);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 135, SwordBeam.DIST * 2.25f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
//poseStack.scale(1.0f + progress, 1.0f + progress, 1.0f + progress);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer2,
COLOR0.x(), COLOR0.y(), COLOR0.z(), alpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.04f);
poseStack.popPose();
}
};
}
@@ -0,0 +1,222 @@
package com.lzxnone.terraria.client.item.melee;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.beam.SwordBeam;
import com.lzxnone.terraria.entity.summon.StaticSummon;
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.client.renderer.MultiBufferSource;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.*;
import net.minecraft.world.phys.*;
import org.joml.Vector3f;
import com.lzxnone.terraria.client.entity.summon.IStaticSummonRenderBehavior;
import static com.lzxnone.terraria.item.weapon.melee.TerraBlade.*;
public class ClientTerraBlade {
public static final IStaticSummonRenderBehavior SUMMON_BEHAVIOR = new IStaticSummonRenderBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick,
PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon)) return;
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;
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
Vector3f dir = new Vector3f();
if(customData.contains("dirX")) dir.x = customData.getFloat("dirX");
if(customData.contains("dirY")) dir.y = customData.getFloat("dirY");
if(customData.contains("dirZ")) dir.z = customData.getFloat("dirZ");
Vector3f up = new Vector3f();
if(customData.contains("upX")) up.x = customData.getFloat("upX");
if(customData.contains("upY")) up.y = customData.getFloat("upY");
if(customData.contains("upZ")) up.z = customData.getFloat("upZ");
Vector3f right = new Vector3f();
if(customData.contains("rightX")) right.x = customData.getFloat("rightX");
if(customData.contains("rightY")) right.y = customData.getFloat("rightY");
if(customData.contains("rightZ")) right.z = customData.getFloat("rightZ");
Vector3f[] dirs = new Vector3f[]{dir, up, right};
double rotate = summon.getEntityData().get(StaticSummon.RZP);
poseStack.pushPose();
float size = 1.0f - 0.25f * progress;
poseStack.scale(size, size, size);
float[] dz = {0.1f, 0f, -0.1f};
for(int x = 0;x < 3;x++) {
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES0));
//左边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90 - 18 * (1.0f - progress), SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 18 * (1.0f - progress), rotate);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR0.x(), COLOR0.y(), COLOR0.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.01f + dz[x]);
poseStack.popPose();
//中间
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR1.x(), COLOR1.y(), COLOR1.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0f + dz[x]);
poseStack.popPose();
//右边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 108, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], -9 * (1.0f - progress), rotate);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR2.x(), COLOR2.y(), COLOR2.z(), alpha, halfWidth, halfHeight, 0f, 0, 0.01f + dz[x]);
poseStack.popPose();
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES1));
//三线
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST / 1.5f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
poseStack.scale(0.5f, 0.5f, 0.5f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer1,
1.0f, 1.0f, 1.0f, alpha, halfWidth, halfHeight, 0f, 0f, 0.02f + dz[x]);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST / 1.25f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
poseStack.scale(0.75f, 0.75f, 0.75f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer1,
1.0f, 1.0f, 1.0f, alpha, halfWidth, halfHeight, 0f, 0f, 0.02f + dz[x]);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST * 1.15f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
poseStack.scale(0.95f, 0.95f, 0.95f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer1,
1.0f, 1.0f, 1.0f, alpha, halfWidth, halfHeight, 0f, 0f, 0.02f + dz[x]);
poseStack.popPose();
VertexConsumer vertexConsumer2 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES2));
//边缘高光
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 100, SwordBeam.DIST * 1.15f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
poseStack.scale(1.0f, 1.0f, 1.0f);
for (int i = 0; i < 5; i++) {
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer2,
COLOR2.x(), COLOR2.y(), COLOR2.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.03f + dz[x]);
}
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);
}
VertexConsumer vertexConsumer3 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES3));
//闪烁(外层)
poseStack.pushPose();
for (int k = 0; k < 2; k++) {
poseStack.pushPose();
if (k == 0) {
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90 - 60.0 * progress, SwordBeam.DIST * 2f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 60 * progress, rotate);
} else {
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90 + 60.0 * progress, SwordBeam.DIST * 2f + 0.5f * progress);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], -60 * progress, rotate);
}
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++) {
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer3,
COLOR2.x(), COLOR2.y(), COLOR2.z(), sparkleAlpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.03f + dz[x]);
}
poseStack.popPose();
}
poseStack.popPose();
}
poseStack.popPose();
//闪烁(中层)
poseStack.pushPose();
for (int k = 0; k < 2; k++) {
poseStack.pushPose();
if (k == 0) {
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90 - 30.0 * progress, SwordBeam.DIST * 2f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 30 * progress, rotate);
} else {
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90 + 30.0 * progress, SwordBeam.DIST * 2.1f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], -30 * progress, rotate);
}
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++) {
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer3,
COLOR2.x(), COLOR2.y(), COLOR2.z(), sparkleAlpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.03f + dz[x]);
}
poseStack.popPose();
}
poseStack.popPose();
}
poseStack.popPose();
//闪烁(内层)
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST * 2f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
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++) {
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer3,
COLOR2.x(), COLOR2.y(), COLOR2.z(), sparkleAlpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.03f + dz[x]);
}
poseStack.popPose();
}
poseStack.popPose();
}
poseStack.popPose();
}
};
}
@@ -0,0 +1,66 @@
package com.lzxnone.terraria.client.item.melee;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.summon.StaticSummon;
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.texture.OverlayTexture;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.*;
import org.joml.Quaternionf;
import com.lzxnone.terraria.client.entity.summon.IStaticSummonRenderBehavior;
import org.joml.Vector3f;
import static com.lzxnone.terraria.item.weapon.melee.Terragrim.*;
public class ClientTerragrim {
public static final IStaticSummonRenderBehavior SUMMON_BEHAVIOR = new IStaticSummonRenderBehavior() {
public static final float HALF_WIDTH = 32.0f;
public static final float HALF_HEIGHT = 30.0f;
public static final float SCALE = 0.05f;
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon)) return;
Entity owner = summon.getOwner();
if(owner == null) return;
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
if(!customData.contains("idx")) return;
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES[Math.min(customData.getInt("idx"), RES.length - 1)]));
Vector3f[] dirs = MathUtil.computeCoordinateSystem(owner);
int rotate = summon.getEntityData().get(StaticSummon.RZP);
Quaternionf rotation = new Quaternionf()
.fromAxisAngleRad(dirs[0], (float) Math.toRadians(rotate));
poseStack.mulPose(rotation);
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.XP.rotationDegrees(-90.0F));
poseStack.mulPose(Axis.ZP.rotationDegrees(-90.0F));
vertexConsumer.addVertex(poseStack.last().pose(), -HALF_WIDTH * SCALE, -HALF_HEIGHT * SCALE, 0)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(0.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
vertexConsumer.addVertex(poseStack.last().pose(), HALF_WIDTH * SCALE, -HALF_HEIGHT * SCALE, 0)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(1.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
vertexConsumer.addVertex(poseStack.last().pose(), HALF_WIDTH * SCALE, HALF_HEIGHT * SCALE, 0)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(1.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
vertexConsumer.addVertex(poseStack.last().pose(), -HALF_WIDTH * SCALE, HALF_HEIGHT * SCALE, 0)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(0.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
}
};
}
@@ -0,0 +1,138 @@
package com.lzxnone.terraria.client.item.melee;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.beam.SwordBeam;
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.client.renderer.MultiBufferSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.*;
import org.joml.Vector3f;
import com.lzxnone.terraria.client.entity.beam.ISwordBeamRenderBehavior;
public class ClientTrueExcalibur {
public static final ISwordBeamRenderBehavior SWORD_BEAM_BEHAVIOR = new ISwordBeamRenderBehavior() {
@Override
public 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) return;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(beam.getOwner());
dirs = MathUtil.rotateCoordinateSystem(dirs[0], dirs[2], beam.getEntityData().get(SwordBeam.ROTATE));
float rotate = beam.getEntityData().get(SwordBeam.ROTATE);
Vector3f color0 = new Vector3f(0.651f, 0.102f, 0.224f);
Vector3f color1 = new Vector3f(0.945f, 0.286f, 0.525f);
Vector3f color2 = new Vector3f(0.945f, 0.286f, 0.525f);
Vector3f color3 = new Vector3f(1.0f, 1.0f, 1.0f);
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(beam.getEntityData().get(SwordBeam.RIGHT)) progress = 1.0f - progress;
float halfWidth = SwordBeam.HALF_WIDTH * SwordBeam.SCALE;
float halfHeight = SwordBeam.HALF_HEIGHT * SwordBeam.SCALE;
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES0));
//左边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress - 0.1f * (1.0f - progress)) * 180, SwordBeam.DIST * 1.5f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress - 0.1f * (1.0f - progress))) * 180, rotate);
poseStack.scale(1.5f, 1.5f, 1.5f);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color0.x(), color0.y(), color0.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.05f);
poseStack.popPose();
//右边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.1f) * 180, SwordBeam.DIST * 1.5f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress + 0.05f)) * 180, rotate);
poseStack.scale(1.5f, 1.5f, 1.5f);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color2.x(), color2.y(), color2.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.06f);
poseStack.popPose();
//中间
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], progress * 180, SwordBeam.DIST * 1.5f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(1.5f, 1.5f, 1.5f);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color1.x(), color1.y(), color1.z(), alpha, halfWidth, halfHeight, 0f, 0f, -0.04f);
poseStack.popPose();
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES3));
//三线
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.05f) * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(0.75f, 0.75f, 0.75f);
renderQuad(poseStack.last().pose(), vertexConsumer1,
color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, -0.045f);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.05f) * 180, SwordBeam.DIST * 1.2f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(1.125f, 1.125f, 1.125f);
renderQuad(poseStack.last().pose(), vertexConsumer1,
color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, -0.045f);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], progress * 180, SwordBeam.DIST * 1.725f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(1.425f, 1.425f, 1.425f);
renderQuad(poseStack.last().pose(), vertexConsumer1,
color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, -0.045f);
poseStack.popPose();
VertexConsumer vertexConsumer2 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES4));
//边缘高光
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.05f) * 180, SwordBeam.DIST * 1.725f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress + 0.05f)) * 180, rotate);
poseStack.scale(1.5f, 1.5f, 1.5f);
for(int i = 0;i < 20;i++) {
renderQuad(poseStack.last().pose(), vertexConsumer2,
color1.x(), color1.y(), color1.z(), alpha, halfWidth, halfHeight, 0f, 0f, -0.03f);
}
poseStack.popPose();
VertexConsumer vertexConsumer3 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES5));
//闪烁
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.25f) * 180, SwordBeam.DIST * 3.375f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress + 0.25f)) * 180, rotate);
poseStack.mulPose(Axis.ZP.rotationDegrees(45.0F));
poseStack.scale(1.5f, 1.5f, 1.5f);
for(int i = 0;i < 20;i++) {
renderQuad(poseStack.last().pose(), vertexConsumer3,
color1.x(), color1.y(), color1.z(), alpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, -0.03f);
}
poseStack.popPose();
ISwordBeamRenderBehavior.super.render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight);
}
};
}
@@ -0,0 +1,279 @@
package com.lzxnone.terraria.client.item.melee;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.beam.SwordBeam;
import com.lzxnone.terraria.entity.summon.StaticSummon;
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.client.renderer.MultiBufferSource;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.*;
import net.minecraft.world.phys.*;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import com.lzxnone.terraria.client.entity.summon.IStaticSummonRenderBehavior;
import com.lzxnone.terraria.client.entity.beam.ISwordBeamRenderBehavior;
import static com.lzxnone.terraria.item.weapon.melee.TrueNightsEdge.*;
public class ClientTrueNightsEdge {
public static final ISwordBeamRenderBehavior SWORD_BEAM_BEHAVIOR = new ISwordBeamRenderBehavior() {
@Override
public 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) return;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(beam.getOwner());
dirs = MathUtil.rotateCoordinateSystem(dirs[0], dirs[2], beam.getEntityData().get(SwordBeam.ROTATE));
float rotate = beam.getEntityData().get(SwordBeam.ROTATE);
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;
}
if (beam.getEntityData().get(SwordBeam.RIGHT)) progress = 1.0f - progress;
float halfWidth = SwordBeam.HALF_WIDTH * SwordBeam.SCALE;
float halfHeight = SwordBeam.HALF_HEIGHT * SwordBeam.SCALE;
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES0));
//左边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress - 0.1f * (1.0f - progress)) * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress - 0.1f * (1.0f - progress))) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color0.x(), color0.y(), color0.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.01f);
poseStack.popPose();
//右边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.1f) * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress + 0.05f)) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color2.x(), color2.y(), color2.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.02f);
poseStack.popPose();
//中间
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], progress * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color1.x(), color1.y(), color1.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0f);
poseStack.popPose();
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES3));
//外线
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], progress * 180, SwordBeam.DIST * 1.15f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(0.95f, 0.95f, 0.95f);
renderQuad(poseStack.last().pose(), vertexConsumer1,
color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.02f);
poseStack.popPose();
VertexConsumer vertexConsumer2 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES5));
//闪烁
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.25f) * 180, SwordBeam.DIST * 2.25f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress - 0.25f) * 180, rotate);
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(), vertexConsumer2,
color1.x(), color1.y(), color1.z(), alpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.03f);
}
poseStack.popPose();
}
};
public static final IStaticSummonRenderBehavior SUMMON_BEHAVIOR = new IStaticSummonRenderBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick,
PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon)) return;
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;
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
Vector3f dir = new Vector3f();
if (customData.contains("dirX")) dir.x = customData.getFloat("dirX");
if (customData.contains("dirY")) dir.y = customData.getFloat("dirY");
if (customData.contains("dirZ")) dir.z = customData.getFloat("dirZ");
Vector3f up = new Vector3f();
if (customData.contains("upX")) up.x = customData.getFloat("upX");
if (customData.contains("upY")) up.y = customData.getFloat("upY");
if (customData.contains("upZ")) up.z = customData.getFloat("upZ");
Vector3f right = new Vector3f();
if (customData.contains("rightX")) right.x = customData.getFloat("rightX");
if (customData.contains("rightY")) right.y = customData.getFloat("rightY");
if (customData.contains("rightZ")) right.z = customData.getFloat("rightZ");
Vector3f[] dirs = new Vector3f[]{dir, up, right};
double rotate = summon.getEntityData().get(StaticSummon.RZP);
double rotateSpeed = summon.getEntityData().get(StaticSummon.RZPS);
float rotateAngle = (float) ((summon.getEntityData().get(StaticSummon.AGE) + partialTick) * rotateSpeed);
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES0));
//外层(亮)
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR0.x(), COLOR0.y(), COLOR0.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0f);
poseStack.popPose();
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 160, SwordBeam.DIST * 1.5f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], -45, rotate);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR0.x(), COLOR0.y(), COLOR0.z(), alpha * 0.5f, halfWidth, halfHeight, 0f, 0f, -0.01f);
poseStack.popPose();
//外层(淡)
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 20, SwordBeam.DIST * 1.25f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 45, rotate);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR0.x(), COLOR0.y(), COLOR0.z(), alpha * 0.25f, halfWidth, halfHeight, 0f, 0f, -0.02f);
poseStack.popPose();
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], -100, SwordBeam.DIST * 2.5f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 180, rotate);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR0.x(), COLOR0.y(), COLOR0.z(), alpha * 0.125f, halfWidth, halfHeight, 0f, 0f, -0.03f);
poseStack.popPose();
//内层
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 160, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], -45, rotate);
poseStack.scale(0.8f, 0.8f, 0.8f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR1.x(), COLOR1.y(), COLOR1.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.01f);
poseStack.popPose();
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 70, SwordBeam.DIST * 0.5);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 15, rotate);
poseStack.scale(0.8f, 0.8f, 0.8f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR1.x(), COLOR1.y(), COLOR1.z(), alpha * 0.5f, halfWidth, halfHeight, 0f, 0f, -0.03f);
poseStack.popPose();
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], -30, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 75, rotate);
poseStack.scale(0.8f, 0.8f, 0.8f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR1.x(), COLOR1.y(), COLOR1.z(), alpha * 0.25f, halfWidth, halfHeight, 0f, 0f, -0.02f);
poseStack.popPose();
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], -120, SwordBeam.DIST * 2f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 210, rotate);
poseStack.scale(0.8f, 0.8f, 0.8f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR1.x(), COLOR1.y(), COLOR1.z(), alpha * 0.125f, halfWidth, halfHeight, 0f, 0f, -0.02f);
poseStack.popPose();
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES1));
//外线
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST * 1.15f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
poseStack.scale(0.95f, 0.95f, 0.95f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer1,
1.0f, 1.0f, 1.0f, alpha, halfWidth, halfHeight, 0f, 0f, 0.02f);
poseStack.popPose();
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 160, SwordBeam.DIST * 1.725f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], -45, rotate);
poseStack.scale(0.95f, 0.95f, 0.95f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer1,
1.0f, 1.0f, 1.0f, alpha, halfWidth, halfHeight, 0f, 0f, 0.02f);
poseStack.popPose();
VertexConsumer vertexConsumer2 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES2));
//闪烁
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 180, SwordBeam.DIST * 1.75f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], -45, rotate);
poseStack.mulPose(Axis.ZP.rotationDegrees(45.0F));
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer2,
COLOR2.x(), COLOR2.y(), COLOR2.z(), alpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.04f);
poseStack.popPose();
}
private void rotateInCenter(PoseStack poseStack, Vector3f[] dirs, float angle) {
float cos = (float) Math.cos(Math.toRadians(90));
float sin = (float) Math.sin(Math.toRadians(90));
Vector3f center = new Vector3f(
cos * dirs[2].x + sin * dirs[0].x,
cos * dirs[2].y + sin * dirs[0].y,
cos * dirs[2].z + sin * dirs[0].z
).normalize().mul(1.15f);
Quaternionf rotation = new Quaternionf().fromAxisAngleRad(
dirs[1], (float) Math.toRadians(angle)
);
poseStack.translate(-center.x, -center.y, -center.z);
poseStack.mulPose(rotation);
poseStack.translate(center.x, center.y, center.z);
}
};
}
@@ -0,0 +1,199 @@
package com.lzxnone.terraria.client.item.melee;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.TintedVertexConsumer;
import com.lzxnone.terraria.entity.projectile.StaticProjectile;
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.client.Minecraft;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.*;
import net.minecraft.world.phys.Vec3;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import com.lzxnone.terraria.client.entity.projectile.IStaticProjectileRenderBehavior;
import static com.lzxnone.terraria.item.weapon.melee.Zenith.*;
public class ClientZenith {
public static final IStaticProjectileRenderBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileRenderBehavior() {
@Override
public void render(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;
CompoundTag customData = proj.getEntityData().get(StaticProjectile.CUSTOM_DATA);
if(!customData.contains("a") || !customData.contains("w") || !customData.contains("angle") || !customData.contains("start") || !customData.contains("idx")) return;
int start = customData.getInt("start");
if(proj.getEntityData().get(StaticProjectile.AGE) <= start) return;
int idx = customData.getInt("idx");
Vec3 dir = MathUtil.toVec3(proj.getEntityData().get(StaticProjectile.DIRECTION)).normalize();
Vec3 up = MathUtil.toVec3(proj.getEntityData().get(StaticProjectile.UP)).normalize();
Vec3 right = MathUtil.toVec3(proj.getEntityData().get(StaticProjectile.RIGHT)).normalize();
Quaternionf rotationDir = new Quaternionf()
.fromAxisAngleRad(dir.toVector3f(), (float) Math.toRadians(customData.getInt("angle")));
Quaternionf rotationUp1 = new Quaternionf()
.fromAxisAngleRad(up.toVector3f(), (float) -(customData.getDouble("w") * (proj.getEntityData().get(StaticProjectile.AGE) - start + partialTick)));
Quaternionf rotationUp2 = new Quaternionf()
.fromAxisAngleRad(up.toVector3f(), (float) Math.PI);
float[] xyRot = MathUtil.computeXYRot(dir.toVector3f(), up.toVector3f());
poseStack.pushPose();
//旋转
poseStack.mulPose(rotationUp1);
poseStack.mulPose(rotationUp2);
poseStack.mulPose(rotationDir);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.XP.rotationDegrees(proj.getEntityData().get(StaticProjectile.RXP)));
poseStack.mulPose(Axis.YP.rotationDegrees(proj.getEntityData().get(StaticProjectile.RYP)));
poseStack.mulPose(Axis.ZP.rotationDegrees(proj.getEntityData().get(StaticProjectile.RZP)));
//缩放
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,
1.0f,
1.0f,
1.0f,
proj.getEntityData().get(StaticProjectile.COLOR_A));
},
entity.level(),
0
);
poseStack.popPose();
Vec3 currentPos = proj.getPosition(partialTick);
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES0));
Matrix4f matrix = poseStack.last().pose();
Vector3f color = new Vector3f(
proj.getEntityData().get(StaticProjectile.COLOR_R),
proj.getEntityData().get(StaticProjectile.COLOR_G),
proj.getEntityData().get(StaticProjectile.COLOR_B)
);
float mainAlpha = (float) getTrailAlpha();
if(idx == 1) mainAlpha = mainAlpha * 0.5f;
if(idx == 2) mainAlpha = mainAlpha * 0.25f;
//尾迹
int quadCount = proj.trailPositions.size() / 2 - 1;
for(int j = 0;j < 2;j++) {
for(int i = 1; i < quadCount; i++) {
Vec3 currentPoint1 = proj.trailPositions.get(i * 2);
Vec3 currentPoint2 = proj.trailPositions.get(i * 2 + 1);
Vec3 nextPoint1 = proj.trailPositions.get(i * 2 + 3);
Vec3 nextPoint2 = proj.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 radio1 = (float) i / quadCount;
float radio2 = (float) (i + 1) / quadCount;
vertexConsumer0.addVertex(matrix, (float) x1, (float) y1, (float) z1)
.setColor(color.x, color.y, color.z, mainAlpha).setUv(radio1, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
vertexConsumer0.addVertex(matrix, (float) x2, (float) y2, (float) z2)
.setColor(color.x, color.y, color.z, 0).setUv(radio1, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
vertexConsumer0.addVertex(matrix, (float) x3, (float) y3, (float) z3)
.setColor(color.x, color.y, color.z, 0).setUv(radio2, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
vertexConsumer0.addVertex(matrix, (float) x4, (float) y4, (float) z4)
.setColor(color.x, color.y, color.z, mainAlpha).setUv(radio2, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
}
}
//闪烁
if(idx != 0) return;
float halfWidth = 32 * 0.05f;
float halfHeight = 32 * 0.05f;
float radio = (float) (proj.getEntityData().get(StaticProjectile.AGE) - start) / (float) proj.getEntityData().get(StaticProjectile.LIFETIME);
float alpha;
if(radio > 0.25f && radio < 0.4f) {
alpha = (radio - 0.25f) / 0.15f;
}else if(radio >= 0.4f && radio < 0.6f) {
alpha = 1.0f;
}else if(radio >= 0.6f && radio < 0.75f) {
alpha = 1.0f - (radio - 0.6f) / 0.15f;
}else {
alpha = 0;
}
if(Math.abs(alpha) < 0.001) return;
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES1));
poseStack.pushPose();
Vector3f tempRight = right.toVector3f();
double rad = customData.getDouble("w") * (proj.getEntityData().get(StaticProjectile.AGE) - start + partialTick);
Vector3f swordTipDir = tempRight.rotate(new Quaternionf().fromAxisAngleRad(up.toVector3f(), (float) (Math.PI / 2 - rad))).normalize();
Vec3 trans = MathUtil.toVec3(swordTipDir).scale(1.25);
poseStack.translate(trans.x, trans.y, trans.z);
poseStack.mulPose(new Quaternionf()
.fromAxisAngleRad(dir.toVector3f(), (float) Math.toRadians(customData.getInt("angle")))
.rotateY((float) Math.toRadians(-xyRot[1]))
.rotateX((float) Math.toRadians(-90 + xyRot[0]))
);
poseStack.scale(1.0f, 1.0f, 1.0f);
matrix = poseStack.last().pose();
for(int i = 0; i < 3; i++) {
vertexConsumer1.addVertex(matrix, -halfWidth, -halfHeight, 0.01f)
.setColor(color.x, color.y, color.z, alpha).setUv(0.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
vertexConsumer1.addVertex(matrix, halfWidth, -halfHeight, 0.01f)
.setColor(color.x, color.y, color.z, alpha).setUv(1.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
vertexConsumer1.addVertex(matrix, halfWidth, halfHeight, 0.01f)
.setColor(color.x, color.y, color.z, alpha).setUv(1.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
vertexConsumer1.addVertex(matrix, -halfWidth, halfHeight, 0.01f)
.setColor(color.x, color.y, color.z, alpha).setUv(0.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
}
poseStack.popPose();
}
};
}
@@ -0,0 +1,181 @@
package com.lzxnone.terraria.client.item.summon;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.PureColorVertexConsumer;
import com.lzxnone.terraria.entity.TintedVertexConsumer;
import com.lzxnone.terraria.entity.summon.StaticSummon;
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.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.*;
import net.minecraft.world.phys.Vec3;
import com.lzxnone.terraria.client.entity.summon.IStaticSummonRenderBehavior;
import static com.lzxnone.terraria.item.weapon.summon.Terraprisma.*;
public class ClientTerraprisma {
public static final IStaticSummonRenderBehavior SUMMON_BEHAVIOR = new IStaticSummonRenderBehavior() {
public static final ResourceLocation RES = ResourceLocation.parse("lzxnoneterraria:textures/vfx/sword_trail.png");
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon) || summon.getOwner() == null) return;
ItemStack stack = summon.getEntityData().get(StaticSummon.ITEM);
if(stack.isEmpty()) return;
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
int idx = customData.contains("idx") ? customData.getInt("idx") : 0;
int state = customData.contains("state") ? customData.getInt("state") : 0;
float[] color = computeCrystalColor(summon.tickCount + partialTick, idx);
Vec3 currentPos = summon.position();
if(state == State.DASH_PRE.ordinal() || state == State.DASH.ordinal()) {
for(int i = summon.afterimageFrames.size() - 1; i >= 0; i--) {
StaticSummon.AfterimageFrame frame = summon.afterimageFrames.get(i);
float alpha = AFTERIMAGE_ALPHA * (1.0f - (float)i / AFTERIMAGE_MAX_LENGTH);
Vec3 offset = frame.position().subtract(currentPos);
poseStack.pushPose();
poseStack.translate(offset.x, offset.y, offset.z);
poseStack.mulPose(Axis.YP.rotationDegrees(-frame.yRot()));
poseStack.mulPose(Axis.XP.rotationDegrees(frame.xRot()));
poseStack.mulPose(Axis.ZP.rotationDegrees(90));
poseStack.mulPose(Axis.YP.rotationDegrees(90));
poseStack.scale(
summon.getEntityData().get(StaticSummon.SCALE_X) * AFTERIMAGE_SCALE,
summon.getEntityData().get(StaticSummon.SCALE_Y) * AFTERIMAGE_SCALE,
summon.getEntityData().get(StaticSummon.SCALE_Z) * AFTERIMAGE_SCALE
);
Minecraft.getInstance().getItemRenderer().renderStatic(
stack,
ItemDisplayContext.NONE,
LightTexture.FULL_BRIGHT,
OverlayTexture.NO_OVERLAY,
poseStack,
renderType -> {
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(InventoryMenu.BLOCK_ATLAS));
return new PureColorVertexConsumer(vertexConsumer,
frame.r(),
frame.g(),
frame.b(),
alpha);
},
entity.level(),
0
);
poseStack.popPose();
}
}
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.ZP.rotationDegrees(90));
poseStack.mulPose(Axis.YP.rotationDegrees(90));
poseStack.scale(
summon.getEntityData().get(StaticSummon.SCALE_X),
summon.getEntityData().get(StaticSummon.SCALE_Y),
summon.getEntityData().get(StaticSummon.SCALE_Z)
);
for(int i = 0;i < 3;i++) {
Minecraft.getInstance().getItemRenderer().renderStatic(
stack,
ItemDisplayContext.NONE,
LightTexture.FULL_BRIGHT,
OverlayTexture.NO_OVERLAY,
poseStack,
renderType -> {
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(InventoryMenu.BLOCK_ATLAS));
return new TintedVertexConsumer(vertexConsumer,
color[0],
color[1],
color[2],
summon.getEntityData().get(StaticSummon.COLOR_A));
},
entity.level(),
0
);
}
poseStack.popPose();
if(state == State.ROTATE.ordinal()) {
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES));
float mainAlpha = TRAIL_ALPHA;
int quadCount = summon.trailPositions.size() / 2 - 1;
for(int j = 0; j < 3; j++) {
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 radio1 = (float) i / quadCount;
float radio2 = (float) (i + 1) / quadCount;
vertexConsumer.addVertex(poseStack.last().pose(), (float)x1, (float)y1, (float)z1)
.setColor(color[0], color[1], color[2], mainAlpha).setUv(radio1, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float)x2, (float)y2, (float)z2)
.setColor(color[0], color[1], color[2], 0).setUv(radio1, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float)x3, (float)y3, (float)z3)
.setColor(color[0], color[1], color[2], 0).setUv(radio2, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float)x4, (float)y4, (float)z4)
.setColor(color[0], color[1], color[2], mainAlpha).setUv(radio2, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
}
}
}
}
};
private static float[] computeCrystalColor(float time, int idx) {
float hue = (time * 0.015F + idx * 0.12F) % 1.0F;
int rgb = Mth.hsvToRgb(hue, 0.85F, 1.0F);
float rainbowR = ((rgb >> 16) & 255) / 255.0F;
float rainbowG = ((rgb >> 8) & 255) / 255.0F;
float rainbowB = (rgb & 255) / 255.0F;
float tint = 0.35F;
float pulse = 0.92F + 0.08F * Mth.sin(time * 0.12F + idx * 0.7F);
return new float[]{
(1.0F * (1.0F - tint) + rainbowR * tint) * pulse,
(1.0F * (1.0F - tint) + rainbowG * tint) * pulse,
(1.0F * (1.0F - tint) + rainbowB * tint) * pulse
};
}
}
@@ -1,14 +1,14 @@
package com.lzxnone.terraria.renderer; package com.lzxnone.terraria.client.renderer;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.client.entity.beam.ClientSwordBeamRenderBehaviors;
import com.lzxnone.terraria.client.entity.projectile.ClientStaticProjectileRenderBehaviors;
import com.lzxnone.terraria.client.entity.summon.ClientStaticSummonRenderBehaviors;
import com.lzxnone.terraria.entity.IrisCompat; import com.lzxnone.terraria.entity.IrisCompat;
import com.lzxnone.terraria.entity.beam.SwordBeam; 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.StaticProjectile;
import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors;
import com.lzxnone.terraria.entity.summon.StaticSummon; import com.lzxnone.terraria.entity.summon.StaticSummon;
import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors; import com.lzxnone.terraria.client.event.ShaderRegistry;
import com.lzxnone.terraria.event.ShaderRegistry;
import com.mojang.blaze3d.pipeline.RenderTarget; import com.mojang.blaze3d.pipeline.RenderTarget;
import com.mojang.blaze3d.pipeline.TextureTarget; import com.mojang.blaze3d.pipeline.TextureTarget;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
@@ -214,20 +214,20 @@ public class BloomRenderer {
&& projectile.getEntityData().get(StaticProjectile.GLOW)) { && projectile.getEntityData().get(StaticProjectile.GLOW)) {
poseStack.pushPose(); poseStack.pushPose();
poseStack.translate(camX, camY, camZ); poseStack.translate(camX, camY, camZ);
StaticProjectileBehaviors.getBehavior(projectile.getEntityData().get(StaticProjectile.BEHAVIOR)) ClientStaticProjectileRenderBehaviors.getBehavior(projectile.getEntityData().get(StaticProjectile.BEHAVIOR))
.render(projectile, entityYaw, partialTick, poseStack, bufferSource, LightTexture.FULL_BRIGHT); .render(projectile, entityYaw, partialTick, poseStack, bufferSource, LightTexture.FULL_BRIGHT);
poseStack.popPose(); poseStack.popPose();
}else if (entity instanceof StaticSummon summon }else if (entity instanceof StaticSummon summon
&& summon.getEntityData().get(StaticSummon.GLOW)) { && summon.getEntityData().get(StaticSummon.GLOW)) {
poseStack.pushPose(); poseStack.pushPose();
poseStack.translate(camX, camY, camZ); poseStack.translate(camX, camY, camZ);
StaticSummonBehaviors.getBehavior(summon.getEntityData().get(StaticSummon.BEHAVIOR)) ClientStaticSummonRenderBehaviors.getBehavior(summon.getEntityData().get(StaticSummon.BEHAVIOR))
.render(summon, entityYaw, partialTick, poseStack, bufferSource, LightTexture.FULL_BRIGHT); .render(summon, entityYaw, partialTick, poseStack, bufferSource, LightTexture.FULL_BRIGHT);
poseStack.popPose(); poseStack.popPose();
}else if (entity instanceof SwordBeam beam) { }else if (entity instanceof SwordBeam beam) {
poseStack.pushPose(); poseStack.pushPose();
poseStack.translate(camX, camY, camZ); poseStack.translate(camX, camY, camZ);
SwordBeamBehaviors.getBehavior(beam.getEntityData().get(SwordBeam.BEHAVIOR)) ClientSwordBeamRenderBehaviors.getBehavior(beam.getEntityData().get(SwordBeam.BEHAVIOR))
.render(beam, entityYaw, partialTick, poseStack, bufferSource, LightTexture.FULL_BRIGHT); .render(beam, entityYaw, partialTick, poseStack, bufferSource, LightTexture.FULL_BRIGHT);
poseStack.popPose(); poseStack.popPose();
} }
@@ -1,14 +1,14 @@
package com.lzxnone.terraria.renderer; package com.lzxnone.terraria.client.renderer;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.client.entity.beam.ClientSwordBeamRenderBehaviors;
import com.lzxnone.terraria.client.entity.projectile.ClientStaticProjectileRenderBehaviors;
import com.lzxnone.terraria.client.entity.summon.ClientStaticSummonRenderBehaviors;
import com.lzxnone.terraria.entity.IrisCompat; import com.lzxnone.terraria.entity.IrisCompat;
import com.lzxnone.terraria.entity.beam.SwordBeam; 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.StaticProjectile;
import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors;
import com.lzxnone.terraria.entity.summon.StaticSummon; import com.lzxnone.terraria.entity.summon.StaticSummon;
import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors; import com.lzxnone.terraria.client.event.ShaderRegistry;
import com.lzxnone.terraria.event.ShaderRegistry;
import com.mojang.blaze3d.pipeline.RenderTarget; import com.mojang.blaze3d.pipeline.RenderTarget;
import com.mojang.blaze3d.pipeline.TextureTarget; import com.mojang.blaze3d.pipeline.TextureTarget;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
@@ -160,21 +160,21 @@ public class OutlineRenderer {
&& projectile.getEntityData().get(StaticProjectile.OUTLINE)) { && projectile.getEntityData().get(StaticProjectile.OUTLINE)) {
poseStack.pushPose(); poseStack.pushPose();
poseStack.translate(camX, camY, camZ); poseStack.translate(camX, camY, camZ);
StaticProjectileBehaviors.getBehavior(projectile.getEntityData().get(StaticProjectile.BEHAVIOR)) ClientStaticProjectileRenderBehaviors.getBehavior(projectile.getEntityData().get(StaticProjectile.BEHAVIOR))
.render(projectile, entityYaw, partialTick, poseStack, bufferSource, LightTexture.FULL_BRIGHT); .render(projectile, entityYaw, partialTick, poseStack, bufferSource, LightTexture.FULL_BRIGHT);
poseStack.popPose(); poseStack.popPose();
}else if(entity instanceof StaticSummon summon }else if(entity instanceof StaticSummon summon
&& summon.getEntityData().get(StaticSummon.OUTLINE)) { && summon.getEntityData().get(StaticSummon.OUTLINE)) {
poseStack.pushPose(); poseStack.pushPose();
poseStack.translate(camX, camY, camZ); poseStack.translate(camX, camY, camZ);
StaticSummonBehaviors.getBehavior(summon.getEntityData().get(StaticSummon.BEHAVIOR)) ClientStaticSummonRenderBehaviors.getBehavior(summon.getEntityData().get(StaticSummon.BEHAVIOR))
.render(summon, entityYaw, partialTick, poseStack, bufferSource, LightTexture.FULL_BRIGHT); .render(summon, entityYaw, partialTick, poseStack, bufferSource, LightTexture.FULL_BRIGHT);
poseStack.popPose(); poseStack.popPose();
}else if(entity instanceof SwordBeam beam }else if(entity instanceof SwordBeam beam
&& beam.getEntityData().get(SwordBeam.OUTLINE)) { && beam.getEntityData().get(SwordBeam.OUTLINE)) {
poseStack.pushPose(); poseStack.pushPose();
poseStack.translate(camX, camY, camZ); poseStack.translate(camX, camY, camZ);
SwordBeamBehaviors.getBehavior(beam.getEntityData().get(SwordBeam.BEHAVIOR)) ClientSwordBeamRenderBehaviors.getBehavior(beam.getEntityData().get(SwordBeam.BEHAVIOR))
.render(beam, entityYaw, partialTick, poseStack, bufferSource, LightTexture.FULL_BRIGHT); .render(beam, entityYaw, partialTick, poseStack, bufferSource, LightTexture.FULL_BRIGHT);
poseStack.popPose(); poseStack.popPose();
} }
@@ -0,0 +1,48 @@
package com.lzxnone.terraria.effect;
import com.lzxnone.terraria.LzxnoneTerraria;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.item.alchemy.Potion;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
public class ModPotions {
public static final DeferredRegister<Potion> POTIONS =
DeferredRegister.create(BuiltInRegistries.POTION, LzxnoneTerraria.MODID);
public static final DeferredHolder<Potion, Potion> SHORT_SUMMON_0 =
registerSummonPotion("short_summon_0", 6000, 0);
public static final DeferredHolder<Potion, Potion> MEDIUM_SUMMON_0 =
registerSummonPotion("medium_summon_0", 36000, 0);
public static final DeferredHolder<Potion, Potion> LONG_SUMMON_0 =
registerSummonPotion("long_summon_0", 216000, 0);
public static final DeferredHolder<Potion, Potion> SHORT_SUMMON_1 =
registerSummonPotion("short_summon_1", 6000, 1);
public static final DeferredHolder<Potion, Potion> MEDIUM_SUMMON_1 =
registerSummonPotion("medium_summon_1", 36000, 1);
public static final DeferredHolder<Potion, Potion> LONG_SUMMON_1 =
registerSummonPotion("long_summon_1", 216000, 1);
public static final DeferredHolder<Potion, Potion> SHORT_SUMMON_2 =
registerSummonPotion("short_summon_2", 6000, 2);
public static final DeferredHolder<Potion, Potion> MEDIUM_SUMMON_2 =
registerSummonPotion("medium_summon_2", 36000, 2);
public static final DeferredHolder<Potion, Potion> LONG_SUMMON_2 =
registerSummonPotion("long_summon_2", 216000, 2);
public static final DeferredHolder<Potion, Potion> SHORT_SUMMON_3 =
registerSummonPotion("short_summon_3", 6000, 3);
public static final DeferredHolder<Potion, Potion> MEDIUM_SUMMON_3 =
registerSummonPotion("medium_summon_3", 36000, 3);
public static final DeferredHolder<Potion, Potion> LONG_SUMMON_3 =
registerSummonPotion("long_summon_3", 216000, 3);
public static final DeferredHolder<Potion, Potion> SHORT_SUMMON_4 =
registerSummonPotion("short_summon_4", 6000, 4);
public static final DeferredHolder<Potion, Potion> MEDIUM_SUMMON_4 =
registerSummonPotion("medium_summon_4", 36000, 4);
public static final DeferredHolder<Potion, Potion> LONG_SUMMON_4 =
registerSummonPotion("long_summon_4", 216000, 4);
private static DeferredHolder<Potion, Potion> registerSummonPotion(String name, int duration, int amplifier) {
return POTIONS.register(name, () -> new Potion("summon", new MobEffectInstance(ModEffects.SUMMON, duration, amplifier)));
}
}
@@ -1,10 +1,50 @@
package com.lzxnone.terraria.effect; package com.lzxnone.terraria.effect;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ui.config.ConfigFactory;
import com.lzxnone.terraria.ui.config.ConfigListItem;
import com.lzxnone.terraria.ui.config.ConfigUtil;
import com.lzxnone.terraria.ui.config.IConfigData;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory; import net.minecraft.world.effect.MobEffectCategory;
public class SummonEffect extends MobEffect { public class SummonEffect extends MobEffect {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
public static final String SUMMON_COUNT_PER_LEVEL_PATH = "effect.summon.summon_count_per_level";
public static final int SUMMON_COUNT_PER_LEVEL_DEFAULT = 1;
public static final int SUMMON_COUNT_PER_LEVEL_MIN = 0;
public static final int SUMMON_COUNT_PER_LEVEL_MAX = 10;
public SummonEffect() { public SummonEffect() {
super(MobEffectCategory.BENEFICIAL, 0xF2F7FF); super(MobEffectCategory.BENEFICIAL, 0x34D95A);
} }
public static final IConfigData CONFIG_DATA = new IConfigData() {
@Override
public void onConfigLoad() {
ConfigFactory.loadIntConfig(SUMMON_COUNT_PER_LEVEL_PATH, configText("summon_summon_count_per_level"), configTooltip("summon_summon_count_per_level"), SUMMON_COUNT_PER_LEVEL_DEFAULT, SUMMON_COUNT_PER_LEVEL_MIN, SUMMON_COUNT_PER_LEVEL_MAX);
}
};
private static Component configText(String key) {
return Component.translatable(CONFIG_TRANSLATION_PREFIX + key);
}
private static Component configTooltip(String key) {
return Component.translatable(CONFIG_TRANSLATION_PREFIX + key + ".tooltip");
}
public static int getSummonCountPerLevel() {
return Math.clamp(ConfigUtil.readInt(SUMMON_COUNT_PER_LEVEL_PATH, SUMMON_COUNT_PER_LEVEL_DEFAULT), SUMMON_COUNT_PER_LEVEL_MIN, SUMMON_COUNT_PER_LEVEL_MAX);
}
public static final ConfigListItem CONFIG_LIST_ITEM = new ConfigListItem(
"summon",
ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "textures/mob_effect/summon.png"),
Component.translatable("effect.lzxnoneterraria.summon"),
CONFIG_DATA
);
} }
@@ -0,0 +1,125 @@
package com.lzxnone.terraria.enchantment;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ui.config.ConfigFactory;
import com.lzxnone.terraria.ui.config.ConfigListItem;
import com.lzxnone.terraria.ui.config.ConfigUtil;
import com.lzxnone.terraria.ui.config.IConfigData;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
public class ModEnchantmentConfigs {
private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
private static final ResourceLocation ICON = ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "textures/ui/nav_enchantment_icon.png");
public static final String MANA_LEAK_CONSUME_MULTIPLIER_PATH = "enchantment.mana_leak.consume_multiplier";
public static final double MANA_LEAK_CONSUME_MULTIPLIER_DEFAULT = 1.25D;
public static final double MANA_LEAK_CONSUME_MULTIPLIER_MIN = 0.0D;
public static final double MANA_LEAK_CONSUME_MULTIPLIER_MAX = 10.0D;
public static final String MANA_EFFICIENCY_CONSUME_MULTIPLIER_PATH = "enchantment.mana_efficiency.consume_multiplier";
public static final double MANA_EFFICIENCY_CONSUME_MULTIPLIER_DEFAULT = 0.85D;
public static final double MANA_EFFICIENCY_CONSUME_MULTIPLIER_MIN = 0.0D;
public static final double MANA_EFFICIENCY_CONSUME_MULTIPLIER_MAX = 10.0D;
public static final String MANA_GATHERING_RECOVER_MULTIPLIER_PATH = "enchantment.mana_gathering.recover_multiplier";
public static final double MANA_GATHERING_RECOVER_MULTIPLIER_DEFAULT = 1.25D;
public static final double MANA_GATHERING_RECOVER_MULTIPLIER_MIN = 0.0D;
public static final double MANA_GATHERING_RECOVER_MULTIPLIER_MAX = 10.0D;
public static final String MANA_GATHERING_CURSE_RECOVER_MULTIPLIER_PATH = "enchantment.mana_gathering_curse.recover_multiplier";
public static final double MANA_GATHERING_CURSE_RECOVER_MULTIPLIER_DEFAULT = 0.5D;
public static final double MANA_GATHERING_CURSE_RECOVER_MULTIPLIER_MIN = 0.0D;
public static final double MANA_GATHERING_CURSE_RECOVER_MULTIPLIER_MAX = 10.0D;
public static final String ARCANE_AMPLIFICATION_DAMAGE_MULTIPLIER_PATH = "enchantment.arcane_amplification.damage_multiplier";
public static final double ARCANE_AMPLIFICATION_DAMAGE_MULTIPLIER_DEFAULT = 1.15D;
public static final double ARCANE_AMPLIFICATION_DAMAGE_MULTIPLIER_MIN = 0.0D;
public static final double ARCANE_AMPLIFICATION_DAMAGE_MULTIPLIER_MAX = 10.0D;
public static final String SUMMON_AMPLIFICATION_DAMAGE_MULTIPLIER_PATH = "enchantment.summon_amplification.damage_multiplier";
public static final double SUMMON_AMPLIFICATION_DAMAGE_MULTIPLIER_DEFAULT = 1.15D;
public static final double SUMMON_AMPLIFICATION_DAMAGE_MULTIPLIER_MIN = 0.0D;
public static final double SUMMON_AMPLIFICATION_DAMAGE_MULTIPLIER_MAX = 10.0D;
public static final ConfigListItem MANA_LEAK_CONFIG_LIST_ITEM = createConfigListItem(
"mana_leak",
"enchantment.lzxnoneterraria.mana_leak",
() -> ConfigFactory.loadDoubleConfig(MANA_LEAK_CONSUME_MULTIPLIER_PATH, configText("mana_leak_consume_multiplier"), configTooltip("mana_leak_consume_multiplier"), MANA_LEAK_CONSUME_MULTIPLIER_DEFAULT, MANA_LEAK_CONSUME_MULTIPLIER_MIN, MANA_LEAK_CONSUME_MULTIPLIER_MAX)
);
public static final ConfigListItem MANA_EFFICIENCY_CONFIG_LIST_ITEM = createConfigListItem(
"mana_efficiency",
"enchantment.lzxnoneterraria.mana_efficiency",
() -> ConfigFactory.loadDoubleConfig(MANA_EFFICIENCY_CONSUME_MULTIPLIER_PATH, configText("mana_efficiency_consume_multiplier"), configTooltip("mana_efficiency_consume_multiplier"), MANA_EFFICIENCY_CONSUME_MULTIPLIER_DEFAULT, MANA_EFFICIENCY_CONSUME_MULTIPLIER_MIN, MANA_EFFICIENCY_CONSUME_MULTIPLIER_MAX)
);
public static final ConfigListItem MANA_GATHERING_CONFIG_LIST_ITEM = createConfigListItem(
"mana_gathering",
"enchantment.lzxnoneterraria.mana_gathering",
() -> ConfigFactory.loadDoubleConfig(MANA_GATHERING_RECOVER_MULTIPLIER_PATH, configText("mana_gathering_recover_multiplier"), configTooltip("mana_gathering_recover_multiplier"), MANA_GATHERING_RECOVER_MULTIPLIER_DEFAULT, MANA_GATHERING_RECOVER_MULTIPLIER_MIN, MANA_GATHERING_RECOVER_MULTIPLIER_MAX)
);
public static final ConfigListItem MANA_GATHERING_CURSE_CONFIG_LIST_ITEM = createConfigListItem(
"mana_gathering_curse",
"enchantment.lzxnoneterraria.mana_gathering_curse",
() -> ConfigFactory.loadDoubleConfig(MANA_GATHERING_CURSE_RECOVER_MULTIPLIER_PATH, configText("mana_gathering_curse_recover_multiplier"), configTooltip("mana_gathering_curse_recover_multiplier"), MANA_GATHERING_CURSE_RECOVER_MULTIPLIER_DEFAULT, MANA_GATHERING_CURSE_RECOVER_MULTIPLIER_MIN, MANA_GATHERING_CURSE_RECOVER_MULTIPLIER_MAX)
);
public static final ConfigListItem ARCANE_AMPLIFICATION_CONFIG_LIST_ITEM = createConfigListItem(
"arcane_amplification",
"enchantment.lzxnoneterraria.arcane_amplification",
() -> ConfigFactory.loadDoubleConfig(ARCANE_AMPLIFICATION_DAMAGE_MULTIPLIER_PATH, configText("arcane_amplification_damage_multiplier"), configTooltip("arcane_amplification_damage_multiplier"), ARCANE_AMPLIFICATION_DAMAGE_MULTIPLIER_DEFAULT, ARCANE_AMPLIFICATION_DAMAGE_MULTIPLIER_MIN, ARCANE_AMPLIFICATION_DAMAGE_MULTIPLIER_MAX)
);
public static final ConfigListItem SUMMON_AMPLIFICATION_CONFIG_LIST_ITEM = createConfigListItem(
"summon_amplification",
"enchantment.lzxnoneterraria.summon_amplification",
() -> ConfigFactory.loadDoubleConfig(SUMMON_AMPLIFICATION_DAMAGE_MULTIPLIER_PATH, configText("summon_amplification_damage_multiplier"), configTooltip("summon_amplification_damage_multiplier"), SUMMON_AMPLIFICATION_DAMAGE_MULTIPLIER_DEFAULT, SUMMON_AMPLIFICATION_DAMAGE_MULTIPLIER_MIN, SUMMON_AMPLIFICATION_DAMAGE_MULTIPLIER_MAX)
);
public static double getManaLeakConsumeMultiplier() {
return readDouble(MANA_LEAK_CONSUME_MULTIPLIER_PATH, MANA_LEAK_CONSUME_MULTIPLIER_DEFAULT, MANA_LEAK_CONSUME_MULTIPLIER_MIN, MANA_LEAK_CONSUME_MULTIPLIER_MAX);
}
public static double getManaEfficiencyConsumeMultiplier() {
return readDouble(MANA_EFFICIENCY_CONSUME_MULTIPLIER_PATH, MANA_EFFICIENCY_CONSUME_MULTIPLIER_DEFAULT, MANA_EFFICIENCY_CONSUME_MULTIPLIER_MIN, MANA_EFFICIENCY_CONSUME_MULTIPLIER_MAX);
}
public static double getManaGatheringRecoverMultiplier() {
return readDouble(MANA_GATHERING_RECOVER_MULTIPLIER_PATH, MANA_GATHERING_RECOVER_MULTIPLIER_DEFAULT, MANA_GATHERING_RECOVER_MULTIPLIER_MIN, MANA_GATHERING_RECOVER_MULTIPLIER_MAX);
}
public static double getManaGatheringCurseRecoverMultiplier() {
return readDouble(MANA_GATHERING_CURSE_RECOVER_MULTIPLIER_PATH, MANA_GATHERING_CURSE_RECOVER_MULTIPLIER_DEFAULT, MANA_GATHERING_CURSE_RECOVER_MULTIPLIER_MIN, MANA_GATHERING_CURSE_RECOVER_MULTIPLIER_MAX);
}
public static double getArcaneAmplificationDamageMultiplier() {
return readDouble(ARCANE_AMPLIFICATION_DAMAGE_MULTIPLIER_PATH, ARCANE_AMPLIFICATION_DAMAGE_MULTIPLIER_DEFAULT, ARCANE_AMPLIFICATION_DAMAGE_MULTIPLIER_MIN, ARCANE_AMPLIFICATION_DAMAGE_MULTIPLIER_MAX);
}
public static double getSummonAmplificationDamageMultiplier() {
return readDouble(SUMMON_AMPLIFICATION_DAMAGE_MULTIPLIER_PATH, SUMMON_AMPLIFICATION_DAMAGE_MULTIPLIER_DEFAULT, SUMMON_AMPLIFICATION_DAMAGE_MULTIPLIER_MIN, SUMMON_AMPLIFICATION_DAMAGE_MULTIPLIER_MAX);
}
private static ConfigListItem createConfigListItem(String id, String nameKey, Runnable loader) {
return new ConfigListItem(id, ICON, Component.translatable(nameKey), new IConfigData() {
@Override
public void onConfigLoad() {
loader.run();
}
});
}
private static Component configText(String key) {
return Component.translatable(CONFIG_TRANSLATION_PREFIX + key);
}
private static Component configTooltip(String key) {
return Component.translatable(CONFIG_TRANSLATION_PREFIX + key + ".tooltip");
}
private static double readDouble(String path, double defaultValue, double minValue, double maxValue) {
return Math.clamp(ConfigUtil.readDouble(path, defaultValue), minValue, maxValue);
}
}
@@ -12,6 +12,7 @@ public class ModEnchantments {
public static final ResourceKey<Enchantment> MANA_GATHERING = create("mana_gathering"); public static final ResourceKey<Enchantment> MANA_GATHERING = create("mana_gathering");
public static final ResourceKey<Enchantment> MANA_GATHERING_CURSE = create("mana_gathering_curse"); public static final ResourceKey<Enchantment> MANA_GATHERING_CURSE = create("mana_gathering_curse");
public static final ResourceKey<Enchantment> ARCANE_AMPLIFICATION = create("arcane_amplification"); public static final ResourceKey<Enchantment> ARCANE_AMPLIFICATION = create("arcane_amplification");
public static final ResourceKey<Enchantment> SUMMON_AMPLIFICATION = create("summon_amplification");
private static ResourceKey<Enchantment> create(String name) { private static ResourceKey<Enchantment> create(String name) {
return ResourceKey.create( return ResourceKey.create(
@@ -1,18 +1,6 @@
package com.lzxnone.terraria.entity.beam; package com.lzxnone.terraria.entity.beam;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.summon.StaticSummon;
import com.lzxnone.terraria.utils.MathUtil;
import com.lzxnone.terraria.utils.RenderUtil;
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.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@@ -23,161 +11,14 @@ import net.minecraft.world.item.Items;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f; import org.joml.Vector3f;
public interface ISwordBeamBehavior { 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) return;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(beam.getOwner());
dirs = MathUtil.rotateCoordinateSystem(dirs[0], dirs[2], beam.getEntityData().get(SwordBeam.ROTATE));
float rotate = beam.getEntityData().get(SwordBeam.ROTATE);
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;
}
if(beam.getEntityData().get(SwordBeam.RIGHT)) progress = 1.0f - progress;
float halfWidth = SwordBeam.HALF_WIDTH * SwordBeam.SCALE;
float halfHeight = SwordBeam.HALF_HEIGHT * SwordBeam.SCALE;
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES0));
//左边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress - 0.1f * (1.0f - progress)) * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress - 0.1f * (1.0f - progress))) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color0.x(), color0.y(), color0.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.01f);
poseStack.popPose();
//右边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.1f) * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress + 0.05f)) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color2.x(), color2.y(), color2.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.02f);
poseStack.popPose();
//中间
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], progress * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color1.x(), color1.y(), color1.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0f);
poseStack.popPose();
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES3));
//三线
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.05f) * 180, SwordBeam.DIST / 1.5f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(0.5f, 0.5f, 0.5f);
renderQuad(poseStack.last().pose(), vertexConsumer1,
color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.02f);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.05f) * 180, SwordBeam.DIST / 1.25f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(0.75f, 0.75f, 0.75f);
renderQuad(poseStack.last().pose(), vertexConsumer1,
color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.02f);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], progress * 180, SwordBeam.DIST * 1.15f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(0.95f, 0.95f, 0.95f);
renderQuad(poseStack.last().pose(), vertexConsumer1,
color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.02f);
poseStack.popPose();
VertexConsumer vertexConsumer2 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES4));
//边缘高光
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.05f) * 180, SwordBeam.DIST * 1.15f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress - 0.05f) * 180, rotate);
poseStack.scale(1.0f, 1.0f, 1.0f);
for(int i = 0;i < 20;i++) {
renderQuad(poseStack.last().pose(), vertexConsumer2,
color1.x(), color1.y(), color1.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.03f);
}
poseStack.popPose();
VertexConsumer vertexConsumer3 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES5));
//闪烁
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.25f) * 180, SwordBeam.DIST * 2.25f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress - 0.25f) * 180, rotate);
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(), vertexConsumer3,
color1.x(), color1.y(), color1.z(), alpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.03f);
}
poseStack.popPose();
}
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) { default void generate(Entity entity, CompoundTag beamData) {
if(entity == null) return; if(entity == null) return;
SwordBeam beam = new SwordBeam(ModEntities.SWORD_BEAM.get(), entity.level()); SwordBeam beam = new SwordBeam(ModEntities.SWORD_BEAM.get(), entity.level());
beam.setOwner(entity); beam.setOwner(entity);
if(entity instanceof Player player) beam.getEntityData().set(SwordBeam.STACK_SOURCE, player.getWeaponItem().copy());
Vec3 pos = new Vec3(entity.getX(), entity.getY() + entity.getBbHeight() / 2, entity.getZ()); Vec3 pos = new Vec3(entity.getX(), entity.getY() + entity.getBbHeight() / 2, entity.getZ());
beam.setPos(pos); beam.setPos(pos);
if(beamData.contains("behavior")) beam.getEntityData().set(SwordBeam.BEHAVIOR, beamData.getString("behavior")); if(beamData.contains("behavior")) beam.getEntityData().set(SwordBeam.BEHAVIOR, beamData.getString("behavior"));
@@ -9,6 +9,7 @@ import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.*; import net.minecraft.world.phys.*;
@@ -48,6 +49,8 @@ public class SwordBeam extends Entity {
SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.INT); SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> LIFETIME = public static final EntityDataAccessor<Integer> LIFETIME =
SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.INT); SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<ItemStack> STACK_SOURCE =
SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.ITEM_STACK);
public static final EntityDataAccessor<Optional<UUID>> OWNER = public static final EntityDataAccessor<Optional<UUID>> OWNER =
SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.OPTIONAL_UUID); SynchedEntityData.defineId(SwordBeam.class, EntityDataSerializers.OPTIONAL_UUID);
@@ -203,6 +206,7 @@ public class SwordBeam extends Entity {
builder.define(COLOR3, 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(AGE, 0);
builder.define(LIFETIME, 10); builder.define(LIFETIME, 10);
builder.define(STACK_SOURCE, ItemStack.EMPTY);
builder.define(OWNER, Optional.empty()); builder.define(OWNER, Optional.empty());
builder.define(CUSTOM_DATA, new CompoundTag()); builder.define(CUSTOM_DATA, new CompoundTag());
} }
@@ -232,6 +236,8 @@ public class SwordBeam extends Entity {
tag.putFloat("color3B", c3.z); tag.putFloat("color3B", c3.z);
tag.putInt("age", this.entityData.get(AGE)); tag.putInt("age", this.entityData.get(AGE));
tag.putInt("lifetime", this.entityData.get(LIFETIME)); tag.putInt("lifetime", this.entityData.get(LIFETIME));
ItemStack stackSource = this.entityData.get(STACK_SOURCE);
if(!stackSource.isEmpty()) tag.put("stackSource", stackSource.save(this.level().registryAccess()));
if(getOwner() != null) tag.putUUID("owner", getOwner().getUUID()); if(getOwner() != null) tag.putUUID("owner", getOwner().getUUID());
tag.put("customData", this.entityData.get(CUSTOM_DATA)); tag.put("customData", this.entityData.get(CUSTOM_DATA));
} }
@@ -265,6 +271,10 @@ public class SwordBeam extends Entity {
} }
if(tag.contains("age")) this.entityData.set(AGE, tag.getInt("age")); 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("lifetime")) this.entityData.set(LIFETIME, tag.getInt("lifetime"));
if(tag.contains("stackSource")) {
ItemStack.parse(this.level().registryAccess(), tag.getCompound("stackSource"))
.ifPresent(stack -> this.entityData.set(STACK_SOURCE, stack));
}
if(tag.contains("owner")) { if(tag.contains("owner")) {
this.entityData.set(OWNER, Optional.of(tag.getUUID("owner"))); this.entityData.set(OWNER, Optional.of(tag.getUUID("owner")));
getOwner(); getOwner();
@@ -1,148 +1,9 @@
package com.lzxnone.terraria.entity.projectile; 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.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult; 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 { 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.computeCoordinateSystem(velForRot, 0);
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.computeCoordinateSystem(velForRot, 0);
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 onMoving(StaticProjectile projectile) {}
default void onHitEntity(StaticProjectile projectile, EntityHitResult result) {} default void onHitEntity(StaticProjectile projectile, EntityHitResult result) {}
default void onHitBlock(StaticProjectile projectile, BlockHitResult result) {} default void onHitBlock(StaticProjectile projectile, BlockHitResult result) {}
@@ -28,6 +28,8 @@ public class StaticProjectile extends Projectile {
SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.STRING); SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.STRING);
public static final EntityDataAccessor<ItemStack> ITEM = public static final EntityDataAccessor<ItemStack> ITEM =
SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.ITEM_STACK); SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.ITEM_STACK);
public static final EntityDataAccessor<ItemStack> STACK_SOURCE =
SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.ITEM_STACK);
public static final EntityDataAccessor<BlockState> BLOCK = public static final EntityDataAccessor<BlockState> BLOCK =
SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.BLOCK_STATE); SynchedEntityData.defineId(StaticProjectile.class, EntityDataSerializers.BLOCK_STATE);
public static final EntityDataAccessor<Vector3f> ORIGIN = public static final EntityDataAccessor<Vector3f> ORIGIN =
@@ -109,6 +111,7 @@ public class StaticProjectile extends Projectile {
builder.define(BEHAVIOR, "default"); builder.define(BEHAVIOR, "default");
builder.define(RENDER_MODE, "custom"); builder.define(RENDER_MODE, "custom");
builder.define(ITEM, ItemStack.EMPTY); builder.define(ITEM, ItemStack.EMPTY);
builder.define(STACK_SOURCE, ItemStack.EMPTY);
builder.define(BLOCK, Blocks.AIR.defaultBlockState()); builder.define(BLOCK, Blocks.AIR.defaultBlockState());
builder.define(ORIGIN, new Vector3f(0, 0, 0)); builder.define(ORIGIN, new Vector3f(0, 0, 0));
builder.define(DIRECTION, new Vector3f(0, 0, 1)); builder.define(DIRECTION, new Vector3f(0, 0, 1));
@@ -200,6 +203,8 @@ public class StaticProjectile extends Projectile {
tag.putString("renderMode", this.entityData.get(RENDER_MODE)); tag.putString("renderMode", this.entityData.get(RENDER_MODE));
ItemStack stack = this.entityData.get(ITEM); ItemStack stack = this.entityData.get(ITEM);
if(!stack.isEmpty()) tag.put("item", stack.save(this.level().registryAccess())); if(!stack.isEmpty()) tag.put("item", stack.save(this.level().registryAccess()));
ItemStack stackSource = this.entityData.get(STACK_SOURCE);
if(!stackSource.isEmpty()) tag.put("stackSource", stackSource.save(this.level().registryAccess()));
tag.put("block", NbtUtils.writeBlockState(this.entityData.get(BLOCK))); tag.put("block", NbtUtils.writeBlockState(this.entityData.get(BLOCK)));
tag.putFloat("originX", this.entityData.get(ORIGIN).x); tag.putFloat("originX", this.entityData.get(ORIGIN).x);
tag.putFloat("originY", this.entityData.get(ORIGIN).y); tag.putFloat("originY", this.entityData.get(ORIGIN).y);
@@ -244,6 +249,10 @@ public class StaticProjectile extends Projectile {
ItemStack.parse(this.level().registryAccess(), tag.getCompound("item")) ItemStack.parse(this.level().registryAccess(), tag.getCompound("item"))
.ifPresent(stack -> this.entityData.set(ITEM, stack)); .ifPresent(stack -> this.entityData.set(ITEM, stack));
} }
if(tag.contains("stackSource")) {
ItemStack.parse(this.level().registryAccess(), tag.getCompound("stackSource"))
.ifPresent(stack -> this.entityData.set(STACK_SOURCE, stack));
}
if(tag.contains("block")) { if(tag.contains("block")) {
BlockState blockState = NbtUtils.readBlockState( BlockState blockState = NbtUtils.readBlockState(
this.level().holderLookup(Registries.BLOCK), this.level().holderLookup(Registries.BLOCK),
@@ -1,48 +0,0 @@
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.core.BlockPos;
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<Entity> {
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);
}
*/
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.RENDER_MODE).equals("custom")) {
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;
}
}
@@ -17,6 +17,7 @@ import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.animal.Bee; import net.minecraft.world.entity.animal.Bee;
import net.minecraft.world.entity.monster.Monster; import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -34,6 +35,7 @@ public class BeeSummon extends Bee {
public int customAttackCount = 0; public int customAttackCount = 0;
public LivingEntity owner = null; public LivingEntity owner = null;
public ItemStack stackSource = ItemStack.EMPTY;
public BeeSummon(EntityType<? extends Bee> entityType, Level level) { public BeeSummon(EntityType<? extends Bee> entityType, Level level) {
super(entityType, level); super(entityType, level);
@@ -123,8 +125,8 @@ public class BeeSummon extends Bee {
public boolean doHurtTarget(Entity target) { public boolean doHurtTarget(Entity target) {
if(owner == null) return false; if(owner == null) return false;
boolean isHurt; boolean isHurt;
if(owner instanceof Player player) { if(owner instanceof Player) {
isHurt = DamageUtil.normalAttack(this, target, (float) BeeKeeper.getBeeDamage(), 1.0f); isHurt = DamageUtil.meleeAttack(this, target, stackSource, (float) BeeKeeper.getBeeDamage(), 1.0f);
}else { }else {
DamageSource damageSource = this.damageSources().mobAttack(owner); DamageSource damageSource = this.damageSources().mobAttack(owner);
isHurt = target.hurt(damageSource, (float) BeeKeeper.getBeeDamage()); isHurt = target.hurt(damageSource, (float) BeeKeeper.getBeeDamage());
@@ -172,6 +174,7 @@ public class BeeSummon extends Bee {
tag.putInt("customAttackCount", this.customAttackCount); tag.putInt("customAttackCount", this.customAttackCount);
tag.putInt("customAge", this.customAge); tag.putInt("customAge", this.customAge);
if(this.owner != null) tag.putUUID("owner", this.owner.getUUID()); if(this.owner != null) tag.putUUID("owner", this.owner.getUUID());
if(!this.stackSource.isEmpty()) tag.put("stackSource", this.stackSource.save(this.level().registryAccess()));
} }
@Override @Override
@@ -183,6 +186,10 @@ public class BeeSummon extends Bee {
Entity entity = level.getEntity(tag.getUUID("owner")); Entity entity = level.getEntity(tag.getUUID("owner"));
if(entity instanceof LivingEntity livingEntity) this.owner = livingEntity; if(entity instanceof LivingEntity livingEntity) this.owner = livingEntity;
} }
if(tag.contains("stackSource")) {
ItemStack.parse(this.level().registryAccess(), tag.getCompound("stackSource"))
.ifPresent(stack -> this.stackSource = stack);
}
} }
} }
@@ -1,117 +1,8 @@
package com.lzxnone.terraria.entity.summon; 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 net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import java.util.UUID;
public interface IStaticSummonBehavior { 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) { default void checkBeforeTick(StaticSummon summon) {
if(summon.level().isClientSide()) return; if(summon.level().isClientSide()) return;
if(summon.getOwner() == null || !summon.getOwner().isAlive()) { if(summon.getOwner() == null || !summon.getOwner().isAlive()) {
@@ -9,6 +9,7 @@ import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
@@ -26,6 +27,8 @@ public class StaticSummon extends Entity {
SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.STRING); SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.STRING);
public static final EntityDataAccessor<ItemStack> ITEM = public static final EntityDataAccessor<ItemStack> ITEM =
SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.ITEM_STACK); SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.ITEM_STACK);
public static final EntityDataAccessor<ItemStack> STACK_SOURCE =
SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.ITEM_STACK);
public static final EntityDataAccessor<BlockState> BLOCK = public static final EntityDataAccessor<BlockState> BLOCK =
SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.BLOCK_STATE); SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.BLOCK_STATE);
public static final EntityDataAccessor<Float> SCALE_X = public static final EntityDataAccessor<Float> SCALE_X =
@@ -111,6 +114,7 @@ public class StaticSummon extends Entity {
builder.define(BEHAVIOR, "default"); builder.define(BEHAVIOR, "default");
builder.define(RENDER_MODE, "custom"); builder.define(RENDER_MODE, "custom");
builder.define(ITEM, ItemStack.EMPTY); builder.define(ITEM, ItemStack.EMPTY);
builder.define(STACK_SOURCE, ItemStack.EMPTY);
builder.define(BLOCK, Blocks.AIR.defaultBlockState()); builder.define(BLOCK, Blocks.AIR.defaultBlockState());
builder.define(SCALE_X, 1.0f); builder.define(SCALE_X, 1.0f);
builder.define(SCALE_Y, 1.0f); builder.define(SCALE_Y, 1.0f);
@@ -138,7 +142,8 @@ public class StaticSummon extends Entity {
super.tick(); super.tick();
this.owner = getOwner(); this.owner = getOwner();
StaticSummonBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).tick(this); StaticSummonBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).tick(this);
this.setPos(this.position().add(this.getDeltaMovement())); //this.setPos(this.position().add(this.getDeltaMovement()));
this.move(MoverType.SELF, this.getDeltaMovement());
} }
@Override @Override
@@ -147,6 +152,8 @@ public class StaticSummon extends Entity {
tag.putString("renderMode", this.entityData.get(RENDER_MODE)); tag.putString("renderMode", this.entityData.get(RENDER_MODE));
ItemStack stack = this.entityData.get(ITEM); ItemStack stack = this.entityData.get(ITEM);
if(!stack.isEmpty()) tag.put("item", stack.save(this.level().registryAccess())); if(!stack.isEmpty()) tag.put("item", stack.save(this.level().registryAccess()));
ItemStack stackSource = this.entityData.get(STACK_SOURCE);
if(!stackSource.isEmpty()) tag.put("stackSource", stackSource.save(this.level().registryAccess()));
tag.put("block", NbtUtils.writeBlockState(this.entityData.get(BLOCK))); tag.put("block", NbtUtils.writeBlockState(this.entityData.get(BLOCK)));
tag.putFloat("scaleX", this.entityData.get(SCALE_X)); tag.putFloat("scaleX", this.entityData.get(SCALE_X));
tag.putFloat("scaleY", this.entityData.get(SCALE_Y)); tag.putFloat("scaleY", this.entityData.get(SCALE_Y));
@@ -177,6 +184,10 @@ public class StaticSummon extends Entity {
ItemStack.parse(this.level().registryAccess(), tag.getCompound("item")) ItemStack.parse(this.level().registryAccess(), tag.getCompound("item"))
.ifPresent(stack -> this.entityData.set(ITEM, stack)); .ifPresent(stack -> this.entityData.set(ITEM, stack));
} }
if(tag.contains("stackSource")) {
ItemStack.parse(this.level().registryAccess(), tag.getCompound("stackSource"))
.ifPresent(stack -> this.entityData.set(STACK_SOURCE, stack));
}
if(tag.contains("block")) { if(tag.contains("block")) {
BlockState blockState = NbtUtils.readBlockState( BlockState blockState = NbtUtils.readBlockState(
this.level().holderLookup(Registries.BLOCK), this.level().holderLookup(Registries.BLOCK),
@@ -0,0 +1,35 @@
package com.lzxnone.terraria.event;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.effect.ModPotions;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.alchemy.Potions;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.brewing.RegisterBrewingRecipesEvent;
@EventBusSubscriber(modid = LzxnoneTerraria.MODID)
public class BrewingRecipeHandler {
@SubscribeEvent
public static void onRegisterBrewingRecipes(RegisterBrewingRecipesEvent event) {
event.getBuilder().addMix(Potions.AWKWARD, Items.NETHERITE_SCRAP, ModPotions.SHORT_SUMMON_0);
event.getBuilder().addMix(ModPotions.SHORT_SUMMON_0, Items.NETHERITE_SCRAP, ModPotions.MEDIUM_SUMMON_0);
event.getBuilder().addMix(ModPotions.MEDIUM_SUMMON_0, Items.NETHERITE_SCRAP, ModPotions.LONG_SUMMON_0);
event.getBuilder().addMix(ModPotions.LONG_SUMMON_0, Items.NETHERITE_INGOT, ModPotions.SHORT_SUMMON_1);
event.getBuilder().addMix(ModPotions.SHORT_SUMMON_1, Items.NETHERITE_SCRAP, ModPotions.MEDIUM_SUMMON_1);
event.getBuilder().addMix(ModPotions.MEDIUM_SUMMON_1, Items.NETHERITE_SCRAP, ModPotions.LONG_SUMMON_1);
event.getBuilder().addMix(ModPotions.LONG_SUMMON_1, Items.NETHERITE_INGOT, ModPotions.SHORT_SUMMON_2);
event.getBuilder().addMix(ModPotions.SHORT_SUMMON_2, Items.NETHERITE_SCRAP, ModPotions.MEDIUM_SUMMON_2);
event.getBuilder().addMix(ModPotions.MEDIUM_SUMMON_2, Items.NETHERITE_SCRAP, ModPotions.LONG_SUMMON_2);
event.getBuilder().addMix(ModPotions.LONG_SUMMON_2, Items.NETHERITE_INGOT, ModPotions.SHORT_SUMMON_3);
event.getBuilder().addMix(ModPotions.SHORT_SUMMON_3, Items.NETHERITE_SCRAP, ModPotions.MEDIUM_SUMMON_3);
event.getBuilder().addMix(ModPotions.MEDIUM_SUMMON_3, Items.NETHERITE_SCRAP, ModPotions.LONG_SUMMON_3);
event.getBuilder().addMix(ModPotions.LONG_SUMMON_3, Items.NETHERITE_BLOCK, ModPotions.SHORT_SUMMON_4);
event.getBuilder().addMix(ModPotions.SHORT_SUMMON_4, Items.NETHERITE_SCRAP, ModPotions.MEDIUM_SUMMON_4);
event.getBuilder().addMix(ModPotions.MEDIUM_SUMMON_4, Items.NETHERITE_SCRAP, ModPotions.LONG_SUMMON_4);
}
}
@@ -1,6 +1,7 @@
package com.lzxnone.terraria.item.weapon; package com.lzxnone.terraria.item.weapon;
import com.lzxnone.terraria.enchantment.ModEnchantments; import com.lzxnone.terraria.enchantment.ModEnchantments;
import com.lzxnone.terraria.enchantment.ModEnchantmentConfigs;
import net.minecraft.core.component.DataComponents; import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
@@ -8,7 +9,6 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.component.CustomData; import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier; import net.minecraft.world.item.Tier;
import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.item.enchantment.Enchantment;
@@ -17,16 +17,10 @@ import net.minecraft.world.level.Level;
import java.util.function.IntSupplier; import java.util.function.IntSupplier;
public class MagicWeapon extends Item { public class MagicWeapon extends Weapon {
private static final String MANA_CONSUME_PROGRESS_KEY = "magicManaConsumeProgress"; private static final String MANA_CONSUME_PROGRESS_KEY = "magicManaConsumeProgress";
private static final String MANA_RECOVER_PROGRESS_KEY = "magicManaRecoverProgress"; private static final String MANA_RECOVER_PROGRESS_KEY = "magicManaRecoverProgress";
private static final double MANA_LEAK_CONSUME_MULTIPLIER = 1.25D;
private static final double MANA_EFFICIENCY_CONSUME_MULTIPLIER = 0.85D;
private static final double MANA_GATHERING_RECOVER_MULTIPLIER = 1.25D;
private static final double MANA_GATHERING_CURSE_RECOVER_MULTIPLIER = 0.5D;
private static final double ARCANE_AMPLIFICATION_DAMAGE_MULTIPLIER = 1.15D;
private final int enchantmentValue;
private final IntSupplier manaConsumeRate; private final IntSupplier manaConsumeRate;
private final IntSupplier manaRecoverRate; private final IntSupplier manaRecoverRate;
@@ -35,15 +29,13 @@ public class MagicWeapon extends Item {
} }
public MagicWeapon(Tier tier, Properties properties, IntSupplier manaConsumeRate, IntSupplier manaRecoverRate) { public MagicWeapon(Tier tier, Properties properties, IntSupplier manaConsumeRate, IntSupplier manaRecoverRate) {
super(properties.durability(tier.getUses())); super(tier, properties);
this.enchantmentValue = tier.getEnchantmentValue();
this.manaConsumeRate = manaConsumeRate; this.manaConsumeRate = manaConsumeRate;
this.manaRecoverRate = manaRecoverRate; this.manaRecoverRate = manaRecoverRate;
} }
public MagicWeapon(Properties properties) { public MagicWeapon(Properties properties) {
super(properties); super(properties);
this.enchantmentValue = 0;
this.manaConsumeRate = () -> 1; this.manaConsumeRate = () -> 1;
this.manaRecoverRate = () -> 1; this.manaRecoverRate = () -> 1;
} }
@@ -90,8 +82,8 @@ public class MagicWeapon extends Item {
int leakLevel = getEnchantmentLevel(entity, stack, ModEnchantments.MANA_LEAK); int leakLevel = getEnchantmentLevel(entity, stack, ModEnchantments.MANA_LEAK);
int efficiencyLevel = getEnchantmentLevel(entity, stack, ModEnchantments.MANA_EFFICIENCY); int efficiencyLevel = getEnchantmentLevel(entity, stack, ModEnchantments.MANA_EFFICIENCY);
rate *= Math.pow(MANA_LEAK_CONSUME_MULTIPLIER, leakLevel); rate *= Math.pow(ModEnchantmentConfigs.getManaLeakConsumeMultiplier(), leakLevel);
rate *= Math.pow(MANA_EFFICIENCY_CONSUME_MULTIPLIER, efficiencyLevel); rate *= Math.pow(ModEnchantmentConfigs.getManaEfficiencyConsumeMultiplier(), efficiencyLevel);
return Math.max(0.0D, rate); return Math.max(0.0D, rate);
} }
@@ -100,8 +92,8 @@ public class MagicWeapon extends Item {
int gatheringLevel = getEnchantmentLevel(entity, stack, ModEnchantments.MANA_GATHERING); int gatheringLevel = getEnchantmentLevel(entity, stack, ModEnchantments.MANA_GATHERING);
int curseLevel = getEnchantmentLevel(entity, stack, ModEnchantments.MANA_GATHERING_CURSE); int curseLevel = getEnchantmentLevel(entity, stack, ModEnchantments.MANA_GATHERING_CURSE);
rate *= Math.pow(MANA_GATHERING_RECOVER_MULTIPLIER, gatheringLevel); rate *= Math.pow(ModEnchantmentConfigs.getManaGatheringRecoverMultiplier(), gatheringLevel);
rate *= Math.pow(MANA_GATHERING_CURSE_RECOVER_MULTIPLIER, curseLevel); rate *= Math.pow(ModEnchantmentConfigs.getManaGatheringCurseRecoverMultiplier(), curseLevel);
return Math.max(0.0D, rate); return Math.max(0.0D, rate);
} }
@@ -109,7 +101,7 @@ public class MagicWeapon extends Item {
double finalDamage = damage; double finalDamage = damage;
int amplificationLevel = getEnchantmentLevel(entity, stack, ModEnchantments.ARCANE_AMPLIFICATION); int amplificationLevel = getEnchantmentLevel(entity, stack, ModEnchantments.ARCANE_AMPLIFICATION);
finalDamage *= Math.pow(ARCANE_AMPLIFICATION_DAMAGE_MULTIPLIER, amplificationLevel); finalDamage *= Math.pow(ModEnchantmentConfigs.getArcaneAmplificationDamageMultiplier(), amplificationLevel);
return (float) Math.max(0.0D, finalDamage); return (float) Math.max(0.0D, finalDamage);
} }
@@ -165,13 +157,4 @@ public class MagicWeapon extends Item {
.orElse(0); .orElse(0);
} }
@Override
public boolean isEnchantable(ItemStack stack) {
return stack.getMaxStackSize() == 1;
}
@Override
public int getEnchantmentValue(ItemStack stack) {
return enchantmentValue;
}
} }
@@ -1,31 +1,13 @@
package com.lzxnone.terraria.item.weapon; package com.lzxnone.terraria.item.weapon;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier; import net.minecraft.world.item.Tier;
public class MeleeWeapon extends Item { public class MeleeWeapon extends Weapon {
private final int enchantmentValue;
public MeleeWeapon(Tier tier, Properties properties) { public MeleeWeapon(Tier tier, Properties properties) {
super(properties.durability(tier.getUses())); super(tier, properties);
this.enchantmentValue = tier.getEnchantmentValue();
} }
public MeleeWeapon(Properties properties) { public MeleeWeapon(Properties properties) {
super(properties); super(properties);
this.enchantmentValue = 0;
}
@Override
public boolean isEnchantable(ItemStack stack) {
return stack.getMaxStackSize() == 1;
}
@Override
public int getEnchantmentValue(ItemStack stack) {
return enchantmentValue;
} }
} }
@@ -1,4 +1,13 @@
package com.lzxnone.terraria.item.weapon; package com.lzxnone.terraria.item.weapon;
public class RangedWeapon { import net.minecraft.world.item.Tier;
public class RangedWeapon extends Weapon {
public RangedWeapon(Tier tier, Properties properties) {
super(tier, properties);
}
public RangedWeapon(Properties properties) {
super(properties);
}
} }
@@ -2,45 +2,48 @@ package com.lzxnone.terraria.item.weapon;
import com.lzxnone.terraria.attachment.ModAttachments; import com.lzxnone.terraria.attachment.ModAttachments;
import com.lzxnone.terraria.effect.ModEffects; import com.lzxnone.terraria.effect.ModEffects;
import com.lzxnone.terraria.effect.SummonEffect;
import com.lzxnone.terraria.enchantment.ModEnchantments;
import com.lzxnone.terraria.enchantment.ModEnchantmentConfigs;
import com.lzxnone.terraria.entity.summon.StaticSummon; import com.lzxnone.terraria.entity.summon.StaticSummon;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier; import net.minecraft.world.item.Tier;
import net.minecraft.world.item.enchantment.Enchantment;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
public class SummonWeapon extends Item { public class SummonWeapon extends Weapon {
private final int enchantmentValue; private static final double MAX_RANGE = 256;
public SummonWeapon(Tier tier, Properties properties) { public SummonWeapon(Tier tier, Properties properties) {
super(properties.durability(tier.getUses())); super(tier, properties);
this.enchantmentValue = tier.getEnchantmentValue();
} }
public SummonWeapon(Properties properties) { public SummonWeapon(Properties properties) {
super(properties); super(properties);
this.enchantmentValue = 0;
}
@Override
public boolean isEnchantable(ItemStack stack) {
return stack.getMaxStackSize() == 1;
}
@Override
public int getEnchantmentValue(ItemStack stack) {
return enchantmentValue;
} }
public static int getMaxSummonCount(Player player) { public static int getMaxSummonCount(Player player) {
MobEffectInstance instance = player.getEffect(ModEffects.SUMMON); MobEffectInstance instance = player.getEffect(ModEffects.SUMMON);
return 1 + (instance == null ? 0 : instance.getAmplifier() + 1); return 1 + (instance == null ? 0 : (instance.getAmplifier() + 1) * SummonEffect.getSummonCountPerLevel());
}
public static float applySummonDamageBonus(ItemStack stack, LivingEntity entity, float damage) {
double finalDamage = damage;
int amplificationLevel = getEnchantmentLevel(entity, stack, ModEnchantments.SUMMON_AMPLIFICATION);
finalDamage *= Math.pow(ModEnchantmentConfigs.getSummonAmplificationDamageMultiplier(), amplificationLevel);
return (float)Math.max(0.0D, finalDamage);
} }
public static List<UUID> getSummons(Player player) { public static List<UUID> getSummons(Player player) {
@@ -57,7 +60,7 @@ public class SummonWeapon extends Item {
Entity owner = summon1.getOwner(); Entity owner = summon1.getOwner();
if(owner != null) { if(owner != null) {
double dist = owner.position().subtract(summon.position()).length(); double dist = owner.position().subtract(summon.position()).length();
if(dist > 256) return true; if(dist > MAX_RANGE) return true;
}else return true; }else return true;
} }
return entity == null || !entity.isAlive(); return entity == null || !entity.isAlive();
@@ -72,6 +75,10 @@ public class SummonWeapon extends Item {
summons.add(summon.getUUID()); summons.add(summon.getUUID());
player.setData(ModAttachments.SUMMON_WEAPON_SUMMONS, summons); player.setData(ModAttachments.SUMMON_WEAPON_SUMMONS, summons);
player.displayClientMessage(
Component.translatable("message.lzxnoneterraria.current_summons", summons.size(), maxSummonCount),
true
);
} }
public static void addFreshSummon(Player player, Entity summon) { public static void addFreshSummon(Player player, Entity summon) {
@@ -89,4 +96,12 @@ public class SummonWeapon extends Item {
public String getSummonId() { public String getSummonId() {
return ""; return "";
} }
private static int getEnchantmentLevel(LivingEntity entity, ItemStack stack, ResourceKey<Enchantment> enchantment) {
return entity.registryAccess()
.lookupOrThrow(Registries.ENCHANTMENT)
.get(enchantment)
.map(stack::getEnchantmentLevel)
.orElse(0);
}
} }
@@ -0,0 +1,38 @@
package com.lzxnone.terraria.item.weapon;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
public class Weapon extends Item {
private final int enchantmentValue;
public Weapon(Tier tier, Properties properties) {
super(properties.durability(tier.getUses()));
this.enchantmentValue = tier.getEnchantmentValue();
}
public Weapon(Properties properties) {
super(properties);
this.enchantmentValue = 0;
}
@Override
public boolean canAttackBlock(BlockState state, Level level, BlockPos pos, Player player) {
return false;
}
@Override
public boolean isEnchantable(ItemStack stack) {
return stack.getMaxStackSize() == 1;
}
@Override
public int getEnchantmentValue(ItemStack stack) {
return enchantmentValue;
}
}
@@ -3,7 +3,6 @@ package com.lzxnone.terraria.item.weapon.magic;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds; import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior; import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior;
import com.lzxnone.terraria.entity.summon.StaticSummon; import com.lzxnone.terraria.entity.summon.StaticSummon;
import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors; import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors;
@@ -20,12 +19,7 @@ import com.lzxnone.terraria.utils.FilterUtil;
import com.lzxnone.terraria.utils.MathUtil; import com.lzxnone.terraria.utils.MathUtil;
import com.lzxnone.terraria.utils.ParticleUtil; import com.lzxnone.terraria.utils.ParticleUtil;
import com.lzxnone.terraria.utils.SoundUtil; import com.lzxnone.terraria.utils.SoundUtil;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@@ -47,7 +41,6 @@ import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.joml.Matrix4f;
import org.joml.Quaternionf; import org.joml.Quaternionf;
import org.joml.Vector3f; import org.joml.Vector3f;
import org.jspecify.annotations.NonNull; import org.jspecify.annotations.NonNull;
@@ -180,47 +173,6 @@ public class LastPrism extends MagicWeapon {
}; };
public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() { 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;
Entity owner = summon.getOwner();
if(owner == null) return;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(owner);
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
float time = summon.getEntityData().get(StaticSummon.AGE) + partialTick;
float size = 0.35F;
float hue = (time * 0.02F) % 1.0F;
float baseZ = -size / 3.0F;
float baseRadius = size * 2.0F * Mth.sqrt(2.0F) / 3.0F;
Vec3 v0 = new Vec3(0.0D, 0.0D, size);
Vec3 v1 = new Vec3(baseRadius, 0.0D, baseZ);
Vec3 v2 = new Vec3(baseRadius * Math.cos(Math.toRadians(120.0D)), baseRadius * Math.sin(Math.toRadians(120.0D)), baseZ);
Vec3 v3 = new Vec3(baseRadius * Math.cos(Math.toRadians(240.0D)), baseRadius * Math.sin(Math.toRadians(240.0D)), baseZ);
poseStack.pushPose();
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.ZP.rotationDegrees(computePrismAngle(time)));
Matrix4f matrix = poseStack.last().pose();
VertexConsumer innerConsumer = bufferSource.getBuffer(ModRenderTypes.entitySolidEmissiveTriangles(RES));
renderTetrahedronFace(innerConsumer, matrix, v0, v1, v2, 1.0F, 1.0F, 1.0F, 0.5f);
renderTetrahedronFace(innerConsumer, matrix, v0, v3, v1, 1.0F, 1.0F, 1.0F, 0.5f);
renderTetrahedronFace(innerConsumer, matrix, v0, v2, v3, 1.0F, 1.0F, 1.0F, 0.5f);
renderTetrahedronFace(innerConsumer, matrix, v1, v3, v2, 1.0F, 1.0F, 1.0F, 0.5f);
float outerScale = 1.2F;
VertexConsumer outerConsumer = bufferSource.getBuffer(ModRenderTypes.entitySolidEmissiveTriangles(RES));
renderTetrahedronFace(outerConsumer, matrix, v0.scale(outerScale), v1.scale(outerScale), v2.scale(outerScale), hue);
renderTetrahedronFace(outerConsumer, matrix, v0.scale(outerScale), v3.scale(outerScale), v1.scale(outerScale), hue + 0.25F);
renderTetrahedronFace(outerConsumer, matrix, v0.scale(outerScale), v2.scale(outerScale), v3.scale(outerScale), hue + 0.50F);
renderTetrahedronFace(outerConsumer, matrix, v1.scale(outerScale), v3.scale(outerScale), v2.scale(outerScale), hue + 0.75F);
poseStack.popPose();
}
@Override @Override
public void tick(StaticSummon summon) { public void tick(StaticSummon summon) {
@@ -249,26 +201,6 @@ public class LastPrism extends MagicWeapon {
}; };
public static final IStaticSummonBehavior SUMMON_BEHAVIOR2 = new IStaticSummonBehavior() { public static final IStaticSummonBehavior SUMMON_BEHAVIOR2 = new IStaticSummonBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon beam)) return;
if(!(beam.getOwner() instanceof StaticSummon tri)) return;
BeamData beamData = computeBeamData(tri, getBeamIndex(beam), partialTick);
if(beamData == null) return;
VertexConsumer consumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES));
Matrix4f matrix = poseStack.last().pose();
List<Vec3> points = List.of(beamData.start(), beamData.end());
renderTube(consumer, matrix, beam.position(),
points, beamData.radius() * 0.8f, 1.0f, 1.0f, 1.0f, 1.0f, false);
renderTube(consumer, matrix, beam.position(),
points, beamData.radius(), beam.getEntityData().get(StaticSummon.COLOR_A),
beam.getEntityData().get(StaticSummon.COLOR_R),
beam.getEntityData().get(StaticSummon.COLOR_G),
beam.getEntityData().get(StaticSummon.COLOR_B), false);
}
@Override @Override
public void tick(StaticSummon beam) { public void tick(StaticSummon beam) {
@@ -315,8 +247,7 @@ public class LastPrism extends MagicWeapon {
AABB entityBox = hitEntity.getBoundingBox().inflate(beamData.radius()); AABB entityBox = hitEntity.getBoundingBox().inflate(beamData.radius());
Optional<Vec3> clipResult = entityBox.clip(beamData.start(), beamData.end()); Optional<Vec3> clipResult = entityBox.clip(beamData.start(), beamData.end());
if(entityBox.contains(beamData.start()) || clipResult.isPresent()) { if(entityBox.contains(beamData.start()) || clipResult.isPresent()) {
float damage = MagicWeapon.applyMagicDamageBonus(stack, player, getDamage() * beamData.ratio()); if(DamageUtil.magicAttack(beam, hitEntity, beam.getEntityData().get(StaticSummon.STACK_SOURCE), getDamage() * beamData.ratio(), 0.1f)) {
if(DamageUtil.normalAttack(beam, hitEntity, damage, 0.1f)) {
hitEntity.invulnerableTime = 5; hitEntity.invulnerableTime = 5;
} }
} }
@@ -400,6 +331,7 @@ public class LastPrism extends MagicWeapon {
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level); StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level);
summon.setOwner(player); summon.setOwner(player);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, stack.copy());
Vec3 pos = player.getEyePosition().add(MathUtil.toVec3(dirs[0]).scale(0.5)).add(MathUtil.toVec3(dirs[1]).scale(-1.0)); Vec3 pos = player.getEyePosition().add(MathUtil.toVec3(dirs[0]).scale(0.5)).add(MathUtil.toVec3(dirs[1]).scale(-1.0));
summon.setPos(pos); summon.setPos(pos);
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.LAST_PRISM_TRI); summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.LAST_PRISM_TRI);
@@ -420,6 +352,7 @@ public class LastPrism extends MagicWeapon {
StaticSummon beam = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level); StaticSummon beam = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level);
Vector3f color = BEAM_COLORS[i]; Vector3f color = BEAM_COLORS[i];
beam.setOwner(summon); beam.setOwner(summon);
beam.getEntityData().set(StaticSummon.STACK_SOURCE, stack.copy());
beam.setPos(pos); beam.setPos(pos);
beam.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.LAST_PRISM_BEAM); beam.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.LAST_PRISM_BEAM);
beam.getEntityData().set(StaticSummon.RENDER_MODE, "custom"); beam.getEntityData().set(StaticSummon.RENDER_MODE, "custom");
@@ -464,66 +397,9 @@ public class LastPrism extends MagicWeapon {
return 72000; return 72000;
} }
private static void renderTetrahedronFace(
VertexConsumer buffer,
Matrix4f matrix,
Vec3 v0,
Vec3 v1,
Vec3 v2,
float hue
) {
float[] color0 = computeSoftPrismColor(hue);
float[] color1 = computeSoftPrismColor(hue + 0.10F);
float[] color2 = computeSoftPrismColor(hue + 0.20F);
renderTetrahedronVertex(buffer, matrix, v0, color0[0], color0[1], color0[2]);
renderTetrahedronVertex(buffer, matrix, v1, color1[0], color1[1], color1[2]);
renderTetrahedronVertex(buffer, matrix, v2, color2[0], color2[1], color2[2]);
}
private static void renderTetrahedronFace(
VertexConsumer buffer,
Matrix4f matrix,
Vec3 v0,
Vec3 v1,
Vec3 v2,
float r,
float g,
float b,
float alpha
) {
renderTetrahedronVertex(buffer, matrix, v0, r, g, b, alpha);
renderTetrahedronVertex(buffer, matrix, v1, r, g, b, alpha);
renderTetrahedronVertex(buffer, matrix, v2, r, g, b, alpha);
}
private static void renderTetrahedronVertex(
VertexConsumer buffer,
Matrix4f matrix,
Vec3 vertex,
float r,
float g,
float b
) {
renderTetrahedronVertex(buffer, matrix, vertex, r, g, b, 1.0F);
}
private static void renderTetrahedronVertex(
VertexConsumer buffer,
Matrix4f matrix,
Vec3 vertex,
float r,
float g,
float b,
float alpha
) {
buffer.addVertex(matrix, (float)vertex.x, (float)vertex.y, (float)vertex.z)
.setColor(r, g, b, alpha)
.setUv(0.5F, 0.5F)
.setOverlay(OverlayTexture.NO_OVERLAY)
.setLight(LightTexture.FULL_BRIGHT)
.setNormal(0.0F, 1.0F, 0.0F);
}
private static float[] computeSoftPrismColor(float hue) { private static float[] computeSoftPrismColor(float hue) {
float normalizedHue = Math.floorMod((int)(hue * 1000.0F), 1000) / 1000.0F; float normalizedHue = Math.floorMod((int)(hue * 1000.0F), 1000) / 1000.0F;
@@ -540,63 +416,9 @@ public class LastPrism extends MagicWeapon {
}; };
} }
public static void renderTube(VertexConsumer buffer, Matrix4f matrix, Vec3 entityWorldPos,
List<Vec3> points, float radius, float alpha, float colorR, float colorG, float colorB, boolean linear) {
int n = points.size();
if(n < 2) return;
Vector3f[][] oriDirs = new Vector3f[n][3];
Vec3[] dir = new Vec3[n], up = new Vec3[n], right = new Vec3[n];
for(int i = 0;i < n;i++) {
if(i == n - 1) oriDirs[i] = MathUtil.computeCoordinateSystem(points.get(n - 1).subtract(points.get(n - 2)).toVector3f(), 0);
else oriDirs[i] = MathUtil.computeCoordinateSystem(points.get(i + 1).subtract(points.get(i)).toVector3f(), 0);
dir[i] = MathUtil.toVec3(oriDirs[i][0]);
up[i] = MathUtil.toVec3(oriDirs[i][1]);
right[i] = MathUtil.toVec3(oriDirs[i][2]);
}
for(int i = 0;i < n - 1;i++) {
float r0 = linear ? radius * (1.0F - (float) i / (float) (n - 1)) : radius;
float r1 = linear ? radius * (1.0F - (float) (i + 1) / (float) (n - 1)) : radius;
if(r0 <= 0.001F && r1 <= 0.001F) continue;
Vec3 N = right[i], B = up[i], N1 = right[i + 1], B1 = up[i + 1];
Vec3 P = points.get(i), P1 = points.get(i + 1);
for(int j = 0;j < RING;j++) {
float a0 = (float) (2.0 * Math.PI * j / RING);
float a1 = (float) (2.0 * Math.PI * (j + 1) / RING);
Vec3 d0 = computeRingDir(N, B, a0);
Vec3 d1 = computeRingDir(N1, B1, a0);
Vec3 d0b = computeRingDir(N, B, a1);
Vec3 d1b = computeRingDir(N1, B1, a1);
Vec3 v0 = P.add(d0.scale(r0));
Vec3 v1 = P1.add(d1.scale(r1));
Vec3 v2 = P1.add(d1b.scale(r1));
Vec3 v3 = P.add(d0b.scale(r0));
for(int k = 0;k < 3;k++) {
writeVert(buffer, matrix, entityWorldPos, v0, 0.5f, 0.5f, alpha, colorR, colorG, colorB);
writeVert(buffer, matrix, entityWorldPos, v1, 0.5f, 0.5f, alpha, colorR, colorG, colorB);
writeVert(buffer, matrix, entityWorldPos, v2, 0.5f, 0.5f, alpha, colorR, colorG, colorB);
writeVert(buffer, matrix, entityWorldPos, v3, 0.5f, 0.5f, alpha, colorR, colorG, colorB);
}
}
}
}
public static Vec3 computeRingDir(Vec3 n, Vec3 b, float ang) { public static Vec3 computeRingDir(Vec3 n, Vec3 b, float ang) {
return n.scale(Math.cos(ang)).add(b.scale(Math.sin(ang))); return n.scale(Math.cos(ang)).add(b.scale(Math.sin(ang)));
} }
public static void writeVert(VertexConsumer buffer, Matrix4f matrix, Vec3 entityWorldPos,
Vec3 worldPos, float u, float v, float alpha, float colorR, float colorG, float colorB) {
double lx = worldPos.x - entityWorldPos.x;
double ly = worldPos.y - entityWorldPos.y;
double lz = worldPos.z - entityWorldPos.z;
buffer.addVertex(matrix, (float)lx, (float)ly, (float)lz)
.setColor(colorR, colorG, colorB, alpha)
.setUv(u, v)
.setOverlay(OverlayTexture.NO_OVERLAY)
.setLight(LightTexture.FULL_BRIGHT)
.setNormal(0.0F, 1.0F, 0.0F);
}
} }
@@ -118,6 +118,7 @@ public class BeeKeeper extends MeleeWeapon {
BeeSummon bee = ModEntities.BEE_SUMMON.get().create(player.level()); BeeSummon bee = ModEntities.BEE_SUMMON.get().create(player.level());
if(bee != null) { if(bee != null) {
bee.owner = player; bee.owner = player;
bee.stackSource = itemStack.copy();
bee.setPos(new Vec3(target.getX(), target.getY() + target.getBbHeight() / 2, target.getZ())); bee.setPos(new Vec3(target.getX(), target.getY() + target.getBbHeight() / 2, target.getZ()));
player.level().addFreshEntity(bee); player.level().addFreshEntity(bee);
} }
@@ -2,27 +2,16 @@ package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon; import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.effect.ModEffects;
import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.projectile.IStaticProjectileBehavior; import com.lzxnone.terraria.entity.projectile.IStaticProjectileBehavior;
import com.lzxnone.terraria.entity.projectile.StaticProjectile; import com.lzxnone.terraria.entity.projectile.StaticProjectile;
import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors; import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors;
import com.lzxnone.terraria.item.ModItems; import com.lzxnone.terraria.item.ModItems;
import com.lzxnone.terraria.particle.ModParticles; import com.lzxnone.terraria.particle.ModParticles;
import com.lzxnone.terraria.utils.*; 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.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
import net.minecraft.tags.FluidTags; import net.minecraft.tags.FluidTags;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
@@ -39,7 +28,6 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tiers; import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.item.component.ItemAttributeModifiers; import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
@@ -47,7 +35,6 @@ import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.joml.Matrix4f;
import org.joml.Vector3f; import org.joml.Vector3f;
import com.lzxnone.terraria.ui.config.ConfigFactory; import com.lzxnone.terraria.ui.config.ConfigFactory;
import com.lzxnone.terraria.ui.config.ConfigListItem; import com.lzxnone.terraria.ui.config.ConfigListItem;
@@ -165,62 +152,8 @@ public class BladeOfGrass extends MeleeWeapon {
} }
public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileBehavior() { public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileBehavior() {
public static final ResourceLocation RES = ResourceLocation.parse("lzxnoneterraria:textures/vfx/normal_trail.png");
public static final Vector3f TRAIL_COLOR = new Vector3f(0.271f, 0.486f, 0.016f);
public static final float TRAIL_ALPHA = 0.25f;
public static final int MAX_LENGTH = 10; public static final int MAX_LENGTH = 10;
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticProjectile projectile)) return;
this.renderItem(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight);
Vec3 currentPos = projectile.getPosition(partialTick);
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucent(RES));
Matrix4f matrix = poseStack.last().pose();
int quadCount = projectile.trailPositions.size() / 2 - 1;
for(int i = 1; i < quadCount;i++) {
Vec3 currentPoint1 = projectile.trailPositions.get(i * 2);
Vec3 currentPoint2 = projectile.trailPositions.get(i * 2 + 1);
Vec3 nextPoint1 = projectile.trailPositions.get(i * 2 + 3);
Vec3 nextPoint2 = projectile.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 radio1 = (float) i / quadCount;
float radio2 = (float) (i + 1) / quadCount;
vertexConsumer.addVertex(matrix, (float)x1, (float)y1, (float)z1)
.setColor(TRAIL_COLOR.x, TRAIL_COLOR.y, TRAIL_COLOR.z, TRAIL_ALPHA).setUv(radio1, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(matrix, (float)x2, (float)y2, (float)z2)
.setColor(TRAIL_COLOR.x, TRAIL_COLOR.y, TRAIL_COLOR.z, TRAIL_ALPHA).setUv(radio1, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(matrix, (float)x3, (float)y3, (float)z3)
.setColor(TRAIL_COLOR.x, TRAIL_COLOR.y, TRAIL_COLOR.z, TRAIL_ALPHA).setUv(radio2, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(matrix, (float)x4, (float)y4, (float)z4)
.setColor(TRAIL_COLOR.x, TRAIL_COLOR.y, TRAIL_COLOR.z, TRAIL_ALPHA).setUv(radio2, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
}
}
@Override @Override
public void onMoving(StaticProjectile projectile) { public void onMoving(StaticProjectile projectile) {
ParticleUtil.addParticle( ParticleUtil.addParticle(
@@ -243,7 +176,7 @@ public class BladeOfGrass extends MeleeWeapon {
CompoundTag customData = projectile.getEntityData().get(StaticProjectile.CUSTOM_DATA); CompoundTag customData = projectile.getEntityData().get(StaticProjectile.CUSTOM_DATA);
if(!customData.contains("hitCount") || customData.getInt("hitCount") >= getProjectileMaxHitCount()) return; if(!customData.contains("hitCount") || customData.getInt("hitCount") >= getProjectileMaxHitCount()) return;
if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return; if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(DamageUtil.normalAttack(projectile, target, (float) getProjectileDamage(), 1.0f)) { if(DamageUtil.meleeAttack(projectile, target, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE), (float) getProjectileDamage(), 1.0f)) {
int count = customData.getInt("hitCount"); int count = customData.getInt("hitCount");
count++; count++;
if(target instanceof LivingEntity livingEntity && projectile.getRandom().nextInt(4) == 0) { if(target instanceof LivingEntity livingEntity && projectile.getRandom().nextInt(4) == 0) {
@@ -299,6 +232,7 @@ public class BladeOfGrass extends MeleeWeapon {
StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level); StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level);
projectile.setOwner(player); projectile.setOwner(player);
projectile.getEntityData().set(StaticProjectile.STACK_SOURCE, player.getWeaponItem().copy());
Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ()); Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ());
projectile.setPos(pos); projectile.setPos(pos);
projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.LEAF_PROJECTILE); projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.LEAF_PROJECTILE);
@@ -2,39 +2,29 @@ package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon; import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.LzxnoneTerrariaClient;
import com.lzxnone.terraria.ModSounds; import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.attachment.ModAttachments; import com.lzxnone.terraria.attachment.ModAttachments;
import com.lzxnone.terraria.effect.ModEffects; import com.lzxnone.terraria.effect.ModEffects;
import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.projectile.IStaticProjectileBehavior; import com.lzxnone.terraria.entity.projectile.IStaticProjectileBehavior;
import com.lzxnone.terraria.entity.projectile.StaticProjectile; import com.lzxnone.terraria.entity.projectile.StaticProjectile;
import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors; import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors;
import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior; import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior;
import com.lzxnone.terraria.entity.summon.StaticSummon; import com.lzxnone.terraria.entity.summon.StaticSummon;
import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors; import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors;
import com.lzxnone.terraria.event.ScreenShakeHandler;
import com.lzxnone.terraria.item.IItemWaveBehavior; import com.lzxnone.terraria.item.IItemWaveBehavior;
import com.lzxnone.terraria.item.ModItems; import com.lzxnone.terraria.item.ModItems;
import com.lzxnone.terraria.network.payload.DevilsDevastationLeftClickPayload; import com.lzxnone.terraria.network.payload.DevilsDevastationLeftClickPayload;
import com.lzxnone.terraria.network.payload.ScreenShakePayload;
import com.lzxnone.terraria.particle.CircleParticleOptions; import com.lzxnone.terraria.particle.CircleParticleOptions;
import com.lzxnone.terraria.particle.IronSparkParticleOptions; import com.lzxnone.terraria.particle.IronSparkParticleOptions;
import com.lzxnone.terraria.particle.ModParticles; import com.lzxnone.terraria.particle.ModParticles;
import com.lzxnone.terraria.utils.*; 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.client.Minecraft;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffectInstance;
@@ -45,7 +35,6 @@ import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*; import net.minecraft.world.item.*;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.item.component.ItemAttributeModifiers; import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
@@ -55,10 +44,8 @@ import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.event.entity.player.AttackEntityEvent; import net.neoforged.neoforge.event.entity.player.AttackEntityEvent;
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
import net.neoforged.neoforge.network.PacketDistributor; import net.neoforged.neoforge.network.PacketDistributor;
import org.joml.Matrix4f;
import org.joml.Quaternionf; import org.joml.Quaternionf;
import org.joml.Vector3f; import org.joml.Vector3f;
import net.minecraft.client.Camera;
import com.lzxnone.terraria.ui.config.ConfigFactory; import com.lzxnone.terraria.ui.config.ConfigFactory;
import com.lzxnone.terraria.ui.config.ConfigListItem; import com.lzxnone.terraria.ui.config.ConfigListItem;
import com.lzxnone.terraria.ui.config.ConfigUtil; import com.lzxnone.terraria.ui.config.ConfigUtil;
@@ -324,24 +311,6 @@ public class DevilsDevastation extends MeleeWeapon {
//右键射出的弹射 //右键射出的弹射
public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileBehavior() { public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticProjectile projectile)) return;
renderItem(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight);
VertexConsumer buffer = bufferSource.getBuffer(ModRenderTypes.entityAdditiveEmissive(RES));
Vec3 entWorldPos = new Vec3(
Mth.lerp(partialTick, projectile.xo, projectile.getX()),
Mth.lerp(partialTick, projectile.yo, projectile.getY()),
Mth.lerp(partialTick, projectile.zo, projectile.getZ())
);
Matrix4f matrix = poseStack.last().pose();
renderTube(buffer, matrix, entWorldPos, projectile.trailPositions, PROJECTILE_TRAIL_RADIUS * 1.0F, 1.0f, 1,1,1, true);
renderTube(buffer, matrix, entWorldPos, projectile.trailPositions, PROJECTILE_TRAIL_RADIUS * 1.25F, 1.0f * 0.5F, 0.7F,0.15F,0.55F, true);
renderTube(buffer, matrix, entWorldPos, projectile.trailPositions, PROJECTILE_TRAIL_RADIUS * 1.5F, 1.0f * 0.2F, 0.5F,0.1F,0.4F, true);
renderTube(buffer, matrix, entWorldPos, projectile.trailPositions2, PROJECTILE_TRAIL_RADIUS * 1.0F, 1.0f, 1,1,1, true);
renderTube(buffer, matrix, entWorldPos, projectile.trailPositions2, PROJECTILE_TRAIL_RADIUS * 1.25F, 1.0f * 0.5F, 0.7F,0.15F,0.55F, true);
renderTube(buffer, matrix, entWorldPos, projectile.trailPositions2, PROJECTILE_TRAIL_RADIUS * 1.5F, 1.0f * 0.2F, 0.5F,0.1F,0.4F, true);
}
@Override @Override
public void onMoving(StaticProjectile projectile) { public void onMoving(StaticProjectile projectile) {
@@ -383,7 +352,7 @@ public class DevilsDevastation extends MeleeWeapon {
Entity owner = projectile.getOwner(); Entity owner = projectile.getOwner();
if(owner == null) return; if(owner == null) return;
if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return; if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(DamageUtil.normalAttack(projectile, target, (float) getProjectileDamage(), 1.0f)) { if(DamageUtil.meleeAttack(projectile, target, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE), (float) getProjectileDamage(), 1.0f)) {
if(target instanceof LivingEntity le) { if(target instanceof LivingEntity le) {
MobEffectInstance effectInstance = new MobEffectInstance(ModEffects.DEMONIC_FLAMES, getProjectileEffectDuration(), 0); MobEffectInstance effectInstance = new MobEffectInstance(ModEffects.DEMONIC_FLAMES, getProjectileEffectDuration(), 0);
le.addEffect(effectInstance); le.addEffect(effectInstance);
@@ -392,6 +361,7 @@ public class DevilsDevastation extends MeleeWeapon {
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), projectile.level()); StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), projectile.level());
summon.setOwner(target); summon.setOwner(target);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE).copy());
Vec3 pos = projectile.position(); Vec3 pos = projectile.position();
summon.setPos(pos); summon.setPos(pos);
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.DEVILS_DEVASTATION_STUCK_PROJECTILE); summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.DEVILS_DEVASTATION_STUCK_PROJECTILE);
@@ -438,6 +408,7 @@ public class DevilsDevastation extends MeleeWeapon {
StaticSummon lightning = new StaticSummon(ModEntities.STATIC_SUMMON.get(), projectile.level()); StaticSummon lightning = new StaticSummon(ModEntities.STATIC_SUMMON.get(), projectile.level());
lightning.setOwner(owner); lightning.setOwner(owner);
lightning.getEntityData().set(StaticSummon.STACK_SOURCE, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE).copy());
lightning.setPos(pos); lightning.setPos(pos);
lightning.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.DEVILS_DEVASTATION_LIGHTNING); lightning.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.DEVILS_DEVASTATION_LIGHTNING);
lightning.getEntityData().set(StaticSummon.RENDER_MODE, "custom"); lightning.getEntityData().set(StaticSummon.RENDER_MODE, "custom");
@@ -495,56 +466,6 @@ public class DevilsDevastation extends MeleeWeapon {
//弹出的弹射 //弹出的弹射
public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR2 = new IStaticProjectileBehavior() { public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR2 = new IStaticProjectileBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticProjectile projectile)) return;
ItemStack stack = projectile.getEntityData().get(StaticProjectile.ITEM);
if(stack.isEmpty()) return;
float scaleX = 0.05f;
float scaleY = 0.05f;
float scaleZ = 0.05f;
float age = projectile.getEntityData().get(StaticProjectile.AGE) + partialTick;
Vector3f dir = projectile.getEntityData().get(StaticProjectile.DIRECTION);
Vector3f up = projectile.getEntityData().get(StaticProjectile.UP);
int rotate = projectile.getEntityData().get(StaticProjectile.RZP);
poseStack.pushPose();
RenderUtil.applyRotate(poseStack, dir, up, age * 30 + 60, rotate);
poseStack.scale(4.0f, 4.0f, 4.0f);
Minecraft.getInstance().getItemRenderer().renderStatic(
stack,
ItemDisplayContext.NONE,
LightTexture.FULL_BRIGHT,
OverlayTexture.NO_OVERLAY,
poseStack,
bufferSource,
entity.level(),
0
);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyRotate(poseStack, dir, up, age * 30 + 180, rotate);
poseStack.scale(scaleX, scaleY, scaleZ);
VertexConsumer buffer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES2));
RenderUtil.renderQuad(poseStack.last().pose(), buffer0, 0.729f, 0.396f, 0.345f, 1.0f, 78, 78, 0, 0, 0);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyRotate(poseStack, dir, up, age * 30, rotate);
poseStack.scale(scaleX, scaleY, scaleZ);
VertexConsumer buffer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES3));
RenderUtil.renderQuad(poseStack.last().pose(), buffer1, 0.8f, 0.176f, 0.78f, 1.0f, 78, 78, 0, 0, 0);
poseStack.popPose();
}
@Override @Override
public void onMoving(StaticProjectile projectile) { public void onMoving(StaticProjectile projectile) {
@@ -615,7 +536,7 @@ public class DevilsDevastation extends MeleeWeapon {
Entity owner = projectile.getOwner(); Entity owner = projectile.getOwner();
if(owner == null) return; if(owner == null) return;
if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return; if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(DamageUtil.normalAttack(projectile, target, (float) getStuckProjectileDamage(), 1.0f)) { if(DamageUtil.meleeAttack(projectile, target, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE), (float) getStuckProjectileDamage(), 1.0f)) {
if(target instanceof LivingEntity le) { if(target instanceof LivingEntity le) {
MobEffectInstance effectInstance = new MobEffectInstance(ModEffects.DEMONIC_FLAMES, getStuckProjectileEffectDuration(), 0); MobEffectInstance effectInstance = new MobEffectInstance(ModEffects.DEMONIC_FLAMES, getStuckProjectileEffectDuration(), 0);
le.addEffect(effectInstance); le.addEffect(effectInstance);
@@ -630,129 +551,6 @@ public class DevilsDevastation extends MeleeWeapon {
//杀戮模式弹射 //杀戮模式弹射
public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR3 = new IStaticProjectileBehavior() { public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR3 = new IStaticProjectileBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticProjectile projectile)) return;
ItemStack itemStack = projectile.getEntityData().get(StaticProjectile.ITEM);
if(itemStack == ItemStack.EMPTY) return;
CompoundTag customData = projectile.getEntityData().get(StaticProjectile.CUSTOM_DATA);
if(!customData.contains("w")) return;
float w = customData.getFloat("w");
float t = projectile.getEntityData().get(StaticProjectile.AGE) + partialTick;
Vec3 dir = MathUtil.toVec3(projectile.getEntityData().get(StaticProjectile.DIRECTION)).normalize();
Vec3 up = MathUtil.toVec3(projectile.getEntityData().get(StaticProjectile.UP)).normalize();
Quaternionf rotationDir = new Quaternionf()
.fromAxisAngleRad(dir.toVector3f(), (float) Math.toRadians(projectile.getEntityData().get(StaticProjectile.RZP)));
Quaternionf rotationUp;
Quaternionf rotationUp2;
if(w > 0) {
rotationUp = new Quaternionf().fromAxisAngleRad(up.toVector3f(), (float) Math.PI - w * t);
rotationUp2 = new Quaternionf().fromAxisAngleRad(up.toVector3f(), (float) Math.PI * 0.75f - w * t);
}else {
rotationUp = new Quaternionf().fromAxisAngleRad(up.toVector3f(), (float) -Math.PI - w * t);
rotationUp2 = new Quaternionf().fromAxisAngleRad(up.toVector3f(), (float) -Math.PI * 1.25f - w * t);
}
float[] xyRot = MathUtil.computeXYRot(dir.toVector3f(), up.toVector3f());
poseStack.pushPose();
//旋转
poseStack.mulPose(rotationUp);
poseStack.mulPose(rotationDir);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.XP.rotationDegrees(-90));
poseStack.mulPose(Axis.ZP.rotationDegrees(-135));
//缩放
poseStack.scale(4.0f, 4.0f, 4.0f);
Minecraft.getInstance().getItemRenderer().renderStatic(
itemStack,
ItemDisplayContext.NONE,
LightTexture.FULL_BRIGHT,
OverlayTexture.NO_OVERLAY,
poseStack,
bufferSource,
entity.level(),
0
);
poseStack.popPose();
poseStack.pushPose();
Vector3f tipDir = dir.toVector3f().rotate(rotationUp);
poseStack.translate(-tipDir.x * 2, -tipDir.y * 2, -tipDir.z * 2);
poseStack.translate(-up.x * 0.5, -up.y * 0.5, -up.z * 0.5);
poseStack.mulPose(rotationUp2);
poseStack.mulPose(rotationDir);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.XP.rotationDegrees(-90));
poseStack.mulPose(Axis.ZP.rotationDegrees(-135));
renderEnergyWave(bufferSource, poseStack, projectile);
poseStack.popPose();
float radio = t / projectile.getEntityData().get(StaticProjectile.LIFETIME);
float alpha = 1.0f - radio;
if(alpha > 0.001f) {
poseStack.pushPose();
poseStack.mulPose(rotationUp);
poseStack.mulPose(rotationDir);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.XP.rotationDegrees(-90));
if(w > 0) poseStack.mulPose(Axis.ZP.rotationDegrees(-105));
else poseStack.mulPose(Axis.ZP.rotationDegrees(75));
float halfWidth = 78;
float halfHeight = 78;
VertexConsumer consumer = bufferSource.getBuffer(ModRenderTypes.entityAdditiveEmissive(RES5));
Vector3f[] sizes = new Vector3f[]{
new Vector3f(0.2f, 0.2f, 0.2f),
new Vector3f(0.3f, 0.3f, 0.3f),
new Vector3f(0.4f, 0.4f, 0.4f),
};
Vector3f[] colors = new Vector3f[]{
new Vector3f(0.725f, 0.345f, 1.0f),
new Vector3f(0.847f, 0.247f, 0.745f),
new Vector3f(0.882f, 0.345f, 0.247f),
};
for(int i = 0;i < 3;i++) {
poseStack.pushPose();
poseStack.scale(sizes[i].x, sizes[i].y, sizes[i].z);
for(int j = 0;j < 3;j++) {
consumer.addVertex(poseStack.last().pose(), -halfWidth, halfHeight, 0.01f * i)
.setColor(colors[i].x, colors[i].y, colors[i].z, alpha).setUv(0.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
consumer.addVertex(poseStack.last().pose(), -halfWidth, -halfHeight, 0.01f * i)
.setColor(colors[i].x, colors[i].y, colors[i].z, alpha).setUv(0.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
consumer.addVertex(poseStack.last().pose(), halfWidth, -halfHeight, 0.01f * i)
.setColor(colors[i].x, colors[i].y, colors[i].z, alpha).setUv(1.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
consumer.addVertex(poseStack.last().pose(), halfWidth, halfHeight, 0.01f * i)
.setColor(colors[i].x, colors[i].y, colors[i].z, alpha).setUv(1.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
}
poseStack.popPose();
}
poseStack.popPose();
}
}
@Override @Override
public void onMoving(StaticProjectile projectile) { public void onMoving(StaticProjectile projectile) {
@@ -848,7 +646,7 @@ public class DevilsDevastation extends MeleeWeapon {
Entity target = result.getEntity(); Entity target = result.getEntity();
List<UUID> tempStuckList = target.getData(ModAttachments.STUCK_DEVILS_DEVASTATION_PROJECTILE); List<UUID> tempStuckList = target.getData(ModAttachments.STUCK_DEVILS_DEVASTATION_PROJECTILE);
boolean valid = !tempStuckList.isEmpty(); boolean valid = !tempStuckList.isEmpty();
if(projectile.getOwner() instanceof Player player && DamageUtil.normalAttack(projectile, target, (float) getKillModeProjectileDamage(), 1.0f)) { if(projectile.getOwner() instanceof Player player && DamageUtil.meleeAttack(projectile, target, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE), (float) getKillModeProjectileDamage(), 4.0f)) {
if(target instanceof LivingEntity le) { if(target instanceof LivingEntity le) {
MobEffectInstance effectInstance = new MobEffectInstance(ModEffects.DEMONIC_FLAMES, getKillModeProjectileEffectDuration(), 1); MobEffectInstance effectInstance = new MobEffectInstance(ModEffects.DEMONIC_FLAMES, getKillModeProjectileEffectDuration(), 1);
le.addEffect(effectInstance); le.addEffect(effectInstance);
@@ -865,6 +663,7 @@ public class DevilsDevastation extends MeleeWeapon {
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), projectile.level()); StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), projectile.level());
summon.setOwner(target); summon.setOwner(target);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE).copy());
Vec3 pos = target.getBoundingBox().getCenter(); Vec3 pos = target.getBoundingBox().getCenter();
summon.setPos(pos); summon.setPos(pos);
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.DEVILS_DEVASTATION_MARK); summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.DEVILS_DEVASTATION_MARK);
@@ -887,7 +686,9 @@ public class DevilsDevastation extends MeleeWeapon {
else SoundUtil.playServerSound(projectile.level(), ModSounds.DEMON_SWORD_STRONG_IMPACT.get(), target.position(), 16.0f, pitch); else SoundUtil.playServerSound(projectile.level(), ModSounds.DEMON_SWORD_STRONG_IMPACT.get(), target.position(), 16.0f, pitch);
customData.putBoolean("hit", true); customData.putBoolean("hit", true);
projectile.getEntityData().set(StaticProjectile.CUSTOM_DATA, customData); projectile.getEntityData().set(StaticProjectile.CUSTOM_DATA, customData);
ScreenShakeHandler.startShake(10, 2f); if(player instanceof ServerPlayer serverPlayer) {
PacketDistributor.sendToPlayer(serverPlayer, new ScreenShakePayload(10, 2f));
}
} }
List<UUID> stuckList = new ArrayList<>(target.getData(ModAttachments.STUCK_DEVILS_DEVASTATION_PROJECTILE)); List<UUID> stuckList = new ArrayList<>(target.getData(ModAttachments.STUCK_DEVILS_DEVASTATION_PROJECTILE));
if(!customData.contains("validHit") && valid) { if(!customData.contains("validHit") && valid) {
@@ -904,6 +705,7 @@ public class DevilsDevastation extends MeleeWeapon {
StaticSummon lightning = new StaticSummon(ModEntities.STATIC_SUMMON.get(), projectile.level()); StaticSummon lightning = new StaticSummon(ModEntities.STATIC_SUMMON.get(), projectile.level());
lightning.setOwner(player); lightning.setOwner(player);
lightning.getEntityData().set(StaticSummon.STACK_SOURCE, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE).copy());
lightning.setPos(target.getBoundingBox().getCenter()); lightning.setPos(target.getBoundingBox().getCenter());
lightning.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.DEVILS_DEVASTATION_LIGHTNING); lightning.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.DEVILS_DEVASTATION_LIGHTNING);
lightning.getEntityData().set(StaticSummon.RENDER_MODE, "custom"); lightning.getEntityData().set(StaticSummon.RENDER_MODE, "custom");
@@ -975,49 +777,6 @@ public class DevilsDevastation extends MeleeWeapon {
//右键弹射击中后生成的闪电 //右键弹射击中后生成的闪电
public static final IStaticSummonBehavior SUMMON_BEHAVIOR2 = new IStaticSummonBehavior() { public static final IStaticSummonBehavior SUMMON_BEHAVIOR2 = new IStaticSummonBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon)) return;
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
if(!customData.contains("dirX") || !customData.contains("dirY") || !customData.contains("dirZ") || !customData.contains("seed")) return;
Vec3 dir = new Vec3(customData.getDouble("dirX"), customData.getDouble("dirY"), customData.getDouble("dirZ")).normalize();
long seed = customData.getLong("seed");
int age = summon.getEntityData().get(StaticSummon.AGE);
int lifetime = summon.getEntityData().get(StaticSummon.LIFETIME);
if(lifetime <= 0) return;
float lifeRatio = Mth.clamp((age + partialTick) / (float) lifetime, 0.0F, 1.0F);
if(lifeRatio > 0.999f) return;
float radius = PROJECTILE_HIT_LIGHTNING_RADIUS * (1.0f - lifeRatio);
float alpha = 1.0f - lifeRatio;
Vec3 entWorldPos = new Vec3(
Mth.lerp(partialTick, summon.xo, summon.getX()),
Mth.lerp(partialTick, summon.yo, summon.getY()),
Mth.lerp(partialTick, summon.zo, summon.getZ())
);
VertexConsumer buffer = bufferSource.getBuffer(ModRenderTypes.entityAdditiveEmissive(RES));
Matrix4f matrix = poseStack.last().pose();
Random rand0 = new Random(seed);
Vec3 start0 = entWorldPos.add(dir.scale(4.0));
Vec3 end0 = start0.add(dir.scale(PROJECTILE_HIT_LIGHTNING_LENGTH));
List<Vec3> branch0 = generateBranch(start0, end0, rand0, PROJECTILE_HIT_LIGHTNING_DEPTH, PROJECTILE_HIT_LIGHTNING_JITTER);
Random rand1 = new Random(seed + 1);
Vec3 end1 = start0.add(spreadDir(dir, rand1, 0.4F).scale(PROJECTILE_HIT_LIGHTNING_LENGTH * 0.7F));
List<Vec3> branch1 = generateBranch(start0, end1, rand1, PROJECTILE_HIT_LIGHTNING_DEPTH, PROJECTILE_HIT_LIGHTNING_JITTER);
Random rand2 = new Random(seed + 2);
Vec3 start2 = branch0.get(1);
Vec3 end2 = start2.add(spreadDir(dir, rand2, 0.4F).scale(PROJECTILE_HIT_LIGHTNING_LENGTH * 0.5F));
List<Vec3> branch2 = generateBranch(start2, end2, rand2, PROJECTILE_HIT_LIGHTNING_DEPTH, PROJECTILE_HIT_LIGHTNING_JITTER);
for(List<Vec3> branch : List.of(branch0, branch1, branch2)) {
renderTube(buffer, matrix, entWorldPos, branch, radius * 1.0F, alpha, 1,1,1, true);
renderTube(buffer, matrix, entWorldPos, branch, radius * 1.25F, alpha * 0.5F, 0.7F,0.15F,0.55F, true);
renderTube(buffer, matrix, entWorldPos, branch, radius * 0.75F, alpha * 0.2F, 0.5F,0.1F,0.4F, true);
}
}
@Override @Override
public AABB getBoundingBoxForCulling(StaticSummon summon) { public AABB getBoundingBoxForCulling(StaticSummon summon) {
@@ -1029,50 +788,6 @@ public class DevilsDevastation extends MeleeWeapon {
//标记 //标记
public static final IStaticSummonBehavior SUMMON_BEHAVIOR3 = new IStaticSummonBehavior() { public static final IStaticSummonBehavior SUMMON_BEHAVIOR3 = new IStaticSummonBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon)) return;
Vec3 entWorldPos = new Vec3(
Mth.lerp(partialTick, entity.xo, entity.getX()),
Mth.lerp(partialTick, entity.yo, entity.getY()),
Mth.lerp(partialTick, entity.zo, entity.getZ())
);
// 公告板:根据相机计算平面基向量
Camera camera = Minecraft.getInstance().gameRenderer.getMainCamera();
Vec3 toCamera = camera.getPosition().subtract(entWorldPos).normalize();
Vec3 up = new Vec3(0, 1, 0);
Vec3 right = toCamera.cross(up).normalize();
if(right.lengthSqr() < 0.01) right = new Vec3(1, 0, 0);
Vec3 realUp = right.cross(toCamera).normalize();
// 十字交叉的4个方向
Vec3[] dirs = {
realUp.add(right).normalize(),
realUp.subtract(right).normalize(),
realUp.scale(-1.0).add(right).normalize(),
realUp.scale(-1.0).subtract(right).normalize()
};
float age = summon.getEntityData().get(StaticSummon.AGE) + partialTick;
float lifetime = summon.getEntityData().get(StaticSummon.LIFETIME);
float progress = age / lifetime;
float alpha = 1.0f;
float length = MARK_LENGTH + progress * MARK_LENGTH * 2;
float radius = MARK_RADIUS + progress * MARK_RADIUS * 2;
VertexConsumer buffer = bufferSource.getBuffer(ModRenderTypes.entityAdditiveEmissive(RES));
Matrix4f matrix = poseStack.last().pose();
for(Vec3 dir : dirs) {
List<Vec3> points = new ArrayList<>();
points.add(entWorldPos);
points.add(entWorldPos.add(dir.scale(length)));
renderTube(buffer, matrix, entWorldPos, points, radius * 0.5f, alpha * 0.8f, 1.0f, 1.0f, 1.0f, true);
renderTube(buffer, matrix, entWorldPos, points, radius, alpha, 0.8f, 0.176f, 0.78f, true);
}
}
@Override @Override
public void tick(StaticSummon summon) { public void tick(StaticSummon summon) {
@@ -1118,9 +833,10 @@ public class DevilsDevastation extends MeleeWeapon {
UUID uuid = customData.getUUID("uuid"); UUID uuid = customData.getUUID("uuid");
Entity entity = serverLevel.getEntity(uuid); Entity entity = serverLevel.getEntity(uuid);
if(entity instanceof Player player) { if(entity instanceof Player player) {
DamageUtil.normalAttack(player, owner, (float) getMarkLightningDamage(), 1.0f); DamageUtil.meleeAttack(player, owner, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float) getMarkLightningDamage(), 1.0f);
StaticSummon newSummon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), serverLevel); StaticSummon newSummon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), serverLevel);
newSummon.setOwner(player); newSummon.setOwner(player);
newSummon.getEntityData().set(StaticSummon.STACK_SOURCE, summon.getEntityData().get(StaticSummon.STACK_SOURCE).copy());
Vec3 pos = owner.getBoundingBox().getCenter(); Vec3 pos = owner.getBoundingBox().getCenter();
newSummon.setPos(pos); newSummon.setPos(pos);
newSummon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.DEVILS_DEVASTATION_MARK_LIGHTNING); newSummon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.DEVILS_DEVASTATION_MARK_LIGHTNING);
@@ -1143,66 +859,7 @@ public class DevilsDevastation extends MeleeWeapon {
}; };
//标记触发后的大型闪电 //标记触发后的大型闪电
public static final IStaticSummonBehavior SUMMON_BEHAVIOR4 = new IStaticSummonBehavior() { public static final IStaticSummonBehavior SUMMON_BEHAVIOR4 = new IStaticSummonBehavior() {};
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon)) return;
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
if(!customData.contains("seed")) return;
long seed = customData.getLong("seed");
int ageInt = summon.getEntityData().get(StaticSummon.AGE);
int lifetime = summon.getEntityData().get(StaticSummon.LIFETIME);
if(lifetime <= 0) return;
float lifeRatio = Mth.clamp((ageInt + partialTick) / (float) lifetime, 0.0F, 1.0F);
float lengthScale = Math.min(1.0F, lifeRatio * 2.0F);
float length = MARK_LIGHTNING_LENGTH * lengthScale;
if(length < 0.5F) return;
float radius = MARK_LIGHTNING_RADIUS * (1.0F - lifeRatio);
float alpha = 1.0F - lifeRatio;
Vec3 entWorldPos = new Vec3(
Mth.lerp(partialTick, summon.xo, summon.getX()),
Mth.lerp(partialTick, summon.yo, summon.getY()),
Mth.lerp(partialTick, summon.zo, summon.getZ())
);
VertexConsumer buffer = bufferSource.getBuffer(ModRenderTypes.entityAdditiveEmissive(RES));
Matrix4f matrix = poseStack.last().pose();
Random rand = new Random(seed);
float baseAngle = rand.nextFloat() * (float)Math.PI * 2;
Vec3[] dirs = {
new Vec3(Math.cos(baseAngle), 0, Math.sin(baseAngle)),
new Vec3(Math.cos(baseAngle + Math.PI / 2), 0, Math.sin(baseAngle + Math.PI / 2)),
new Vec3(Math.cos(baseAngle + Math.PI), 0, Math.sin(baseAngle + Math.PI)),
new Vec3(Math.cos(baseAngle + Math.PI * 3 / 2), 0, Math.sin(baseAngle + Math.PI * 3 / 2))
};
for(int d = 0; d < 4; d++) {
Random mainRand = new Random(seed + d);
Vec3 dir = dirs[d];
Vec3 start = entWorldPos;
Vec3 end = start.add(dir.scale(length));
List<Vec3> mainBranch = generateBranch(start, end, mainRand, MARK_LIGHTNING_DEPTH, MARK_LIGHTNING_JITTER);
renderTube(buffer, matrix, entWorldPos, mainBranch, radius, alpha, 0.8f, 0.176f, 0.78f, true);
renderTube(buffer, matrix, entWorldPos, mainBranch, radius * 0.5f, alpha * 0.8f, 1.0f, 1.0f, 1.0f, true);
for(int s = 0; s < MARK_LIGHTNING_SUB_COUNT; s++) {
Random subRand = new Random(seed + d * 10 + s);
int idx = subRand.nextInt(mainBranch.size());
Vec3 branchPos = mainBranch.get(idx);
Vec3 subEnd = branchPos.add(spreadDir(dir, subRand, MARK_LIGHTNING_SUB_SPREAD).scale(length * MARK_LIGHTNING_SUB_LENGTH));
List<Vec3> subBranch = generateBranch(branchPos, subEnd, subRand, MARK_LIGHTNING_DEPTH, MARK_LIGHTNING_JITTER);
renderTube(buffer, matrix, entWorldPos, subBranch, radius, alpha, 0.8f, 0.176f, 0.78f, true);
renderTube(buffer, matrix, entWorldPos, subBranch, radius * 0.5f, alpha * 0.8f, 1.0f, 1.0f, 1.0f, true);
}
}
}
};
//生成弹出弹射 //生成弹出弹射
public static void summonStuckProjectile(StaticSummon stuckProjectile) { public static void summonStuckProjectile(StaticSummon stuckProjectile) {
@@ -1220,6 +877,7 @@ public class DevilsDevastation extends MeleeWeapon {
StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), serverLevel); StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), serverLevel);
projectile.setOwner(player); projectile.setOwner(player);
projectile.getEntityData().set(StaticProjectile.STACK_SOURCE, stuckProjectile.getEntityData().get(StaticSummon.STACK_SOURCE).copy());
Vec3 pos = stuckProjectile.position(); Vec3 pos = stuckProjectile.position();
projectile.setPos(pos); projectile.setPos(pos);
projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.DEVILS_DEVASTATION_PROJECTILE2); projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.DEVILS_DEVASTATION_PROJECTILE2);
@@ -1256,6 +914,7 @@ public class DevilsDevastation extends MeleeWeapon {
StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), player.level()); StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), player.level());
projectile.setOwner(player); projectile.setOwner(player);
projectile.getEntityData().set(StaticProjectile.STACK_SOURCE, itemStack.copy());
Vec3 pos = player.getBoundingBox().getCenter(); Vec3 pos = player.getBoundingBox().getCenter();
projectile.setPos(pos); projectile.setPos(pos);
projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.DEVILS_DEVASTATION_PROJECTILE3); projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.DEVILS_DEVASTATION_PROJECTILE3);
@@ -1358,177 +1017,13 @@ public class DevilsDevastation extends MeleeWeapon {
); );
} }
public static void renderTube(VertexConsumer buffer, Matrix4f matrix, Vec3 entityWorldPos,
List<Vec3> points, float radius, float alpha, float colorR, float colorG, float colorB, boolean linear) {
int n = points.size();
if(n < 2) return;
Vector3f[][] oriDirs = new Vector3f[n][3];
Vec3[] dir = new Vec3[n], up = new Vec3[n], right = new Vec3[n];
for(int i = 0;i < n;i++) {
if(i == n - 1) oriDirs[i] = MathUtil.computeCoordinateSystem(points.get(n - 1).subtract(points.get(n - 2)).toVector3f(), 0);
else oriDirs[i] = MathUtil.computeCoordinateSystem(points.get(i + 1).subtract(points.get(i)).toVector3f(), 0);
dir[i] = MathUtil.toVec3(oriDirs[i][0]);
up[i] = MathUtil.toVec3(oriDirs[i][1]);
right[i] = MathUtil.toVec3(oriDirs[i][2]);
}
for(int i = 0;i < n - 1;i++) {
float r0 = linear ? radius * (1.0F - (float) i / (float) (n - 1)) : radius;
float r1 = linear ? radius * (1.0F - (float) (i + 1) / (float) (n - 1)) : radius;
if(r0 <= 0.001F && r1 <= 0.001F) continue;
Vec3 N = right[i], B = up[i], N1 = right[i + 1], B1 = up[i + 1];
Vec3 P = points.get(i), P1 = points.get(i + 1);
for(int j = 0;j < RING;j++) {
float a0 = (float) (2.0 * Math.PI * j / RING);
float a1 = (float) (2.0 * Math.PI * (j + 1) / RING);
Vec3 d0 = computeRingDir(N, B, a0);
Vec3 d1 = computeRingDir(N1, B1, a0);
Vec3 d0b = computeRingDir(N, B, a1);
Vec3 d1b = computeRingDir(N1, B1, a1);
Vec3 v0 = P.add(d0.scale(r0));
Vec3 v1 = P1.add(d1.scale(r1));
Vec3 v2 = P1.add(d1b.scale(r1));
Vec3 v3 = P.add(d0b.scale(r0));
for(int k = 0;k < 3;k++) {
writeVert(buffer, matrix, entityWorldPos, v0, 0.5f, 0.5f, alpha, colorR, colorG, colorB);
writeVert(buffer, matrix, entityWorldPos, v1, 0.5f, 0.5f, alpha, colorR, colorG, colorB);
writeVert(buffer, matrix, entityWorldPos, v2, 0.5f, 0.5f, alpha, colorR, colorG, colorB);
writeVert(buffer, matrix, entityWorldPos, v3, 0.5f, 0.5f, alpha, colorR, colorG, colorB);
}
}
}
}
public static void renderTubeSegmented(VertexConsumer buffer, Matrix4f matrix, Vec3 entityWorldPos,
List<Vec3> points, float[] radii,
Vector3f[] colors, float alpha,
float uvOffsetU, float uvOffsetV, float uvScaleU, float uvScaleV) {
int n = points.size();
if(n < 2 || radii.length < n || colors.length < n) return;
Vector3f[][] oriDirs = new Vector3f[n][3];
Vec3[] dir = new Vec3[n], up = new Vec3[n], right = new Vec3[n];
for(int i = 0;i < n;i++) {
if(i == n - 1) oriDirs[i] = MathUtil.computeCoordinateSystem(points.get(n - 1).subtract(points.get(n - 2)).toVector3f(), 0);
else oriDirs[i] = MathUtil.computeCoordinateSystem(points.get(i + 1).subtract(points.get(i)).toVector3f(), 0);
dir[i] = MathUtil.toVec3(oriDirs[i][0]);
up[i] = MathUtil.toVec3(oriDirs[i][1]);
right[i] = MathUtil.toVec3(oriDirs[i][2]);
}
for(int i = 0;i < n - 1;i++) {
float r0 = radii[i];
float r1 = radii[i + 1];
if(r0 <= 0.001F && r1 <= 0.001F) continue;
Vec3 N = right[i], B = up[i], N1 = right[i + 1], B1 = up[i + 1];
Vec3 P = points.get(i), P1 = points.get(i + 1);
Vector3f c0 = colors[i], c1 = colors[i + 1];
float u0 = uvOffsetU + uvScaleU * ((float)i / (float)(n - 1));
float u1 = uvOffsetU + uvScaleU * ((float)(i + 1) / (float)(n - 1));
for(int j = 0;j < RING;j++) {
float a0 = (float) (2.0 * Math.PI * j / RING);
float a1 = (float) (2.0 * Math.PI * (j + 1) / RING);
// 每个面独立映射完整纹理 V=[0,1]
float v0 = (float) j / (float)RING + uvOffsetV;
float v1 = (float) (j + 1) / (float)RING + uvOffsetV;
Vec3 d0 = computeRingDir(N, B, a0);
Vec3 d1 = computeRingDir(N1, B1, a0);
Vec3 d0b = computeRingDir(N, B, a1);
Vec3 d1b = computeRingDir(N1, B1, a1);
Vec3 v00 = P.add(d0.scale(r0));
Vec3 v01 = P1.add(d1.scale(r1));
Vec3 v02 = P1.add(d1b.scale(r1));
Vec3 v03 = P.add(d0b.scale(r0));
for(int k = 0;k < 10;k++) {
writeVert(buffer, matrix, entityWorldPos, v00, u0, v0, alpha, c0.x(), c0.y(), c0.z());
writeVert(buffer, matrix, entityWorldPos, v01, u1, v0, alpha, c1.x(), c1.y(), c1.z());
writeVert(buffer, matrix, entityWorldPos, v02, u1, v1, alpha, c1.x(), c1.y(), c1.z());
writeVert(buffer, matrix, entityWorldPos, v03, u0, v1, alpha, c0.x(), c0.y(), c0.z());
}
}
}
}
public static Vec3 computeRingDir(Vec3 n, Vec3 b, float ang) { public static Vec3 computeRingDir(Vec3 n, Vec3 b, float ang) {
return n.scale(Math.cos(ang)).add(b.scale(Math.sin(ang))); return n.scale(Math.cos(ang)).add(b.scale(Math.sin(ang)));
} }
public static void writeVert(VertexConsumer buffer, Matrix4f matrix, Vec3 entityWorldPos,
Vec3 worldPos, float u, float v, float alpha, float colorR, float colorG, float colorB) {
double lx = worldPos.x - entityWorldPos.x;
double ly = worldPos.y - entityWorldPos.y;
double lz = worldPos.z - entityWorldPos.z;
buffer.addVertex(matrix, (float)lx, (float)ly, (float)lz)
.setColor(colorR, colorG, colorB, alpha)
.setUv(u, v)
.setOverlay(OverlayTexture.NO_OVERLAY)
.setLight(LightTexture.FULL_BRIGHT)
.setNormal(0.0F, 1.0F, 0.0F);
}
public static void renderEnergyWave(MultiBufferSource buffer, PoseStack poseStack, Entity entity) {
Matrix4f matrix = poseStack.last().pose();
int time = entity.tickCount;
poseStack.translate(0, 1.4, 0.6);
float baseRadius = 1.0f;
float speed = 0.25f;
Vector3f colorA = new Vector3f(0.729f, 0.396f, 0.345f);
Vector3f colorB = new Vector3f(0.8f, 0.176f, 0.78f);
List<Vec3> points = new ArrayList<>();
float[] outRadius = new float[ENERGY_WAVE_SEG + 1];
Vector3f[] outColors = new Vector3f[ENERGY_WAVE_SEG + 1];
for(int i = 0; i <= ENERGY_WAVE_SEG; i++) {
float t = (float) i / ENERGY_WAVE_SEG;
float y = t * ENERGY_WAVE_LENGTH;
float phase = time * speed * 6f - t * (float) Math.PI * 5;
float wave = (float) Math.sin(phase);
points.add(new Vec3(0, y, 0));
float taper = (float) Math.cos(t * Math.PI * 0.5f);
float pulse = 0.7f + 0.3f * (0.5f + 0.5f * wave);
outRadius[i] = baseRadius * taper * pulse;
float blend = 0.5f + 0.5f * (float) Math.sin(time * 0.3f * speed - t * (float) Math.PI * 2);
outColors[i] = new Vector3f(
colorA.x + (colorB.x - colorA.x) * blend,
colorA.y + (colorB.y - colorA.y) * blend,
colorA.z + (colorB.z - colorA.z) * blend
);
}
float[] inRadius = new float[ENERGY_WAVE_SEG + 1];
Vector3f[] inColors = new Vector3f[ENERGY_WAVE_SEG + 1];
for(int i = 0; i <= ENERGY_WAVE_SEG; i++) {
inRadius[i] = outRadius[i] * 0.1f;
inColors[i] = new Vector3f(1.0f, 1.0f, 1.0f);
}
VertexConsumer consumer2 = buffer.getBuffer(ModRenderTypes.entityAdditiveEmissive(RES));
renderTubeSegmented(consumer2, matrix, new Vec3(0, 0, 0), points, inRadius, inColors, 1.0f,
0, 0, 1.0f, 0.0f);
float uOffset = time * 0.125f;
float vOffset = time * 0.125f;
VertexConsumer consumer = buffer.getBuffer(ModRenderTypes.entityAdditiveEmissive(RES4));
for(int i = 0;i < 1;i++) {
renderTubeSegmented(consumer, matrix, new Vec3(0, 0, 0), points, outRadius, outColors, 1.0f,
uOffset, 0 + vOffset, 2.0f, 0.0f);
renderTubeSegmented(consumer, matrix, new Vec3(0, 0, 0), points, outRadius, outColors, 1.0f,
uOffset, 0.5f + vOffset, 2.0f, 0.0f);
}
}
public static final IItemWaveBehavior ITEM_WAVE_BEHAVIOR = new IItemWaveBehavior() { public static final IItemWaveBehavior ITEM_WAVE_BEHAVIOR = new IItemWaveBehavior() {
@Override @Override
@@ -1586,6 +1081,7 @@ public class DevilsDevastation extends MeleeWeapon {
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player); Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level); StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level);
projectile.setOwner(player); projectile.setOwner(player);
projectile.getEntityData().set(StaticProjectile.STACK_SOURCE, stack.copy());
Vec3 pos = player.getBoundingBox().getCenter(); Vec3 pos = player.getBoundingBox().getCenter();
projectile.setPos(pos); projectile.setPos(pos);
projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.DEVILS_DEVASTATION_PROJECTILE); projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.DEVILS_DEVASTATION_PROJECTILE);
@@ -123,7 +123,7 @@ public class EnchantedSword extends MeleeWeapon {
Entity owner = projectile.getOwner(); Entity owner = projectile.getOwner();
if(owner == null) return; if(owner == null) return;
if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return; if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(DamageUtil.normalAttack(projectile, target, (float) getDamage(), 1.0f)) { if(DamageUtil.meleeAttack(projectile, target, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE),(float) getDamage(), 1.0f)) {
target.invulnerableTime = 5; target.invulnerableTime = 5;
ParticleUtil.addParticles( ParticleUtil.addParticles(
(ServerLevel) projectile.level(), ModParticles.COLORFUL_PARTICLE, (ServerLevel) projectile.level(), ModParticles.COLORFUL_PARTICLE,
@@ -155,6 +155,7 @@ public class EnchantedSword extends MeleeWeapon {
projectile.setPos(pos); projectile.setPos(pos);
projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.ENCHANTED_SWORD_BEAM); projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.ENCHANTED_SWORD_BEAM);
projectile.getEntityData().set(StaticProjectile.RENDER_MODE, "item"); projectile.getEntityData().set(StaticProjectile.RENDER_MODE, "item");
projectile.getEntityData().set(StaticProjectile.STACK_SOURCE, stack.copy());
projectile.getEntityData().set(StaticProjectile.ORIGIN, MathUtil.toVector3f(pos)); projectile.getEntityData().set(StaticProjectile.ORIGIN, MathUtil.toVector3f(pos));
projectile.getEntityData().set(StaticProjectile.DIRECTION, dirs[0]); projectile.getEntityData().set(StaticProjectile.DIRECTION, dirs[0]);
projectile.getEntityData().set(StaticProjectile.UP, dirs[1]); projectile.getEntityData().set(StaticProjectile.UP, dirs[1]);
@@ -152,7 +152,7 @@ public class Excalibur extends MeleeWeapon {
if(custom_data.contains("hitEntityCount")) { if(custom_data.contains("hitEntityCount")) {
int count = custom_data.getInt("hitEntityCount"); int count = custom_data.getInt("hitEntityCount");
if(count < getMaxHitCount()) { if(count < getMaxHitCount()) {
if(DamageUtil.normalAttack(beam, target, (float) getDamage(), 1.0f)) { if(DamageUtil.meleeAttack(beam, target, beam.getEntityData().get(SwordBeam.STACK_SOURCE), (float) getDamage(), 1.0f)) {
target.invulnerableTime = 20; target.invulnerableTime = 20;
count++; count++;
custom_data.putInt("hitEntityCount", count); custom_data.putInt("hitEntityCount", count);
@@ -4,25 +4,13 @@ import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds; import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.TintedVertexConsumer;
import com.lzxnone.terraria.entity.projectile.StaticProjectile;
import com.lzxnone.terraria.entity.summon.*; import com.lzxnone.terraria.entity.summon.*;
import com.lzxnone.terraria.item.ModItems; import com.lzxnone.terraria.item.ModItems;
import com.lzxnone.terraria.particle.ZenithTrailParticleOptions; import com.lzxnone.terraria.particle.ZenithTrailParticleOptions;
import com.lzxnone.terraria.network.SkinFetch; import com.lzxnone.terraria.network.SkinFetch;
import com.lzxnone.terraria.utils.*; import com.lzxnone.terraria.utils.*;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.PlayerModel;
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.client.resources.PlayerSkin;
import net.minecraft.core.component.DataComponents; import net.minecraft.core.component.DataComponents;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FastColor; import net.minecraft.util.FastColor;
@@ -40,7 +28,6 @@ import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.joml.Matrix4f;
import org.joml.Vector3f; import org.joml.Vector3f;
import org.jspecify.annotations.NonNull; import org.jspecify.annotations.NonNull;
import com.lzxnone.terraria.ui.config.ConfigFactory; import com.lzxnone.terraria.ui.config.ConfigFactory;
@@ -205,194 +192,6 @@ public class FirstFractal extends MeleeWeapon {
public static final ResourceLocation RES = ResourceLocation.parse("lzxnoneterraria:textures/vfx/beam_sparkle.png"); public static final ResourceLocation RES = ResourceLocation.parse("lzxnoneterraria:textures/vfx/beam_sparkle.png");
public static final ResourceLocation RES2 = ResourceLocation.parse("lzxnoneterraria:textures/vfx/first_fractal_star.png"); public static final ResourceLocation RES2 = ResourceLocation.parse("lzxnoneterraria:textures/vfx/first_fractal_star.png");
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon)) return;
UUID uuid = summon.getEntityData().get(StaticSummon.OWNER).orElse(null);
if(uuid == null) return;
ItemStack item = summon.getEntityData().get(StaticSummon.ITEM);
if(item == ItemStack.EMPTY) return;
GameProfile profile = SkinFetch.getCachedProfile(uuid);
PlayerSkin playerSkin = Minecraft.getInstance().getSkinManager().getInsecureSkin(profile);
boolean isSlim = playerSkin.model() == PlayerSkin.Model.SLIM;
PlayerModel<LivingEntity> activeModel = isSlim ? StaticSummonRenderer.getSlimModel() : StaticSummonRenderer.getWideModel();
activeModel.rightArm.resetPose();
activeModel.leftArm.resetPose();
activeModel.rightLeg.resetPose();
activeModel.leftLeg.resetPose();
activeModel.rightSleeve.resetPose();
activeModel.leftSleeve.resetPose();
activeModel.rightPants.resetPose();
activeModel.leftPants.resetPose();
activeModel.young = false;
//确定模型方向
activeModel.rightArm.xRot = (float) Math.toRadians(-90);
activeModel.leftArm.xRot = (float) Math.toRadians(-90);
activeModel.rightArm.yRot = (float) Math.toRadians(-30);
activeModel.leftArm.yRot = (float) Math.toRadians(30);
activeModel.rightLeg.xRot = (float) Math.toRadians(-30);
activeModel.leftLeg.xRot = (float) Math.toRadians(30);
activeModel.rightSleeve.xRot = activeModel.rightArm.xRot;
activeModel.rightSleeve.yRot = activeModel.rightArm.yRot;
activeModel.leftSleeve.xRot = activeModel.leftArm.xRot;
activeModel.leftSleeve.yRot = activeModel.leftArm.yRot;
activeModel.rightPants.xRot = activeModel.rightLeg.xRot;
activeModel.leftPants.xRot = activeModel.leftLeg.xRot;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(summon.getLookAngle().toVector3f(), 0);
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
Vector3f color = new Vector3f(
summon.getEntityData().get(StaticSummon.COLOR_R),
summon.getEntityData().get(StaticSummon.COLOR_G),
summon.getEntityData().get(StaticSummon.COLOR_B)
);
float radio = (float) (summon.getEntityData().get(StaticSummon.AGE) + partialTick) / (float) summon.getEntityData().get(StaticSummon.LIFETIME);
float alpha;
if(radio < 0.25f) {
alpha = radio / 0.25f;
}else if(radio > 0.75f) {
alpha = 1.0f - (radio - 0.75f) / 0.25f;
}else {
alpha = 1.0f;
}
if(alpha < 0.001f) return;
//流星
poseStack.pushPose();
float starHalfWidth = 45 * 0.06f;
float starHalfHeight = 17 * 0.06f;
VertexConsumer starConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES2));
poseStack.translate(
dirs[0].x * 0 + dirs[1].x * 1.3,
dirs[0].y * 0 + dirs[1].y * 1.3,
dirs[0].z * 0 + dirs[1].z * 1.3
);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.YP.rotationDegrees(270));
poseStack.scale(0.75f + alpha * 0.25f, 0.75f + alpha * 0.25f , 0.75f + alpha * 0.25f);
for(int i = 0; i < 3; i++) {
starConsumer.addVertex(poseStack.last().pose(), -starHalfWidth, -starHalfHeight, 0f)
.setColor(color.x, color.y, color.z, alpha * 0.5f).setUv(0.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
starConsumer.addVertex(poseStack.last().pose(), starHalfWidth, -starHalfHeight, 0f)
.setColor(color.x, color.y, color.z, alpha * 0.5f).setUv(1.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
starConsumer.addVertex(poseStack.last().pose(), starHalfWidth, starHalfHeight, 0f)
.setColor(color.x, color.y, color.z, alpha * 0.5f).setUv(1.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
starConsumer.addVertex(poseStack.last().pose(), -starHalfWidth, starHalfHeight, 0f)
.setColor(color.x, color.y, color.z, alpha * 0.5f).setUv(0.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
}
poseStack.popPose();
//闪烁
poseStack.pushPose();
float sparkleHalfWidth = 32 * 0.12f;
float sparkleHalfHeight = 32 * 0.03f;
VertexConsumer sparkleConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES));
poseStack.translate(
dirs[0].x * 2 + dirs[1].x * 1.3,
dirs[0].y * 2 + dirs[1].y * 1.3,
dirs[0].z * 2 + dirs[1].z * 1.3
);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.YP.rotationDegrees(270));
poseStack.scale(alpha, alpha , alpha);
for(int i = 0; i < 3; i++) {
sparkleConsumer.addVertex(poseStack.last().pose(), -sparkleHalfWidth, -sparkleHalfHeight, 0.01f)
.setColor(color.x, color.y, color.z, alpha).setUv(0.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
sparkleConsumer.addVertex(poseStack.last().pose(), sparkleHalfWidth, -sparkleHalfHeight, 0.01f)
.setColor(color.x, color.y, color.z, alpha).setUv(1.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
sparkleConsumer.addVertex(poseStack.last().pose(), sparkleHalfWidth, sparkleHalfHeight, 0.01f)
.setColor(color.x, color.y, color.z, alpha).setUv(1.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
sparkleConsumer.addVertex(poseStack.last().pose(), -sparkleHalfWidth, sparkleHalfHeight, 0.01f)
.setColor(color.x, color.y, color.z, alpha).setUv(0.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
}
poseStack.popPose();
//剑
poseStack.pushPose();
poseStack.translate(
dirs[0].x * 2.2 + dirs[1].x * 1.5,
dirs[0].y * 2.2 + dirs[1].y * 1.5,
dirs[0].z * 2.2 + dirs[1].z * 1.5
);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.YP.rotationDegrees(270));
poseStack.mulPose(Axis.ZP.rotationDegrees(-45));
poseStack.scale(4.0f, 4.0f , 4.0f);
Minecraft.getInstance().getItemRenderer().renderStatic(
item,
ItemDisplayContext.NONE,
LightTexture.FULL_BRIGHT,
OverlayTexture.NO_OVERLAY,
poseStack,
renderType -> {
VertexConsumer vertexConsumer = bufferSource.getBuffer(renderType);
return new TintedVertexConsumer(vertexConsumer, 1.0f, 1.0f, 1.0f, alpha);
},
summon.level(),
0
);
poseStack.popPose();
//模型
poseStack.pushPose();
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.YP.rotationDegrees(180));
poseStack.scale(-1.0F, -1.0F, 1.0F);
poseStack.translate(0.0F, -1.501F, 0.0F);
VertexConsumer modelConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucent(playerSkin.texture()));
int packedColor = FastColor.ARGB32.color(Math.min((int)(alpha * 255), 255), 255, 255, 255);
activeModel.renderToBuffer(poseStack, modelConsumer, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, packedColor);
poseStack.popPose();
//恢复模型
activeModel.rightArm.resetPose();
activeModel.leftArm.resetPose();
activeModel.rightLeg.resetPose();
activeModel.leftLeg.resetPose();
activeModel.rightSleeve.resetPose();
activeModel.leftSleeve.resetPose();
activeModel.rightPants.resetPose();
activeModel.leftPants.resetPose();
activeModel.young = false;
}
@Override @Override
public void tick(StaticSummon summon) { public void tick(StaticSummon summon) {
@@ -412,7 +211,7 @@ public class FirstFractal extends MeleeWeapon {
FilterUtil.createTargetFilter(summon, summon.getOwner()) FilterUtil.createTargetFilter(summon, summon.getOwner())
); );
for(Entity target : targets) { for(Entity target : targets) {
if(DamageUtil.normalAttack(summon, target, (float) getProjectileDamage(), 0.25f)) { if(DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float) getProjectileDamage(), 0.2f)) {
target.invulnerableTime = 10; target.invulnerableTime = 10;
} }
} }
@@ -456,6 +255,7 @@ public class FirstFractal extends MeleeWeapon {
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), player.level()); StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), player.level());
summon.setOwner(player); summon.setOwner(player);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, player.getWeaponItem().copy());
summon.setPos(summonPos); summon.setPos(summonPos);
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.FIRST_FRACTAL_PROJECTILE); summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.FIRST_FRACTAL_PROJECTILE);
summon.getEntityData().set(StaticSummon.RENDER_MODE, "custom"); summon.getEntityData().set(StaticSummon.RENDER_MODE, "custom");
@@ -225,7 +225,7 @@ public class InfluxWaver extends MeleeWeapon {
Entity target = customData.contains("target") ? summon.level().getEntity(customData.getInt("target")) : null; Entity target = customData.contains("target") ? summon.level().getEntity(customData.getInt("target")) : null;
if(target != null && !hitTarget.getUUID().equals(target.getUUID())) return; if(target != null && !hitTarget.getUUID().equals(target.getUUID())) return;
if(summon.getOwner() instanceof Player player && FilterUtil.createTargetFilter(player).test(hitTarget)) { if(summon.getOwner() instanceof Player player && FilterUtil.createTargetFilter(player).test(hitTarget)) {
if(DamageUtil.normalAttack(summon, hitTarget, (float) getDamage(), 1.0f)) { if(DamageUtil.meleeAttack(summon, hitTarget, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float) getDamage(), 1.0f)) {
hitTarget.invulnerableTime = 2; hitTarget.invulnerableTime = 2;
} }
customData.putBoolean("dead", false); customData.putBoolean("dead", false);
@@ -260,6 +260,7 @@ public class InfluxWaver extends MeleeWeapon {
if(player == null) return; if(player == null) return;
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), player.level()); StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), player.level());
summon.setOwner(player); summon.setOwner(player);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, player.getWeaponItem().copy());
summon.setPos(pos); summon.setPos(pos);
//Vector3f[] dirs = MathUtil.computeCoordinateSystem(player); //Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
@@ -3,7 +3,6 @@ package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon; import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.beam.SwordBeam; import com.lzxnone.terraria.entity.beam.SwordBeam;
import com.lzxnone.terraria.entity.projectile.StaticProjectile; import com.lzxnone.terraria.entity.projectile.StaticProjectile;
import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior; import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior;
@@ -18,14 +17,7 @@ import com.lzxnone.terraria.ui.config.IConfigData;
import com.lzxnone.terraria.utils.DamageUtil; import com.lzxnone.terraria.utils.DamageUtil;
import com.lzxnone.terraria.utils.FilterUtil; import com.lzxnone.terraria.utils.FilterUtil;
import com.lzxnone.terraria.utils.ParticleUtil; import com.lzxnone.terraria.utils.ParticleUtil;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis; 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.RenderType;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@@ -44,7 +36,6 @@ import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.event.entity.player.AttackEntityEvent; import net.neoforged.neoforge.event.entity.player.AttackEntityEvent;
import org.joml.Matrix4f;
import org.joml.Vector3f; import org.joml.Vector3f;
import java.util.Comparator; import java.util.Comparator;
@@ -144,44 +135,6 @@ public class LightsBane extends MeleeWeapon {
}; };
public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() { 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;
float lifeRatio = (summon.getEntityData().get(StaticSummon.AGE) + partialTick) / summon.getEntityData().get(StaticSummon.LIFETIME);
if(lifeRatio > 1.0f) return;
int frame = Math.min((int) (lifeRatio * 12.0f), 11);
poseStack.pushPose();
poseStack.mulPose(Minecraft.getInstance().getEntityRenderDispatcher().cameraOrientation());
VertexConsumer consumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES[frame]));
Matrix4f matrix = poseStack.last().pose();
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
float scale;
if(customData.contains("big") && customData.getBoolean("big")) scale = SCALE_BIG;
else scale = SCALE_SMALL;
poseStack.mulPose(Axis.ZP.rotationDegrees(summon.getEntityData().get(StaticSummon.RZP)));
consumer.addVertex(matrix, -HALF_WIDTH * scale, -HALF_HEIGHT * scale, 0)
.setColor(255, 255, 255, 255).setUv(0.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
consumer.addVertex(matrix, HALF_WIDTH * scale, -HALF_HEIGHT * scale, 0)
.setColor(255, 255, 255, 255).setUv(1.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
consumer.addVertex(matrix, HALF_WIDTH * scale, HALF_HEIGHT * scale, 0)
.setColor(255, 255, 255, 255).setUv(1.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
consumer.addVertex(matrix, -HALF_WIDTH * scale, HALF_HEIGHT * scale, 0)
.setColor(255, 255, 255, 255).setUv(0.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
poseStack.popPose();
}
@Override @Override
public void tick(StaticSummon summon) { public void tick(StaticSummon summon) {
@@ -204,7 +157,7 @@ public class LightsBane extends MeleeWeapon {
List<Entity> targets = summon.level().getEntitiesOfClass(Entity.class, summon.getBoundingBox(), FilterUtil.createTargetFilter(summon, summon.getOwner())); List<Entity> targets = summon.level().getEntitiesOfClass(Entity.class, summon.getBoundingBox(), FilterUtil.createTargetFilter(summon, summon.getOwner()));
for(Entity target : targets) { for(Entity target : targets) {
float damage = customData.contains("big") && customData.getBoolean("big") ? (float) getBigDamage() : (float) getSmallDamage(); float damage = customData.contains("big") && customData.getBoolean("big") ? (float) getBigDamage() : (float) getSmallDamage();
if(DamageUtil.normalAttack(summon, target, damage, 1.0f)) { if(DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), damage, 1.0f)) {
} }
} }
@@ -240,6 +193,7 @@ public class LightsBane extends MeleeWeapon {
if(summonTarget != null) { if(summonTarget != null) {
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), player.level()); StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), player.level());
summon.setOwner(player); summon.setOwner(player);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, player.getWeaponItem().copy());
summon.setPos(new Vec3(summonTarget.getX(), summonTarget.getY() + summonTarget.getBbHeight(), summonTarget.getZ())); summon.setPos(new Vec3(summonTarget.getX(), summonTarget.getY() + summonTarget.getBbHeight(), summonTarget.getZ()));
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.LIGHTS_BANE_SLASH); summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.LIGHTS_BANE_SLASH);
summon.getEntityData().set(StaticSummon.RENDER_MODE, "custom"); summon.getEntityData().set(StaticSummon.RENDER_MODE, "custom");
@@ -12,13 +12,7 @@ import com.lzxnone.terraria.entity.summon.StaticSummon;
import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors; import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors;
import com.lzxnone.terraria.item.ModItems; import com.lzxnone.terraria.item.ModItems;
import com.lzxnone.terraria.utils.*; import com.lzxnone.terraria.utils.*;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.core.component.DataComponents; import net.minecraft.core.component.DataComponents;
import net.minecraft.core.particles.BlockParticleOption; import net.minecraft.core.particles.BlockParticleOption;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
@@ -152,111 +146,6 @@ public class Mace extends MeleeWeapon {
public static final double RIGHT_OFFSET = -0.3; public static final double RIGHT_OFFSET = -0.3;
public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileBehavior() { public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileBehavior() {
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticProjectile projectile)) return;
if(projectile.getOwner() == null) return;
ItemStack itemStack = projectile.getEntityData().get(StaticProjectile.ITEM);
if(itemStack == ItemStack.EMPTY) return;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(projectile.getOwner());
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
poseStack.pushPose();
//旋转(方向修正)
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
Minecraft.getInstance().getItemRenderer().renderStatic(
itemStack,
ItemDisplayContext.NONE,
packedLight,
OverlayTexture.NO_OVERLAY,
poseStack,
bufferSource,
entity.level(),
0
);
poseStack.popPose();
poseStack.pushPose();
//旋转(方向修正)
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0] + 90));
Minecraft.getInstance().getItemRenderer().renderStatic(
itemStack,
ItemDisplayContext.NONE,
packedLight,
OverlayTexture.NO_OVERLAY,
poseStack,
bufferSource,
entity.level(),
0
);
poseStack.popPose();
if(projectile.getOwner() == null) return;
Vec3 eyePos = projectile.getOwner().getEyePosition();
Vec3 start = eyePos.add(new Vec3(
dirs[0].x * DIRECTION_OFFSET + dirs[1].x * UP_OFFSET + dirs[2].x * RIGHT_OFFSET,
dirs[0].y * DIRECTION_OFFSET + dirs[1].y * UP_OFFSET + dirs[2].y * RIGHT_OFFSET,
dirs[0].z * DIRECTION_OFFSET + dirs[1].z * UP_OFFSET + dirs[2].z * RIGHT_OFFSET
));
Vec3 end = projectile.getPosition(partialTick);
double dist = end.subtract(start).length();
Vector3f[] dirs2 = MathUtil.computeCoordinateSystem(end.subtract(start).toVector3f(), 0);
Vec3 dir = MathUtil.toVec3(dirs2[0]);
Vec3 right = MathUtil.toVec3(dirs2[2]);
Vec3 up = MathUtil.toVec3(dirs2[1]);
VertexConsumer vertexConsumer = bufferSource.getBuffer(RenderType.entityCutoutNoCull(RES));
int count = (int) (dist / CHAIN_LENGTH);
for(int j = 0;j < 2;j++) {
for(int i = 0; i < count; i++) {
Vec3 current = start.add(new Vec3(
dir.x * i * CHAIN_LENGTH,
dir.y * i * CHAIN_LENGTH,
dir.z * i * CHAIN_LENGTH
)).subtract(projectile.getPosition(partialTick));
Vec3 next = start.add(new Vec3(
dir.x * (i + 1) * CHAIN_LENGTH,
dir.y * (i + 1) * CHAIN_LENGTH,
dir.z * (i + 1) * CHAIN_LENGTH
)).subtract(projectile.getPosition(partialTick));
Vec3 p1, p2, p3, p4;
if(j == 0) {
p1 = current.add(right.scale(0.125));
p2 = current.add(right.scale(-0.125));
p3 = next.add(right.scale(-0.125));
p4 = next.add(right.scale(0.125));
}else {
p1 = current.add(up.scale(0.125));
p2 = current.add(up.scale(-0.125));
p3 = next.add(up.scale(-0.125));
p4 = next.add(up.scale(0.125));
}
vertexConsumer.addVertex(poseStack.last().pose(), (float) p1.x, (float) p1.y, (float) p1.z)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(0.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float) p2.x, (float) p2.y, (float) p2.z)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(0.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float) p3.x, (float) p3.y, (float) p3.z)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(1.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float) p4.x, (float) p4.y, (float) p4.z)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(1.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
}
}
}
@Override @Override
public void onMoving(StaticProjectile projectile) { public void onMoving(StaticProjectile projectile) {
@@ -295,7 +184,7 @@ public class Mace extends MeleeWeapon {
FilterUtil.createTargetFilter(projectile, player) FilterUtil.createTargetFilter(projectile, player)
); );
for(Entity target : targets) { for(Entity target : targets) {
if(DamageUtil.normalAttack(projectile, target, (float) getDamage(), 1.0f)) { if(DamageUtil.meleeAttack(projectile, target, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE), (float) getDamage(), 1.0f)) {
target.invulnerableTime = 15; target.invulnerableTime = 15;
} }
} }
@@ -318,108 +207,6 @@ public class Mace extends MeleeWeapon {
}; };
public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() { 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;
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())));
Minecraft.getInstance().getItemRenderer().renderStatic(
itemStack,
ItemDisplayContext.NONE,
packedLight,
OverlayTexture.NO_OVERLAY,
poseStack,
bufferSource,
entity.level(),
0
);
poseStack.popPose();
poseStack.pushPose();
//旋转(方向修正)
poseStack.mulPose(Axis.YP.rotationDegrees(-Mth.lerp(partialTick, summon.yRotO, summon.getYRot())));
poseStack.mulPose(Axis.XP.rotationDegrees(Mth.lerp(partialTick, summon.xRotO + 90, summon.getXRot() + 90)));
Minecraft.getInstance().getItemRenderer().renderStatic(
itemStack,
ItemDisplayContext.NONE,
packedLight,
OverlayTexture.NO_OVERLAY,
poseStack,
bufferSource,
entity.level(),
0
);
poseStack.popPose();
if(summon.getOwner() == null) return;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(summon.getOwner());
Vec3 eyePos = summon.getOwner().getEyePosition();
Vec3 start = eyePos.add(new Vec3(
dirs[0].x * DIRECTION_OFFSET + dirs[1].x * UP_OFFSET + dirs[2].x * RIGHT_OFFSET,
dirs[0].y * DIRECTION_OFFSET + dirs[1].y * UP_OFFSET + dirs[2].y * RIGHT_OFFSET,
dirs[0].z * DIRECTION_OFFSET + dirs[1].z * UP_OFFSET + dirs[2].z * RIGHT_OFFSET
));
Vec3 end = summon.getPosition(partialTick);
double dist = end.subtract(start).length();
Vector3f[] dirs2 = MathUtil.computeCoordinateSystem(end.subtract(start).toVector3f(), 0);
Vec3 dir = MathUtil.toVec3(dirs2[0]);
Vec3 right = MathUtil.toVec3(dirs2[2]);
Vec3 up = MathUtil.toVec3(dirs2[1]);
VertexConsumer vertexConsumer = bufferSource.getBuffer(RenderType.entityCutoutNoCull(RES));
int count = (int) (dist / CHAIN_LENGTH);
for(int j = 0;j < 2;j++) {
for(int i = 0; i < count; i++) {
Vec3 current = start.add(new Vec3(
dir.x * i * CHAIN_LENGTH,
dir.y * i * CHAIN_LENGTH,
dir.z * i * CHAIN_LENGTH
)).subtract(summon.getPosition(partialTick));
Vec3 next = start.add(new Vec3(
dir.x * (i + 1) * CHAIN_LENGTH,
dir.y * (i + 1) * CHAIN_LENGTH,
dir.z * (i + 1) * CHAIN_LENGTH
)).subtract(summon.getPosition(partialTick));
Vec3 p1, p2, p3, p4;
if(j == 0) {
p1 = current.add(right.scale(0.125));
p2 = current.add(right.scale(-0.125));
p3 = next.add(right.scale(-0.125));
p4 = next.add(right.scale(0.125));
}else {
p1 = current.add(up.scale(0.125));
p2 = current.add(up.scale(-0.125));
p3 = next.add(up.scale(-0.125));
p4 = next.add(up.scale(0.125));
}
vertexConsumer.addVertex(poseStack.last().pose(), (float) p1.x, (float) p1.y, (float) p1.z)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(0.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float) p2.x, (float) p2.y, (float) p2.z)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(0.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float) p3.x, (float) p3.y, (float) p3.z)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(1.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float) p4.x, (float) p4.y, (float) p4.z)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(1.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(packedLight).setNormal(0, 1, 0);
}
}
}
@Override @Override
public AABB getBoundingBoxForCulling(StaticSummon summon) { public AABB getBoundingBoxForCulling(StaticSummon summon) {
@@ -509,7 +296,7 @@ public class Mace extends MeleeWeapon {
EntityHitResult entityHitResult = CollisionUtil.checkEntityHit(summon, summon.position().add(summon.getDeltaMovement())); EntityHitResult entityHitResult = CollisionUtil.checkEntityHit(summon, summon.position().add(summon.getDeltaMovement()));
if(entityHitResult != null) { if(entityHitResult != null) {
Entity target = entityHitResult.getEntity(); Entity target = entityHitResult.getEntity();
if(DamageUtil.normalAttack(summon, target, (float) getDamage(), 1.0f)) { if(DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float) getDamage(), 1.0f)) {
target.invulnerableTime = 10; target.invulnerableTime = 10;
} }
} }
@@ -528,16 +315,38 @@ public class Mace extends MeleeWeapon {
FilterUtil.createTargetFilter(summon, summon.getOwner()) FilterUtil.createTargetFilter(summon, summon.getOwner())
); );
for(Entity target : targets) { for(Entity target : targets) {
DamageUtil.normalAttack(summon, target, (float) getDamage(), 1.0f); DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float) getDamage(), 1.0f);
} }
}else if(state == State.THROWING_BACK.ordinal()){ }else if(state == State.THROWING_BACK.ordinal()){
Vec3 moveDir = player.getEyePosition().subtract(summon.position()); Vec3 moveDir = player.getEyePosition().subtract(summon.position());
double dist = moveDir.length(); double dist = moveDir.length();
summon.setDeltaMovement(moveDir.normalize().scale(getProjectileSpeed())); summon.setDeltaMovement(moveDir.normalize().scale(getProjectileSpeed()));
if(!summon.noPhysics) {
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
BlockHitResult blockHitResult = CollisionUtil.checkBlockHit(summon, summon.position().add(summon.getDeltaMovement()));
if(blockHitResult.getType() != HitResult.Type.MISS) {
int hitBlockCount = customData.contains("hitBlockCount") ? customData.getInt("hitBlockCount") : 0;
if(hitBlockCount > 10) {
summon.noPhysics = true;
}else {
customData.putInt("hitBlockCount", hitBlockCount + 1);
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
}
if(summon.level() instanceof ServerLevel serverLevel) {
BlockState hitState = serverLevel.getBlockState(blockHitResult.getBlockPos());
ParticleUtil.addParticles(
serverLevel, new BlockParticleOption(ParticleTypes.BLOCK, hitState),
blockHitResult.getLocation(), new Vec3(0, 0, 0),
0.2, 25
);
SoundUtil.playServerSound(serverLevel, ModSounds.DIG.get(), blockHitResult.getLocation());
}
}
}
EntityHitResult entityHitResult = CollisionUtil.checkEntityHit(summon, summon.position().add(summon.getDeltaMovement())); EntityHitResult entityHitResult = CollisionUtil.checkEntityHit(summon, summon.position().add(summon.getDeltaMovement()));
if(entityHitResult != null) { if(entityHitResult != null) {
Entity target = entityHitResult.getEntity(); Entity target = entityHitResult.getEntity();
if(DamageUtil.normalAttack(summon, target, (float) getDamage(), 1.0f)) { if(DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float) getDamage(), 1.0f)) {
target.invulnerableTime = 10; target.invulnerableTime = 10;
} }
} }
@@ -573,6 +382,7 @@ public class Mace extends MeleeWeapon {
if(state == State.IDLE.ordinal()) { if(state == State.IDLE.ordinal()) {
StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level); StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level);
projectile.setOwner(player); projectile.setOwner(player);
projectile.getEntityData().set(StaticProjectile.STACK_SOURCE, player.getWeaponItem().copy());
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player); Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ()); Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ());
@@ -618,6 +428,7 @@ public class Mace extends MeleeWeapon {
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]); float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level); StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level);
summon.setOwner(player); summon.setOwner(player);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, player.getWeaponItem().copy());
Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ()); Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ());
summon.setPos(pos); summon.setPos(pos);
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.MACE_PROJECTILE); summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.MACE_PROJECTILE);
@@ -639,7 +450,6 @@ public class Mace extends MeleeWeapon {
level.addFreshEntity(summon); level.addFreshEntity(summon);
} }
}else if(state == State.DROPPING.ordinal()) { }else if(state == State.DROPPING.ordinal()) {
CustomData.update(DataComponents.CUSTOM_DATA, stack, CustomData.update(DataComponents.CUSTOM_DATA, stack,
tag -> tag.putInt("state", State.THROWING_BACK.ordinal())); tag -> tag.putInt("state", State.THROWING_BACK.ordinal()));
@@ -4,7 +4,6 @@ import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds; import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior; import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior;
import com.lzxnone.terraria.entity.summon.StaticSummon; import com.lzxnone.terraria.entity.summon.StaticSummon;
import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors; import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors;
@@ -15,12 +14,6 @@ import com.lzxnone.terraria.ui.config.ConfigListItem;
import com.lzxnone.terraria.ui.config.ConfigUtil; import com.lzxnone.terraria.ui.config.ConfigUtil;
import com.lzxnone.terraria.ui.config.IConfigData; import com.lzxnone.terraria.ui.config.IConfigData;
import com.lzxnone.terraria.utils.*; 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.core.Direction;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
@@ -38,7 +31,6 @@ import net.minecraft.world.item.*;
import net.minecraft.world.item.component.ItemAttributeModifiers; import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.*; import net.minecraft.world.phys.*;
import org.joml.Matrix4f;
import org.joml.Vector3f; import org.joml.Vector3f;
import java.util.List; import java.util.List;
@@ -137,58 +129,6 @@ public class Meowmere extends MeleeWeapon {
public static final ResourceLocation RES = ResourceLocation.parse("lzxnoneterraria:textures/vfx/rainbow.png"); public static final ResourceLocation RES = ResourceLocation.parse("lzxnoneterraria:textures/vfx/rainbow.png");
public static final int MAX_LENGTH = 100; 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));
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.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 @Override
public void tick(StaticSummon summon) { public void tick(StaticSummon summon) {
@@ -207,7 +147,7 @@ public class Meowmere extends MeleeWeapon {
if(entityHitResult != null) { if(entityHitResult != null) {
Entity target = entityHitResult.getEntity(); Entity target = entityHitResult.getEntity();
if(summon.getOwner() instanceof Player player) { if(summon.getOwner() instanceof Player player) {
if(DamageUtil.normalAttack(summon, target, (float) getDamage(), 1.0f)) { if(DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float) getDamage(), 1.0f)) {
if(customData.contains("hitEntity") && customData.getInt("hitEntity") < 4) { if(customData.contains("hitEntity") && customData.getInt("hitEntity") < 4) {
customData.putInt("hitEntity", customData.getInt("hitEntity") + 1); customData.putInt("hitEntity", customData.getInt("hitEntity") + 1);
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData); summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
@@ -338,6 +278,7 @@ public class Meowmere extends MeleeWeapon {
if(!level.isClientSide()) { if(!level.isClientSide()) {
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level); StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level);
summon.setOwner(player); summon.setOwner(player);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, player.getWeaponItem().copy());
Vec3 pos = player.getBoundingBox().getCenter(); Vec3 pos = player.getBoundingBox().getCenter();
summon.setPos(pos); summon.setPos(pos);
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.MEOWMERE_PROJECTILE); summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.MEOWMERE_PROJECTILE);
@@ -3,7 +3,6 @@ package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon; import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.projectile.IStaticProjectileBehavior; import com.lzxnone.terraria.entity.projectile.IStaticProjectileBehavior;
import com.lzxnone.terraria.entity.projectile.StaticProjectile; import com.lzxnone.terraria.entity.projectile.StaticProjectile;
import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors; import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors;
@@ -14,12 +13,6 @@ import com.lzxnone.terraria.utils.DamageUtil;
import com.lzxnone.terraria.utils.FilterUtil; import com.lzxnone.terraria.utils.FilterUtil;
import com.lzxnone.terraria.utils.MathUtil; import com.lzxnone.terraria.utils.MathUtil;
import com.lzxnone.terraria.utils.ParticleUtil; import com.lzxnone.terraria.utils.ParticleUtil;
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.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlotGroup; import net.minecraft.world.entity.EquipmentSlotGroup;
@@ -35,7 +28,6 @@ import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.event.entity.player.AttackEntityEvent; import net.neoforged.neoforge.event.entity.player.AttackEntityEvent;
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
import org.joml.Matrix4f;
import org.joml.Vector3f; import org.joml.Vector3f;
import com.lzxnone.terraria.ui.config.ConfigFactory; import com.lzxnone.terraria.ui.config.ConfigFactory;
import com.lzxnone.terraria.ui.config.ConfigListItem; import com.lzxnone.terraria.ui.config.ConfigListItem;
@@ -148,6 +140,7 @@ public class Muramasa extends MeleeWeapon {
StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), player.level()); StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), player.level());
projectile.setOwner(player); projectile.setOwner(player);
projectile.getEntityData().set(StaticProjectile.STACK_SOURCE, player.getWeaponItem().copy());
Vec3 start = MathUtil.getRandomPosInRadius(player.position(), 5); Vec3 start = MathUtil.getRandomPosInRadius(player.position(), 5);
Vec3 end = livingTarget.getBoundingBox().getCenter(); Vec3 end = livingTarget.getBoundingBox().getCenter();
@@ -191,54 +184,6 @@ public class Muramasa extends MeleeWeapon {
public static final ResourceLocation RES = ResourceLocation.parse("lzxnoneterraria:textures/vfx/muramasa_trail.png"); public static final ResourceLocation RES = ResourceLocation.parse("lzxnoneterraria:textures/vfx/muramasa_trail.png");
public static final int MAX_LENGTH = 100; 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 StaticProjectile projectile)) return;
Vec3 currentPos = projectile.getPosition(partialTick);
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES));
Matrix4f matrix = poseStack.last().pose();
int quadCount = projectile.trailPositions.size() / 2 - 1;
for(int i = 0; i < quadCount;i++) {
Vec3 currentPoint1 = projectile.trailPositions.get(i * 2);
Vec3 currentPoint2 = projectile.trailPositions.get(i * 2 + 1);
Vec3 nextPoint1 = projectile.trailPositions.get(i * 2 + 3);
Vec3 nextPoint2 = projectile.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 radio1 = (float) i / quadCount;
float radio2 = (float) (i + 1) / quadCount;
vertexConsumer.addVertex(matrix, (float)x1, (float)y1, (float)z1)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(radio1, 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, 1.0f).setUv(radio1, 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, 1.0f).setUv(radio2, 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, 1.0f).setUv(radio2, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
}
}
@Override @Override
public void onMoving(StaticProjectile projectile) { public void onMoving(StaticProjectile projectile) {
@@ -261,7 +206,7 @@ public class Muramasa extends MeleeWeapon {
Entity owner = projectile.getOwner(); Entity owner = projectile.getOwner();
if(owner == null) return; if(owner == null) return;
if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return; if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(DamageUtil.normalAttack(projectile, target, (float) getBeamDamage(), 1.0f)) { if(DamageUtil.meleeAttack(projectile, target, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE), (float) getBeamDamage(), 1.0f)) {
} }
} }
@@ -4,7 +4,6 @@ import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds; import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.beam.ISwordBeamBehavior; import com.lzxnone.terraria.entity.beam.ISwordBeamBehavior;
import com.lzxnone.terraria.entity.beam.SwordBeam; import com.lzxnone.terraria.entity.beam.SwordBeam;
import com.lzxnone.terraria.entity.beam.SwordBeamBehaviors; import com.lzxnone.terraria.entity.beam.SwordBeamBehaviors;
@@ -16,12 +15,8 @@ import com.lzxnone.terraria.network.payload.SwordBeamPayload;
import com.lzxnone.terraria.particle.DustParticleOptions; import com.lzxnone.terraria.particle.DustParticleOptions;
import com.lzxnone.terraria.particle.ModParticles; import com.lzxnone.terraria.particle.ModParticles;
import com.lzxnone.terraria.utils.*; import com.lzxnone.terraria.utils.*;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@@ -212,92 +207,6 @@ public class NightsEdge extends MeleeWeapon {
); );
public static final ISwordBeamBehavior SWORD_BEAM_BEHAVIOR = new ISwordBeamBehavior() { public static final ISwordBeamBehavior SWORD_BEAM_BEHAVIOR = new ISwordBeamBehavior() {
@Override
public 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) return;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(beam.getOwner());
dirs = MathUtil.rotateCoordinateSystem(dirs[0], dirs[2], beam.getEntityData().get(SwordBeam.ROTATE));
float rotate = beam.getEntityData().get(SwordBeam.ROTATE);
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;
}
if (beam.getEntityData().get(SwordBeam.RIGHT)) progress = 1.0f - progress;
float halfWidth = SwordBeam.HALF_WIDTH * SwordBeam.SCALE;
float halfHeight = SwordBeam.HALF_HEIGHT * SwordBeam.SCALE;
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES0));
//左边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress - 0.1f * (1.0f - progress)) * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress - 0.1f * (1.0f - progress))) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color0.x(), color0.y(), color0.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.01f);
poseStack.popPose();
//右边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.1f) * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress + 0.05f)) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color2.x(), color2.y(), color2.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.02f);
poseStack.popPose();
//中间
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], progress * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color1.x(), color1.y(), color1.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0f);
poseStack.popPose();
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES3));
//外线
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], progress * 180, SwordBeam.DIST * 1.15f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(0.95f, 0.95f, 0.95f);
renderQuad(poseStack.last().pose(), vertexConsumer1,
color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.02f);
poseStack.popPose();
VertexConsumer vertexConsumer2 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES5));
//闪烁
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.25f) * 180, SwordBeam.DIST * 2.25f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress - 0.25f) * 180, rotate);
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(), vertexConsumer2,
color1.x(), color1.y(), color1.z(), alpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.03f);
}
poseStack.popPose();
}
@Override @Override
public void onMoving(SwordBeam beam) { public void onMoving(SwordBeam beam) {
@@ -318,7 +227,7 @@ public class NightsEdge extends MeleeWeapon {
if(custom_data.contains("hitEntityCount")) { if(custom_data.contains("hitEntityCount")) {
int count = custom_data.getInt("hitEntityCount"); int count = custom_data.getInt("hitEntityCount");
if(count < getMaxHitCount()) { if(count < getMaxHitCount()) {
if(DamageUtil.normalAttack(beam, target, (float) getDamage(), 1.0f)) { if(DamageUtil.meleeAttack(beam, target, beam.getEntityData().get(SwordBeam.STACK_SOURCE), (float) getDamage(), 1.0f)) {
ParticleUtil.addParticles( ParticleUtil.addParticles(
(ServerLevel) target.level(), ModParticles.NIGHTS_EDGE_HIT_PARTICLE.get(), (ServerLevel) target.level(), ModParticles.NIGHTS_EDGE_HIT_PARTICLE.get(),
new Vec3(target.getX(), target.getY() + target.getBbHeight() / 2.0, target.getZ()), new Vec3(0, 0, 0), new Vec3(target.getX(), target.getY() + target.getBbHeight() / 2.0, target.getZ()), new Vec3(0, 0, 0),
@@ -354,89 +263,6 @@ public class NightsEdge extends MeleeWeapon {
public static final float FADE_OUT = 0.67f; public static final float FADE_OUT = 0.67f;
public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() { 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;
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;
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
Vector3f dir = new Vector3f();
if (customData.contains("dirX")) dir.x = customData.getFloat("dirX");
if (customData.contains("dirY")) dir.y = customData.getFloat("dirY");
if (customData.contains("dirZ")) dir.z = customData.getFloat("dirZ");
Vector3f up = new Vector3f();
if (customData.contains("upX")) up.x = customData.getFloat("upX");
if (customData.contains("upY")) up.y = customData.getFloat("upY");
if (customData.contains("upZ")) up.z = customData.getFloat("upZ");
Vector3f right = new Vector3f();
if (customData.contains("rightX")) right.x = customData.getFloat("rightX");
if (customData.contains("rightY")) right.y = customData.getFloat("rightY");
if (customData.contains("rightZ")) right.z = customData.getFloat("rightZ");
Vector3f[] dirs = new Vector3f[]{dir, up, right};
double rotate = summon.getEntityData().get(StaticSummon.RZP);
double rotateSpeed = summon.getEntityData().get(StaticSummon.RZPS);
float rotateAngle = (float) ((summon.getEntityData().get(StaticSummon.AGE) + partialTick) * rotateSpeed);
Quaternionf rotation = new Quaternionf().fromAxisAngleRad(
up, (float) Math.toRadians(-rotateAngle)
);
poseStack.mulPose(rotation);
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES0));
//外层(亮)
poseStack.pushPose();
poseStack.mulPose(rotation);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
//poseStack.scale(1.0f + progress, 1.0f + progress, 1.0f + progress);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR0.x(), COLOR0.y(), COLOR0.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0f);
poseStack.popPose();
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES1));
//外线
poseStack.pushPose();
poseStack.mulPose(rotation);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST * 1.15f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
//poseStack.scale(0.95f * (1 + progress), 0.95f * (1 + progress), 0.95f * (1 + progress));
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer1,
1.0f, 1.0f, 1.0f, alpha, halfWidth, halfHeight, 0f, 0f, 0.02f);
poseStack.popPose();
VertexConsumer vertexConsumer2 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES2));
//闪烁
poseStack.pushPose();
poseStack.mulPose(rotation);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 135, SwordBeam.DIST * 2.25f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
//poseStack.scale(1.0f + progress, 1.0f + progress, 1.0f + progress);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer2,
COLOR0.x(), COLOR0.y(), COLOR0.z(), alpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.04f);
poseStack.popPose();
}
@Override @Override
public void tick(StaticSummon summon) { public void tick(StaticSummon summon) {
@@ -459,7 +285,7 @@ public class NightsEdge extends MeleeWeapon {
List<Entity> targets = summon.level().getEntitiesOfClass(Entity.class, summon.getBoundingBox(), FilterUtil.createTargetFilter(summon, summon.getOwner())); List<Entity> targets = summon.level().getEntitiesOfClass(Entity.class, summon.getBoundingBox(), FilterUtil.createTargetFilter(summon, summon.getOwner()));
for(Entity target : targets) { for(Entity target : targets) {
if(count >= getProjectileMaxHitCount()) break; if(count >= getProjectileMaxHitCount()) break;
if(DamageUtil.normalAttack(summon, target, (float) getProjectileDamage(), 1.0f)) { if(DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float) getProjectileDamage(), 1.0f)) {
count++; count++;
ParticleUtil.addParticles( ParticleUtil.addParticles(
(ServerLevel) target.level(), ModParticles.NIGHTS_EDGE_HIT_PARTICLE.get(), (ServerLevel) target.level(), ModParticles.NIGHTS_EDGE_HIT_PARTICLE.get(),
@@ -500,6 +326,7 @@ public class NightsEdge extends MeleeWeapon {
public static void summon(Player player, int randomAngle) { public static void summon(Player player, int randomAngle) {
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), player.level()); StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), player.level());
summon.setOwner(player); summon.setOwner(player);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, player.getWeaponItem().copy());
Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ()); Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ());
summon.setPos(pos); summon.setPos(pos);
@@ -146,7 +146,7 @@ public class Seedler extends MeleeWeapon {
if(entityHitResult != null) { if(entityHitResult != null) {
Entity target = entityHitResult.getEntity(); Entity target = entityHitResult.getEntity();
if(summon.getOwner() instanceof Player player) { if(summon.getOwner() instanceof Player player) {
if(DamageUtil.normalAttack(summon, target, (float) getThornDamage(), 1.0f)) { if(DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float) getThornDamage(), 1.0f)) {
target.invulnerableTime = 2; target.invulnerableTime = 2;
} }
} }
@@ -206,6 +206,7 @@ public class Seedler extends MeleeWeapon {
StaticProjectile proj = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), summon.level()); StaticProjectile proj = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), summon.level());
proj.setOwner(summon.getOwner()); proj.setOwner(summon.getOwner());
proj.getEntityData().set(StaticProjectile.STACK_SOURCE, summon.getEntityData().get(StaticSummon.STACK_SOURCE).copy());
proj.setPos(summon.position()); proj.setPos(summon.position());
proj.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.SEEDLER_THORN); proj.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.SEEDLER_THORN);
proj.getEntityData().set(StaticProjectile.RENDER_MODE, "item"); proj.getEntityData().set(StaticProjectile.RENDER_MODE, "item");
@@ -262,7 +263,7 @@ public class Seedler extends MeleeWeapon {
Entity owner = projectile.getOwner(); Entity owner = projectile.getOwner();
if(owner == null) return; if(owner == null) return;
if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return; if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(DamageUtil.normalAttack(projectile, target, (float) getThornDamage(), 1.0f)) { if(DamageUtil.meleeAttack(projectile, target, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE), (float) getThornDamage(), 1.0f)) {
target.invulnerableTime = 2; target.invulnerableTime = 2;
onDied(projectile); onDied(projectile);
} }
@@ -284,6 +285,7 @@ public class Seedler extends MeleeWeapon {
if(!level.isClientSide()) { if(!level.isClientSide()) {
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level); StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level);
summon.setOwner(player); summon.setOwner(player);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, player.getWeaponItem().copy());
Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ()); Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ());
summon.setPos(pos); summon.setPos(pos);
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.SEEDLER_NUT); summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.SEEDLER_NUT);
@@ -140,7 +140,7 @@ public class StarWrath extends MeleeWeapon {
Entity target = result.getEntity(); Entity target = result.getEntity();
Entity owner = projectile.getOwner(); Entity owner = projectile.getOwner();
if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return; if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(DamageUtil.normalAttack(projectile, target, (float) getDamage(), 1.0f)) { if(DamageUtil.meleeAttack(projectile, target, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE), (float) getDamage(), 0.2f)) {
target.invulnerableTime = 2; target.invulnerableTime = 2;
} }
} }
@@ -220,6 +220,7 @@ public class StarWrath extends MeleeWeapon {
StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level); StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level);
projectile.setOwner(player); projectile.setOwner(player);
projectile.getEntityData().set(StaticProjectile.STACK_SOURCE, player.getWeaponItem().copy());
projectile.setPos(spawnPos); projectile.setPos(spawnPos);
projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.STAR_WRATH_STAR); projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.STAR_WRATH_STAR);
projectile.getEntityData().set(StaticProjectile.RENDER_MODE, "item"); projectile.getEntityData().set(StaticProjectile.RENDER_MODE, "item");
@@ -120,7 +120,7 @@ public class Starfury extends MeleeWeapon {
Entity owner = projectile.getOwner(); Entity owner = projectile.getOwner();
if(owner == null) return; if(owner == null) return;
if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return; if(!FilterUtil.createTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(DamageUtil.normalAttack(projectile, target, (float) getDamage(), 1.0f)) { if(DamageUtil.meleeAttack(projectile, target, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE), (float) getDamage(), 1.0f)) {
target.invulnerableTime = 5; target.invulnerableTime = 5;
} }
} }
@@ -179,6 +179,7 @@ public class Starfury extends MeleeWeapon {
StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level); StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level);
projectile.setOwner(player); projectile.setOwner(player);
projectile.getEntityData().set(StaticProjectile.STACK_SOURCE, player.getWeaponItem().copy());
projectile.setPos(spawnPos); projectile.setPos(spawnPos);
projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.STARFURY_STAR); projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.STARFURY_STAR);
projectile.getEntityData().set(StaticProjectile.RENDER_MODE, "item"); projectile.getEntityData().set(StaticProjectile.RENDER_MODE, "item");
@@ -4,7 +4,6 @@ import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds; import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.beam.ISwordBeamBehavior; import com.lzxnone.terraria.entity.beam.ISwordBeamBehavior;
import com.lzxnone.terraria.entity.beam.SwordBeam; import com.lzxnone.terraria.entity.beam.SwordBeam;
import com.lzxnone.terraria.entity.beam.SwordBeamBehaviors; import com.lzxnone.terraria.entity.beam.SwordBeamBehaviors;
@@ -20,11 +19,8 @@ import com.lzxnone.terraria.ui.config.ConfigListItem;
import com.lzxnone.terraria.ui.config.ConfigUtil; import com.lzxnone.terraria.ui.config.ConfigUtil;
import com.lzxnone.terraria.ui.config.IConfigData; import com.lzxnone.terraria.ui.config.IConfigData;
import com.lzxnone.terraria.utils.*; import com.lzxnone.terraria.utils.*;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@@ -220,7 +216,7 @@ public class TerraBlade extends MeleeWeapon {
if(custom_data.contains("hitEntityCount")) { if(custom_data.contains("hitEntityCount")) {
int count = custom_data.getInt("hitEntityCount"); int count = custom_data.getInt("hitEntityCount");
if(count < getSwordBeamMaxHitCount()) { if(count < getSwordBeamMaxHitCount()) {
if(DamageUtil.normalAttack(beam, target, (float)getSwordBeamDamage(), 0.1f)) { if(DamageUtil.meleeAttack(beam, target, beam.getEntityData().get(SwordBeam.STACK_SOURCE), (float)getSwordBeamDamage(), 0.1f)) {
target.invulnerableTime = 20; target.invulnerableTime = 20;
count++; count++;
custom_data.putInt("hitEntityCount", count); custom_data.putInt("hitEntityCount", count);
@@ -254,206 +250,6 @@ public class TerraBlade extends MeleeWeapon {
public static final float FADE_OUT = 0.67f; public static final float FADE_OUT = 0.67f;
public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() { 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;
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;
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
Vector3f dir = new Vector3f();
if(customData.contains("dirX")) dir.x = customData.getFloat("dirX");
if(customData.contains("dirY")) dir.y = customData.getFloat("dirY");
if(customData.contains("dirZ")) dir.z = customData.getFloat("dirZ");
Vector3f up = new Vector3f();
if(customData.contains("upX")) up.x = customData.getFloat("upX");
if(customData.contains("upY")) up.y = customData.getFloat("upY");
if(customData.contains("upZ")) up.z = customData.getFloat("upZ");
Vector3f right = new Vector3f();
if(customData.contains("rightX")) right.x = customData.getFloat("rightX");
if(customData.contains("rightY")) right.y = customData.getFloat("rightY");
if(customData.contains("rightZ")) right.z = customData.getFloat("rightZ");
Vector3f[] dirs = new Vector3f[]{dir, up, right};
double rotate = summon.getEntityData().get(StaticSummon.RZP);
poseStack.pushPose();
float size = 1.0f - 0.25f * progress;
poseStack.scale(size, size, size);
float[] dz = {0.1f, 0f, -0.1f};
for(int x = 0;x < 3;x++) {
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES0));
//左边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90 - 18 * (1.0f - progress), SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 18 * (1.0f - progress), rotate);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR0.x(), COLOR0.y(), COLOR0.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.01f + dz[x]);
poseStack.popPose();
//中间
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR1.x(), COLOR1.y(), COLOR1.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0f + dz[x]);
poseStack.popPose();
//右边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 108, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], -9 * (1.0f - progress), rotate);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR2.x(), COLOR2.y(), COLOR2.z(), alpha, halfWidth, halfHeight, 0f, 0, 0.01f + dz[x]);
poseStack.popPose();
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES1));
//三线
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST / 1.5f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
poseStack.scale(0.5f, 0.5f, 0.5f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer1,
1.0f, 1.0f, 1.0f, alpha, halfWidth, halfHeight, 0f, 0f, 0.02f + dz[x]);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST / 1.25f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
poseStack.scale(0.75f, 0.75f, 0.75f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer1,
1.0f, 1.0f, 1.0f, alpha, halfWidth, halfHeight, 0f, 0f, 0.02f + dz[x]);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST * 1.15f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
poseStack.scale(0.95f, 0.95f, 0.95f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer1,
1.0f, 1.0f, 1.0f, alpha, halfWidth, halfHeight, 0f, 0f, 0.02f + dz[x]);
poseStack.popPose();
VertexConsumer vertexConsumer2 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES2));
//边缘高光
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 100, SwordBeam.DIST * 1.15f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
poseStack.scale(1.0f, 1.0f, 1.0f);
for (int i = 0; i < 5; i++) {
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer2,
COLOR2.x(), COLOR2.y(), COLOR2.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.03f + dz[x]);
}
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);
}
VertexConsumer vertexConsumer3 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES3));
//闪烁(外层)
poseStack.pushPose();
for (int k = 0; k < 2; k++) {
poseStack.pushPose();
if (k == 0) {
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90 - 60.0 * progress, SwordBeam.DIST * 2f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 60 * progress, rotate);
} else {
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90 + 60.0 * progress, SwordBeam.DIST * 2f + 0.5f * progress);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], -60 * progress, rotate);
}
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++) {
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer3,
COLOR2.x(), COLOR2.y(), COLOR2.z(), sparkleAlpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.03f + dz[x]);
}
poseStack.popPose();
}
poseStack.popPose();
}
poseStack.popPose();
//闪烁(中层)
poseStack.pushPose();
for (int k = 0; k < 2; k++) {
poseStack.pushPose();
if (k == 0) {
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90 - 30.0 * progress, SwordBeam.DIST * 2f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 30 * progress, rotate);
} else {
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90 + 30.0 * progress, SwordBeam.DIST * 2.1f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], -30 * progress, rotate);
}
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++) {
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer3,
COLOR2.x(), COLOR2.y(), COLOR2.z(), sparkleAlpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.03f + dz[x]);
}
poseStack.popPose();
}
poseStack.popPose();
}
poseStack.popPose();
//闪烁(内层)
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST * 2f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
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++) {
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer3,
COLOR2.x(), COLOR2.y(), COLOR2.z(), sparkleAlpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.03f + dz[x]);
}
poseStack.popPose();
}
poseStack.popPose();
}
poseStack.popPose();
}
@Override @Override
public void tick(StaticSummon summon) { public void tick(StaticSummon summon) {
@@ -488,7 +284,7 @@ public class TerraBlade extends MeleeWeapon {
int count = customData.getInt("hitCount"); int count = customData.getInt("hitCount");
List<Entity> targets = summon.level().getEntitiesOfClass(Entity.class, summon.getBoundingBox(), FilterUtil.createTargetFilter(summon, summon.getOwner())); List<Entity> targets = summon.level().getEntitiesOfClass(Entity.class, summon.getBoundingBox(), FilterUtil.createTargetFilter(summon, summon.getOwner()));
for(Entity target : targets) { for(Entity target : targets) {
if(DamageUtil.normalAttack(summon, target, (float)getProjectileDamage() * (float)Math.pow(getProjectileDamageDecay(), count), 0.1f)) { if(DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float)getProjectileDamage() * (float)Math.pow(getProjectileDamageDecay(), count), 0.1f)) {
count++; count++;
ParticleUtil.addParticles( ParticleUtil.addParticles(
(ServerLevel) summon.level(), ModParticles.TERRA_BEAM_HIT_PARTICLE.get(), (ServerLevel) summon.level(), ModParticles.TERRA_BEAM_HIT_PARTICLE.get(),
@@ -543,6 +339,7 @@ public class TerraBlade extends MeleeWeapon {
public static void summon(Player player, int randomAngle) { public static void summon(Player player, int randomAngle) {
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), player.level()); StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), player.level());
summon.setOwner(player); summon.setOwner(player);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, player.getWeaponItem().copy());
Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ()); Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ());
summon.setPos(pos); summon.setPos(pos);
@@ -4,7 +4,6 @@ import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds; import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior; import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior;
import com.lzxnone.terraria.entity.summon.StaticSummon; import com.lzxnone.terraria.entity.summon.StaticSummon;
import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors; import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors;
@@ -16,12 +15,7 @@ import com.lzxnone.terraria.utils.DamageUtil;
import com.lzxnone.terraria.utils.FilterUtil; import com.lzxnone.terraria.utils.FilterUtil;
import com.lzxnone.terraria.utils.MathUtil; import com.lzxnone.terraria.utils.MathUtil;
import com.lzxnone.terraria.utils.SoundUtil; import com.lzxnone.terraria.utils.SoundUtil;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.core.component.DataComponents; import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
@@ -149,43 +143,6 @@ public class Terragrim extends MeleeWeapon {
public static final float HALF_HEIGHT = 30.0f; public static final float HALF_HEIGHT = 30.0f;
public static final float SCALE = 0.05f; public static final float SCALE = 0.05f;
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon)) return;
Entity owner = summon.getOwner();
if(owner == null) return;
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
if(!customData.contains("idx")) return;
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES[Math.min(customData.getInt("idx"), RES.length - 1)]));
Vector3f[] dirs = MathUtil.computeCoordinateSystem(owner);
int rotate = summon.getEntityData().get(StaticSummon.RZP);
Quaternionf rotation = new Quaternionf()
.fromAxisAngleRad(dirs[0], (float) Math.toRadians(rotate));
poseStack.mulPose(rotation);
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.XP.rotationDegrees(-90.0F));
poseStack.mulPose(Axis.ZP.rotationDegrees(-90.0F));
vertexConsumer.addVertex(poseStack.last().pose(), -HALF_WIDTH * SCALE, -HALF_HEIGHT * SCALE, 0)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(0.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
vertexConsumer.addVertex(poseStack.last().pose(), HALF_WIDTH * SCALE, -HALF_HEIGHT * SCALE, 0)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(1.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
vertexConsumer.addVertex(poseStack.last().pose(), HALF_WIDTH * SCALE, HALF_HEIGHT * SCALE, 0)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(1.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
vertexConsumer.addVertex(poseStack.last().pose(), -HALF_WIDTH * SCALE, HALF_HEIGHT * SCALE, 0)
.setColor(1.0f, 1.0f, 1.0f, 1.0f).setUv(0.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
}
@Override @Override
public void tick(StaticSummon summon) { public void tick(StaticSummon summon) {
@@ -207,25 +164,7 @@ public class Terragrim extends MeleeWeapon {
); );
for(Entity target : targets) { for(Entity target : targets) {
if(target instanceof LivingEntity livingEntity) { if(target instanceof LivingEntity livingEntity) {
AttributeInstance knockbackResist = null; if(DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float) getDamage(), 0.05f)) target.invulnerableTime = 0;
double originalResist = 0.0;
knockbackResist = livingEntity.getAttribute(Attributes.KNOCKBACK_RESISTANCE);
if(knockbackResist != null) {
originalResist = knockbackResist.getBaseValue();
knockbackResist.setBaseValue(Math.max(0.9, originalResist));
}
if(DamageUtil.normalAttack(summon, target, (float) getDamage(), 1.0f)) {
target.invulnerableTime = 0;
}
if(knockbackResist != null) {
knockbackResist.setBaseValue(originalResist);
}
}else {
if(DamageUtil.normalAttack(summon, target, (float) getDamage(), 1.0f)) {
target.invulnerableTime = 0;
}
} }
} }
} }
@@ -250,6 +189,7 @@ public class Terragrim extends MeleeWeapon {
if(!level.isClientSide()) { if(!level.isClientSide()) {
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level); StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level);
summon.setOwner(player); summon.setOwner(player);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, player.getWeaponItem().copy());
Vec3 pos = new Vec3(player.getX(), player.getY() + player.getBbHeight() * 0.5, player.getZ()); Vec3 pos = new Vec3(player.getX(), player.getY() + player.getBbHeight() * 0.5, player.getZ());
summon.setPos(pos); summon.setPos(pos);
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.TERRAGRIM_BEAM); summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.TERRAGRIM_BEAM);
@@ -203,7 +203,7 @@ public class TheHorsemansBlade extends MeleeWeapon {
if(custom_data.contains("hitEntityCount")) { if(custom_data.contains("hitEntityCount")) {
int count = custom_data.getInt("hitEntityCount"); int count = custom_data.getInt("hitEntityCount");
if(count < getBladeMaxHitCount()) { if(count < getBladeMaxHitCount()) {
if(DamageUtil.normalAttack(beam, target, (float) getBladeDamage(), 1.0f)) { if(DamageUtil.meleeAttack(beam, target, beam.getEntityData().get(SwordBeam.STACK_SOURCE), (float) getBladeDamage(), 1.0f)) {
target.invulnerableTime = 20; target.invulnerableTime = 20;
count++; count++;
custom_data.putInt("hitEntityCount", count); custom_data.putInt("hitEntityCount", count);
@@ -213,6 +213,7 @@ public class TheHorsemansBlade extends MeleeWeapon {
Entity entity = beam.getOwner(); Entity entity = beam.getOwner();
if(entity == null) return; if(entity == null) return;
summon.setOwner(entity); summon.setOwner(entity);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, beam.getEntityData().get(SwordBeam.STACK_SOURCE).copy());
Vec3 pos = MathUtil.getRandomPosInRadius(entity.position(), getPumpkinSpawnRange()); Vec3 pos = MathUtil.getRandomPosInRadius(entity.position(), getPumpkinSpawnRange());
summon.setPos(pos); summon.setPos(pos);
@@ -335,7 +336,7 @@ public class TheHorsemansBlade extends MeleeWeapon {
summon.setYRot(xyRot[1]); summon.setYRot(xyRot[1]);
if(selfPos.distanceToSqr(targetPos) < 2.0D) { if(selfPos.distanceToSqr(targetPos) < 2.0D) {
if(summon.getOwner() instanceof Player player && FilterUtil.createLivingTargetFilter(player).test(target) && DamageUtil.normalAttack(summon, target, (float) getPumpkinDamage(), 1.0f)) onDied(summon); if(summon.getOwner() instanceof Player player && FilterUtil.createLivingTargetFilter(player).test(target) && DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float) getPumpkinDamage(), 1.0f)) onDied(summon);
} }
}else { }else {
Vec3 dir = summon.getLookAngle().normalize(); Vec3 dir = summon.getLookAngle().normalize();
@@ -360,7 +361,7 @@ public class TheHorsemansBlade extends MeleeWeapon {
for(Entity hitEntity : hitEntities) { for(Entity hitEntity : hitEntities) {
if(target != null && hitEntity.getUUID() == target.getUUID()) continue; if(target != null && hitEntity.getUUID() == target.getUUID()) continue;
if(summon.getOwner() instanceof Player player) { if(summon.getOwner() instanceof Player player) {
if(DamageUtil.normalAttack(summon, hitEntity, (float) getPumpkinDamage(), 1.0f)) { if(DamageUtil.meleeAttack(summon, hitEntity, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float) getPumpkinDamage(), 1.0f)) {
hitEntity.invulnerableTime = 2; hitEntity.invulnerableTime = 2;
} }
} }
@@ -62,6 +62,7 @@ public class TrueCopperShortsword extends MeleeWeapon {
for(int i = 0;i < Zenith.getWeaponCount();i++) { for(int i = 0;i < Zenith.getWeaponCount();i++) {
StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), player.level()); StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), player.level());
projectile.setOwner(player); projectile.setOwner(player);
projectile.getEntityData().set(StaticProjectile.STACK_SOURCE, player.getWeaponItem().copy());
projectile.setPos(pos); projectile.setPos(pos);
projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.ZENITH_PROJECTILE); projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.ZENITH_PROJECTILE);
@@ -3,7 +3,6 @@ package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.item.weapon.MeleeWeapon; import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds; import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.beam.ISwordBeamBehavior; import com.lzxnone.terraria.entity.beam.ISwordBeamBehavior;
import com.lzxnone.terraria.entity.beam.SwordBeam; import com.lzxnone.terraria.entity.beam.SwordBeam;
import com.lzxnone.terraria.entity.beam.SwordBeamBehaviors; import com.lzxnone.terraria.entity.beam.SwordBeamBehaviors;
@@ -12,12 +11,8 @@ import com.lzxnone.terraria.network.payload.SwordBeamPayload;
import com.lzxnone.terraria.particle.DustParticleOptions; import com.lzxnone.terraria.particle.DustParticleOptions;
import com.lzxnone.terraria.particle.ModParticles; import com.lzxnone.terraria.particle.ModParticles;
import com.lzxnone.terraria.utils.*; import com.lzxnone.terraria.utils.*;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@@ -138,126 +133,6 @@ public class TrueExcalibur extends MeleeWeapon {
); );
public static final ISwordBeamBehavior SWORD_BEAM_BEHAVIOR = new ISwordBeamBehavior() { public static final ISwordBeamBehavior SWORD_BEAM_BEHAVIOR = new ISwordBeamBehavior() {
@Override
public 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) return;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(beam.getOwner());
dirs = MathUtil.rotateCoordinateSystem(dirs[0], dirs[2], beam.getEntityData().get(SwordBeam.ROTATE));
float rotate = beam.getEntityData().get(SwordBeam.ROTATE);
Vector3f color0 = new Vector3f(0.651f, 0.102f, 0.224f);
Vector3f color1 = new Vector3f(0.945f, 0.286f, 0.525f);
Vector3f color2 = new Vector3f(0.945f, 0.286f, 0.525f);
Vector3f color3 = new Vector3f(1.0f, 1.0f, 1.0f);
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(beam.getEntityData().get(SwordBeam.RIGHT)) progress = 1.0f - progress;
float halfWidth = SwordBeam.HALF_WIDTH * SwordBeam.SCALE;
float halfHeight = SwordBeam.HALF_HEIGHT * SwordBeam.SCALE;
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES0));
//左边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress - 0.1f * (1.0f - progress)) * 180, SwordBeam.DIST * 1.5f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress - 0.1f * (1.0f - progress))) * 180, rotate);
poseStack.scale(1.5f, 1.5f, 1.5f);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color0.x(), color0.y(), color0.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.05f);
poseStack.popPose();
//右边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.1f) * 180, SwordBeam.DIST * 1.5f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress + 0.05f)) * 180, rotate);
poseStack.scale(1.5f, 1.5f, 1.5f);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color2.x(), color2.y(), color2.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.06f);
poseStack.popPose();
//中间
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], progress * 180, SwordBeam.DIST * 1.5f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(1.5f, 1.5f, 1.5f);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color1.x(), color1.y(), color1.z(), alpha, halfWidth, halfHeight, 0f, 0f, -0.04f);
poseStack.popPose();
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES3));
//三线
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.05f) * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(0.75f, 0.75f, 0.75f);
renderQuad(poseStack.last().pose(), vertexConsumer1,
color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, -0.045f);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.05f) * 180, SwordBeam.DIST * 1.2f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(1.125f, 1.125f, 1.125f);
renderQuad(poseStack.last().pose(), vertexConsumer1,
color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, -0.045f);
poseStack.popPose();
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], progress * 180, SwordBeam.DIST * 1.725f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(1.425f, 1.425f, 1.425f);
renderQuad(poseStack.last().pose(), vertexConsumer1,
color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, -0.045f);
poseStack.popPose();
VertexConsumer vertexConsumer2 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES4));
//边缘高光
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.05f) * 180, SwordBeam.DIST * 1.725f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress + 0.05f)) * 180, rotate);
poseStack.scale(1.5f, 1.5f, 1.5f);
for(int i = 0;i < 20;i++) {
renderQuad(poseStack.last().pose(), vertexConsumer2,
color1.x(), color1.y(), color1.z(), alpha, halfWidth, halfHeight, 0f, 0f, -0.03f);
}
poseStack.popPose();
VertexConsumer vertexConsumer3 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES5));
//闪烁
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.25f) * 180, SwordBeam.DIST * 3.375f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress + 0.25f)) * 180, rotate);
poseStack.mulPose(Axis.ZP.rotationDegrees(45.0F));
poseStack.scale(1.5f, 1.5f, 1.5f);
for(int i = 0;i < 20;i++) {
renderQuad(poseStack.last().pose(), vertexConsumer3,
color1.x(), color1.y(), color1.z(), alpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, -0.03f);
}
poseStack.popPose();
ISwordBeamBehavior.super.render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight);
}
@Override @Override
public void onMoving(SwordBeam beam) { public void onMoving(SwordBeam beam) {
@@ -278,7 +153,7 @@ public class TrueExcalibur extends MeleeWeapon {
if(custom_data.contains("hitEntityCount")) { if(custom_data.contains("hitEntityCount")) {
int count = custom_data.getInt("hitEntityCount"); int count = custom_data.getInt("hitEntityCount");
if(count < getMaxHitCount()) { if(count < getMaxHitCount()) {
if(DamageUtil.normalAttack(beam, target, (float) getDamage(), 1.0f)) { if(DamageUtil.meleeAttack(beam, target, beam.getEntityData().get(SwordBeam.STACK_SOURCE), (float) getDamage(), 1.0f)) {
target.invulnerableTime = 20; target.invulnerableTime = 20;
count++; count++;
custom_data.putInt("hitEntityCount", count); custom_data.putInt("hitEntityCount", count);
@@ -4,7 +4,6 @@ import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds; import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.beam.ISwordBeamBehavior; import com.lzxnone.terraria.entity.beam.ISwordBeamBehavior;
import com.lzxnone.terraria.entity.beam.SwordBeam; import com.lzxnone.terraria.entity.beam.SwordBeam;
import com.lzxnone.terraria.entity.beam.SwordBeamBehaviors; import com.lzxnone.terraria.entity.beam.SwordBeamBehaviors;
@@ -16,12 +15,8 @@ import com.lzxnone.terraria.network.payload.SwordBeamPayload;
import com.lzxnone.terraria.particle.DustParticleOptions; import com.lzxnone.terraria.particle.DustParticleOptions;
import com.lzxnone.terraria.particle.ModParticles; import com.lzxnone.terraria.particle.ModParticles;
import com.lzxnone.terraria.utils.*; import com.lzxnone.terraria.utils.*;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@@ -228,92 +223,6 @@ public class TrueNightsEdge extends MeleeWeapon {
); );
public static final ISwordBeamBehavior SWORD_BEAM_BEHAVIOR = new ISwordBeamBehavior() { public static final ISwordBeamBehavior SWORD_BEAM_BEHAVIOR = new ISwordBeamBehavior() {
@Override
public 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) return;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(beam.getOwner());
dirs = MathUtil.rotateCoordinateSystem(dirs[0], dirs[2], beam.getEntityData().get(SwordBeam.ROTATE));
float rotate = beam.getEntityData().get(SwordBeam.ROTATE);
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;
}
if (beam.getEntityData().get(SwordBeam.RIGHT)) progress = 1.0f - progress;
float halfWidth = SwordBeam.HALF_WIDTH * SwordBeam.SCALE;
float halfHeight = SwordBeam.HALF_HEIGHT * SwordBeam.SCALE;
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES0));
//左边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress - 0.1f * (1.0f - progress)) * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress - 0.1f * (1.0f - progress))) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color0.x(), color0.y(), color0.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.01f);
poseStack.popPose();
//右边
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.1f) * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - (progress + 0.05f)) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color2.x(), color2.y(), color2.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.02f);
poseStack.popPose();
//中间
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], progress * 180, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
renderQuad(poseStack.last().pose(), vertexConsumer0,
color1.x(), color1.y(), color1.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0f);
poseStack.popPose();
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES3));
//外线
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], progress * 180, SwordBeam.DIST * 1.15f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress) * 180, rotate);
poseStack.scale(0.95f, 0.95f, 0.95f);
renderQuad(poseStack.last().pose(), vertexConsumer1,
color3.x(), color3.y(), color3.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.02f);
poseStack.popPose();
VertexConsumer vertexConsumer2 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES5));
//闪烁
poseStack.pushPose();
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], (progress + 0.25f) * 180, SwordBeam.DIST * 2.25f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], (0.5f - progress - 0.25f) * 180, rotate);
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(), vertexConsumer2,
color1.x(), color1.y(), color1.z(), alpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.03f);
}
poseStack.popPose();
}
@Override @Override
public void onMoving(SwordBeam beam) { public void onMoving(SwordBeam beam) {
@@ -334,7 +243,7 @@ public class TrueNightsEdge extends MeleeWeapon {
if(custom_data.contains("hitEntityCount")) { if(custom_data.contains("hitEntityCount")) {
int count = custom_data.getInt("hitEntityCount"); int count = custom_data.getInt("hitEntityCount");
if(count < getMaxHitCount()) { if(count < getMaxHitCount()) {
if(DamageUtil.normalAttack(beam, target, (float) getDamage(), 1.0f)) { if(DamageUtil.meleeAttack(beam, target, beam.getEntityData().get(SwordBeam.STACK_SOURCE), (float) getDamage(), 1.0f)) {
ParticleUtil.addParticles( ParticleUtil.addParticles(
(ServerLevel) target.level(), ModParticles.NIGHTS_EDGE_HIT_PARTICLE.get(), (ServerLevel) target.level(), ModParticles.NIGHTS_EDGE_HIT_PARTICLE.get(),
new Vec3(target.getX(), target.getY() + target.getBbHeight() / 2.0, target.getZ()), new Vec3(0, 0, 0), new Vec3(target.getX(), target.getY() + target.getBbHeight() / 2.0, target.getZ()), new Vec3(0, 0, 0),
@@ -372,172 +281,7 @@ public class TrueNightsEdge extends MeleeWeapon {
public static final float FADE_OUT = 0.67f; public static final float FADE_OUT = 0.67f;
public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() { 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;
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;
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
Vector3f dir = new Vector3f();
if (customData.contains("dirX")) dir.x = customData.getFloat("dirX");
if (customData.contains("dirY")) dir.y = customData.getFloat("dirY");
if (customData.contains("dirZ")) dir.z = customData.getFloat("dirZ");
Vector3f up = new Vector3f();
if (customData.contains("upX")) up.x = customData.getFloat("upX");
if (customData.contains("upY")) up.y = customData.getFloat("upY");
if (customData.contains("upZ")) up.z = customData.getFloat("upZ");
Vector3f right = new Vector3f();
if (customData.contains("rightX")) right.x = customData.getFloat("rightX");
if (customData.contains("rightY")) right.y = customData.getFloat("rightY");
if (customData.contains("rightZ")) right.z = customData.getFloat("rightZ");
Vector3f[] dirs = new Vector3f[]{dir, up, right};
double rotate = summon.getEntityData().get(StaticSummon.RZP);
double rotateSpeed = summon.getEntityData().get(StaticSummon.RZPS);
float rotateAngle = (float) ((summon.getEntityData().get(StaticSummon.AGE) + partialTick) * rotateSpeed);
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES0));
//外层(亮)
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR0.x(), COLOR0.y(), COLOR0.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0f);
poseStack.popPose();
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 160, SwordBeam.DIST * 1.5f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], -45, rotate);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR0.x(), COLOR0.y(), COLOR0.z(), alpha * 0.5f, halfWidth, halfHeight, 0f, 0f, -0.01f);
poseStack.popPose();
//外层(淡)
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 20, SwordBeam.DIST * 1.25f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 45, rotate);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR0.x(), COLOR0.y(), COLOR0.z(), alpha * 0.25f, halfWidth, halfHeight, 0f, 0f, -0.02f);
poseStack.popPose();
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], -100, SwordBeam.DIST * 2.5f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 180, rotate);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR0.x(), COLOR0.y(), COLOR0.z(), alpha * 0.125f, halfWidth, halfHeight, 0f, 0f, -0.03f);
poseStack.popPose();
//内层
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 160, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], -45, rotate);
poseStack.scale(0.8f, 0.8f, 0.8f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR1.x(), COLOR1.y(), COLOR1.z(), alpha, halfWidth, halfHeight, 0f, 0f, 0.01f);
poseStack.popPose();
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 70, SwordBeam.DIST * 0.5);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 15, rotate);
poseStack.scale(0.8f, 0.8f, 0.8f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR1.x(), COLOR1.y(), COLOR1.z(), alpha * 0.5f, halfWidth, halfHeight, 0f, 0f, -0.03f);
poseStack.popPose();
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], -30, SwordBeam.DIST);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 75, rotate);
poseStack.scale(0.8f, 0.8f, 0.8f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR1.x(), COLOR1.y(), COLOR1.z(), alpha * 0.25f, halfWidth, halfHeight, 0f, 0f, -0.02f);
poseStack.popPose();
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], -120, SwordBeam.DIST * 2f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 210, rotate);
poseStack.scale(0.8f, 0.8f, 0.8f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer0,
COLOR1.x(), COLOR1.y(), COLOR1.z(), alpha * 0.125f, halfWidth, halfHeight, 0f, 0f, -0.02f);
poseStack.popPose();
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES1));
//外线
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST * 1.15f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], 0, rotate);
poseStack.scale(0.95f, 0.95f, 0.95f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer1,
1.0f, 1.0f, 1.0f, alpha, halfWidth, halfHeight, 0f, 0f, 0.02f);
poseStack.popPose();
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 160, SwordBeam.DIST * 1.725f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], -45, rotate);
poseStack.scale(0.95f, 0.95f, 0.95f);
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer1,
1.0f, 1.0f, 1.0f, alpha, halfWidth, halfHeight, 0f, 0f, 0.02f);
poseStack.popPose();
VertexConsumer vertexConsumer2 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES2));
//闪烁
poseStack.pushPose();
rotateInCenter(poseStack, dirs, rotateAngle);
RenderUtil.applyTranslate(poseStack, dirs[0], dirs[2], 180, SwordBeam.DIST * 1.75f);
RenderUtil.applyRotate(poseStack, dirs[0], dirs[1], -45, rotate);
poseStack.mulPose(Axis.ZP.rotationDegrees(45.0F));
RenderUtil.renderQuad(poseStack.last().pose(), vertexConsumer2,
COLOR2.x(), COLOR2.y(), COLOR2.z(), alpha, 32 * SwordBeam.SCALE, 32 * SwordBeam.SCALE, 0f, 0f, 0.04f);
poseStack.popPose();
}
public void rotateInCenter(PoseStack poseStack, Vector3f[] dirs, float angle) {
float cos = (float) Math.cos(Math.toRadians(90));
float sin = (float) Math.sin(Math.toRadians(90));
Vector3f center = new Vector3f(
cos * dirs[2].x + sin * dirs[0].x,
cos * dirs[2].y + sin * dirs[0].y,
cos * dirs[2].z + sin * dirs[0].z
).normalize().mul(1.15f);
Quaternionf rotation = new Quaternionf().fromAxisAngleRad(
dirs[1], (float) Math.toRadians(angle)
);
poseStack.translate(-center.x, -center.y, -center.z);
poseStack.mulPose(rotation);
poseStack.translate(center.x, center.y, center.z);
}
@Override @Override
public void tick(StaticSummon summon) { public void tick(StaticSummon summon) {
@@ -572,7 +316,7 @@ public class TrueNightsEdge extends MeleeWeapon {
List<Entity> targets = summon.level().getEntitiesOfClass(Entity.class, summon.getBoundingBox(), FilterUtil.createTargetFilter(summon, summon.getOwner())); List<Entity> targets = summon.level().getEntitiesOfClass(Entity.class, summon.getBoundingBox(), FilterUtil.createTargetFilter(summon, summon.getOwner()));
for(Entity target : targets) { for(Entity target : targets) {
if(count >= getProjectileMaxHitCount()) break; if(count >= getProjectileMaxHitCount()) break;
if(DamageUtil.normalAttack(summon, target, (float) getProjectileDamage(), 1.0f)) { if(DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float) getProjectileDamage(), 1.0f)) {
count++; count++;
ParticleUtil.addParticles( ParticleUtil.addParticles(
(ServerLevel) target.level(), ModParticles.TRUE_NIGHTS_EDGE_HIT_PARTICLE.get(), (ServerLevel) target.level(), ModParticles.TRUE_NIGHTS_EDGE_HIT_PARTICLE.get(),
@@ -613,6 +357,7 @@ public class TrueNightsEdge extends MeleeWeapon {
public static void summon(Player player, int randomAngle) { public static void summon(Player player, int randomAngle) {
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), player.level()); StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), player.level());
summon.setOwner(player); summon.setOwner(player);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, player.getWeaponItem().copy());
Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ()); Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ());
summon.setPos(pos); summon.setPos(pos);
@@ -185,7 +185,7 @@ public class Volcano extends MeleeWeapon {
for(LivingEntity livingEntity : targets) { for(LivingEntity livingEntity : targets) {
if(livingEntity.getUUID() == target.getUUID()) continue; if(livingEntity.getUUID() == target.getUUID()) continue;
if(hitCount >= getExplosionMaxHitCount()) break; if(hitCount >= getExplosionMaxHitCount()) break;
if(DamageUtil.normalAttack(player, livingEntity, (float) getExplosionDamage(), 1.0f)) { if(DamageUtil.meleeAttack(player, livingEntity, player.getWeaponItem(), (float) getExplosionDamage(), 1.0f)) {
livingTarget.igniteForSeconds(getIgniteSeconds()); livingTarget.igniteForSeconds(getIgniteSeconds());
hitCount++; hitCount++;
} }
@@ -193,6 +193,7 @@ public class Volcano extends MeleeWeapon {
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), livingTarget.level()); StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), livingTarget.level());
summon.setOwner(player); summon.setOwner(player);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, player.getWeaponItem().copy());
Vec3 pos = livingTarget.position(); Vec3 pos = livingTarget.position();
summon.setPos(pos); summon.setPos(pos);
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.VOLCANO_LIGHT); summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.VOLCANO_LIGHT);
@@ -4,22 +4,13 @@ import com.lzxnone.terraria.item.weapon.MeleeWeapon;
import com.lzxnone.terraria.LzxnoneTerraria; import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds; import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.TintedVertexConsumer;
import com.lzxnone.terraria.entity.projectile.IStaticProjectileBehavior; import com.lzxnone.terraria.entity.projectile.IStaticProjectileBehavior;
import com.lzxnone.terraria.entity.projectile.StaticProjectile; import com.lzxnone.terraria.entity.projectile.StaticProjectile;
import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors; import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors;
import com.lzxnone.terraria.item.ModItems; import com.lzxnone.terraria.item.ModItems;
import com.lzxnone.terraria.particle.ZenithTrailParticleOptions; import com.lzxnone.terraria.particle.ZenithTrailParticleOptions;
import com.lzxnone.terraria.utils.*; import com.lzxnone.terraria.utils.*;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis; 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.RenderType;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.core.component.DataComponents; import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@@ -38,7 +29,6 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.joml.Matrix4f;
import org.joml.Quaternionf; import org.joml.Quaternionf;
import org.joml.Vector3f; import org.joml.Vector3f;
import org.jspecify.annotations.NonNull; import org.jspecify.annotations.NonNull;
@@ -263,178 +253,6 @@ public class Zenith extends MeleeWeapon {
public static final ResourceLocation RES1 = ResourceLocation.parse("lzxnoneterraria:textures/vfx/beam_sparkle.png"); public static final ResourceLocation RES1 = ResourceLocation.parse("lzxnoneterraria:textures/vfx/beam_sparkle.png");
public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileBehavior() { public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileBehavior() {
@Override
public void render(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;
CompoundTag customData = proj.getEntityData().get(StaticProjectile.CUSTOM_DATA);
if(!customData.contains("a") || !customData.contains("w") || !customData.contains("angle") || !customData.contains("start") || !customData.contains("idx")) return;
int start = customData.getInt("start");
if(proj.getEntityData().get(StaticProjectile.AGE) <= start) return;
int idx = customData.getInt("idx");
Vec3 dir = MathUtil.toVec3(proj.getEntityData().get(StaticProjectile.DIRECTION)).normalize();
Vec3 up = MathUtil.toVec3(proj.getEntityData().get(StaticProjectile.UP)).normalize();
Vec3 right = MathUtil.toVec3(proj.getEntityData().get(StaticProjectile.RIGHT)).normalize();
Quaternionf rotationDir = new Quaternionf()
.fromAxisAngleRad(dir.toVector3f(), (float) Math.toRadians(customData.getInt("angle")));
Quaternionf rotationUp1 = new Quaternionf()
.fromAxisAngleRad(up.toVector3f(), (float) -(customData.getDouble("w") * (proj.getEntityData().get(StaticProjectile.AGE) - start + partialTick)));
Quaternionf rotationUp2 = new Quaternionf()
.fromAxisAngleRad(up.toVector3f(), (float) Math.PI);
float[] xyRot = MathUtil.computeXYRot(dir.toVector3f(), up.toVector3f());
poseStack.pushPose();
//旋转
poseStack.mulPose(rotationUp1);
poseStack.mulPose(rotationUp2);
poseStack.mulPose(rotationDir);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.XP.rotationDegrees(proj.getEntityData().get(StaticProjectile.RXP)));
poseStack.mulPose(Axis.YP.rotationDegrees(proj.getEntityData().get(StaticProjectile.RYP)));
poseStack.mulPose(Axis.ZP.rotationDegrees(proj.getEntityData().get(StaticProjectile.RZP)));
//缩放
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,
1.0f,
1.0f,
1.0f,
proj.getEntityData().get(StaticProjectile.COLOR_A));
},
entity.level(),
0
);
poseStack.popPose();
Vec3 currentPos = proj.getPosition(partialTick);
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES0));
Matrix4f matrix = poseStack.last().pose();
Vector3f color = new Vector3f(
proj.getEntityData().get(StaticProjectile.COLOR_R),
proj.getEntityData().get(StaticProjectile.COLOR_G),
proj.getEntityData().get(StaticProjectile.COLOR_B)
);
float mainAlpha = (float) getTrailAlpha();
if(idx == 1) mainAlpha = mainAlpha * 0.5f;
if(idx == 2) mainAlpha = mainAlpha * 0.25f;
//尾迹
int quadCount = proj.trailPositions.size() / 2 - 1;
for(int j = 0;j < 2;j++) {
for(int i = 1; i < quadCount; i++) {
Vec3 currentPoint1 = proj.trailPositions.get(i * 2);
Vec3 currentPoint2 = proj.trailPositions.get(i * 2 + 1);
Vec3 nextPoint1 = proj.trailPositions.get(i * 2 + 3);
Vec3 nextPoint2 = proj.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 radio1 = (float) i / quadCount;
float radio2 = (float) (i + 1) / quadCount;
vertexConsumer0.addVertex(matrix, (float) x1, (float) y1, (float) z1)
.setColor(color.x, color.y, color.z, mainAlpha).setUv(radio1, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
vertexConsumer0.addVertex(matrix, (float) x2, (float) y2, (float) z2)
.setColor(color.x, color.y, color.z, 0).setUv(radio1, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
vertexConsumer0.addVertex(matrix, (float) x3, (float) y3, (float) z3)
.setColor(color.x, color.y, color.z, 0).setUv(radio2, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
vertexConsumer0.addVertex(matrix, (float) x4, (float) y4, (float) z4)
.setColor(color.x, color.y, color.z, mainAlpha).setUv(radio2, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
}
}
//闪烁
if(idx != 0) return;
float halfWidth = 32 * 0.05f;
float halfHeight = 32 * 0.05f;
float radio = (float) (proj.getEntityData().get(StaticProjectile.AGE) - start) / (float) proj.getEntityData().get(StaticProjectile.LIFETIME);
float alpha;
if(radio > 0.25f && radio < 0.4f) {
alpha = (radio - 0.25f) / 0.15f;
}else if(radio >= 0.4f && radio < 0.6f) {
alpha = 1.0f;
}else if(radio >= 0.6f && radio < 0.75f) {
alpha = 1.0f - (radio - 0.6f) / 0.15f;
}else {
alpha = 0;
}
if(Math.abs(alpha) < 0.001) return;
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES1));
poseStack.pushPose();
Vector3f tempRight = right.toVector3f();
double rad = customData.getDouble("w") * (proj.getEntityData().get(StaticProjectile.AGE) - start + partialTick);
Vector3f swordTipDir = tempRight.rotate(new Quaternionf().fromAxisAngleRad(up.toVector3f(), (float) (Math.PI / 2 - rad))).normalize();
Vec3 trans = MathUtil.toVec3(swordTipDir).scale(1.25);
poseStack.translate(trans.x, trans.y, trans.z);
poseStack.mulPose(new Quaternionf()
.fromAxisAngleRad(dir.toVector3f(), (float) Math.toRadians(customData.getInt("angle")))
.rotateY((float) Math.toRadians(-xyRot[1]))
.rotateX((float) Math.toRadians(-90 + xyRot[0]))
);
poseStack.scale(1.0f, 1.0f, 1.0f);
matrix = poseStack.last().pose();
for(int i = 0; i < 3; i++) {
vertexConsumer1.addVertex(matrix, -halfWidth, -halfHeight, 0.01f)
.setColor(color.x, color.y, color.z, alpha).setUv(0.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
vertexConsumer1.addVertex(matrix, halfWidth, -halfHeight, 0.01f)
.setColor(color.x, color.y, color.z, alpha).setUv(1.0f, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
vertexConsumer1.addVertex(matrix, halfWidth, halfHeight, 0.01f)
.setColor(color.x, color.y, color.z, alpha).setUv(1.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
vertexConsumer1.addVertex(matrix, -halfWidth, halfHeight, 0.01f)
.setColor(color.x, color.y, color.z, alpha).setUv(0.0f, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0.0f, 1.0f, 0.0f);
}
poseStack.popPose();
}
@Override @Override
public void onMoving(StaticProjectile projectile) { public void onMoving(StaticProjectile projectile) {
@@ -508,7 +326,7 @@ public class Zenith extends MeleeWeapon {
if(!projectile.level().isClientSide()) { if(!projectile.level().isClientSide()) {
Entity target = result.getEntity(); Entity target = result.getEntity();
if(projectile.getOwner() instanceof Player player && FilterUtil.createTargetFilter(projectile, projectile.getOwner()).test(target)) { if(projectile.getOwner() instanceof Player player && FilterUtil.createTargetFilter(projectile, projectile.getOwner()).test(target)) {
if(DamageUtil.normalAttack(projectile, target, (float) (getDamage() + Math.random() * getDamage()), 0.25f)) { if(DamageUtil.meleeAttack(projectile, target, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE), (float) (getDamage() + Math.random() * getDamage()), 0.2f)) {
target.invulnerableTime = 2; target.invulnerableTime = 2;
} }
} }
@@ -540,6 +358,7 @@ public class Zenith extends MeleeWeapon {
for(int i = 0;i < getWeaponCount();i++) { for(int i = 0;i < getWeaponCount();i++) {
StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), player.level()); StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), player.level());
projectile.setOwner(player); projectile.setOwner(player);
projectile.getEntityData().set(StaticProjectile.STACK_SOURCE, player.getWeaponItem().copy());
projectile.setPos(pos); projectile.setPos(pos);
projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.ZENITH_PROJECTILE); projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.ZENITH_PROJECTILE);
@@ -2,25 +2,21 @@ package com.lzxnone.terraria.item.weapon.summon;
import com.lzxnone.terraria.attachment.ModAttachments; import com.lzxnone.terraria.attachment.ModAttachments;
import com.lzxnone.terraria.entity.ModEntities; import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.PureColorVertexConsumer;
import com.lzxnone.terraria.entity.TintedVertexConsumer;
import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior; import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior;
import com.lzxnone.terraria.entity.summon.StaticSummon; import com.lzxnone.terraria.entity.summon.StaticSummon;
import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors; import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors;
import com.lzxnone.terraria.item.ModItems; import com.lzxnone.terraria.item.ModItems;
import com.lzxnone.terraria.item.weapon.SummonWeapon; import com.lzxnone.terraria.item.weapon.SummonWeapon;
import com.lzxnone.terraria.ui.config.ConfigFactory;
import com.lzxnone.terraria.ui.config.ConfigListItem;
import com.lzxnone.terraria.ui.config.ConfigUtil;
import com.lzxnone.terraria.ui.config.IConfigData;
import com.lzxnone.terraria.utils.DamageUtil; import com.lzxnone.terraria.utils.DamageUtil;
import com.lzxnone.terraria.utils.FilterUtil; import com.lzxnone.terraria.utils.FilterUtil;
import com.lzxnone.terraria.utils.MathUtil; import com.lzxnone.terraria.utils.MathUtil;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis; 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.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
@@ -30,14 +26,10 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.monster.Monster; import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.*; import net.minecraft.world.item.*;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.checkerframework.checker.units.qual.A;
import org.checkerframework.checker.units.qual.C;
import org.joml.Quaternionf; import org.joml.Quaternionf;
import org.joml.Vector3f; import org.joml.Vector3f;
@@ -46,23 +38,53 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
public class Terraprisma extends SummonWeapon { public class Terraprisma extends SummonWeapon {
private static final double TARGET_RANGE = 32.0D; private static final String CONFIG_TRANSLATION_PREFIX = "lzxnoneterraria.configuration.";
private static final double FOLLOW_SPEED = 4.0D; public static final String TARGET_RANGE_PATH = "weapon.terraprisma.target_range";
public static final double TARGET_RANGE_DEFAULT = 64.0D;
public static final double TARGET_RANGE_MIN = 1.0D;
public static final double TARGET_RANGE_MAX = 256.0D;
public static final double DASH_PRE_SPEED = -0.75; public static final String FOLLOW_SPEED_PATH = "weapon.terraprisma.follow_speed";
public static final double DASH_PRE_FRICTION = 0.78; public static final double FOLLOW_SPEED_DEFAULT = 4.0D;
public static final double FOLLOW_SPEED_MIN = 0.0D;
public static final double FOLLOW_SPEED_MAX = 32.0D;
public static final String DASH_PRE_SPEED_PATH = "weapon.terraprisma.dash_pre_speed";
public static final double DASH_PRE_SPEED_DEFAULT = -0.75D;
public static final double DASH_PRE_SPEED_MIN = -10.0D;
public static final double DASH_PRE_SPEED_MAX = 10.0D;
public static final String DASH_PRE_FRICTION_PATH = "weapon.terraprisma.dash_pre_friction";
public static final double DASH_PRE_FRICTION_DEFAULT = 0.78D;
public static final double DASH_PRE_FRICTION_MIN = 0.0D;
public static final double DASH_PRE_FRICTION_MAX = 1.0D;
public static final String DASH_SPEED_PATH = "weapon.terraprisma.dash_speed";
public static final double DASH_SPEED_DEFAULT = 1.6D;
public static final double DASH_SPEED_MIN = 0.01D;
public static final double DASH_SPEED_MAX = 32.0D;
public static final String DASH_FRICTION_PATH = "weapon.terraprisma.dash_friction";
public static final double DASH_FRICTION_DEFAULT = 0.72D;
public static final double DASH_FRICTION_MIN = 0.0D;
public static final double DASH_FRICTION_MAX = 1.0D;
public static final double DASH_SPEED = 1.6;
public static final int DASH_MORE_TIME = 1; public static final int DASH_MORE_TIME = 1;
public static final double DASH_FRICTION = 0.72;
public static final String ROTATE_SPEED_PATH = "weapon.terraprisma.rotate_speed";
public static final double ROTATE_SPEED_DEFAULT = 1.0D;
public static final double ROTATE_SPEED_MIN = 0.01D;
public static final double ROTATE_SPEED_MAX = 32.0D;
public static final String DAMAGE_PATH = "weapon.terraprisma.damage";
public static final float DAMAGE_DEFAULT = 20.0F;
public static final float DAMAGE_MIN = 0.0F;
public static final float DAMAGE_MAX = 8388600.0F;
public static final float ROTATION_LERP = 0.25f; public static final float ROTATION_LERP = 0.25f;
public static final float ROTATION_LERP2 = 0.5f; public static final float ROTATION_LERP2 = 0.5f;
public static final double ROTATE_SPEED = 1.0;
public static final float DAMAGE = 20;
public static final float TRAIL_ALPHA = 1.0f; public static final float TRAIL_ALPHA = 1.0f;
public static final int TRAIL_MAX_LENGTH = 20; public static final int TRAIL_MAX_LENGTH = 20;
public static final float AFTERIMAGE_ALPHA = 0.5f; public static final float AFTERIMAGE_ALPHA = 0.5f;
@@ -81,143 +103,69 @@ public class Terraprisma extends SummonWeapon {
super(Tiers.NETHERITE, new Item.Properties().stacksTo(1).fireResistant().rarity(Rarity.EPIC)); super(Tiers.NETHERITE, new Item.Properties().stacksTo(1).fireResistant().rarity(Rarity.EPIC));
} }
public static final IConfigData CONFIG_DATA = new IConfigData() {
@Override
public void onConfigLoad() {
ConfigFactory.loadDoubleConfig(TARGET_RANGE_PATH, configText("terraprisma_target_range"), configTooltip("terraprisma_target_range"), TARGET_RANGE_DEFAULT, TARGET_RANGE_MIN, TARGET_RANGE_MAX);
ConfigFactory.loadDoubleConfig(FOLLOW_SPEED_PATH, configText("terraprisma_follow_speed"), configTooltip("terraprisma_follow_speed"), FOLLOW_SPEED_DEFAULT, FOLLOW_SPEED_MIN, FOLLOW_SPEED_MAX);
ConfigFactory.loadDoubleConfig(DASH_PRE_SPEED_PATH, configText("terraprisma_dash_pre_speed"), configTooltip("terraprisma_dash_pre_speed"), DASH_PRE_SPEED_DEFAULT, DASH_PRE_SPEED_MIN, DASH_PRE_SPEED_MAX);
ConfigFactory.loadDoubleConfig(DASH_PRE_FRICTION_PATH, configText("terraprisma_dash_pre_friction"), configTooltip("terraprisma_dash_pre_friction"), DASH_PRE_FRICTION_DEFAULT, DASH_PRE_FRICTION_MIN, DASH_PRE_FRICTION_MAX);
ConfigFactory.loadDoubleConfig(DASH_SPEED_PATH, configText("terraprisma_dash_speed"), configTooltip("terraprisma_dash_speed"), DASH_SPEED_DEFAULT, DASH_SPEED_MIN, DASH_SPEED_MAX);
ConfigFactory.loadDoubleConfig(DASH_FRICTION_PATH, configText("terraprisma_dash_friction"), configTooltip("terraprisma_dash_friction"), DASH_FRICTION_DEFAULT, DASH_FRICTION_MIN, DASH_FRICTION_MAX);
ConfigFactory.loadDoubleConfig(ROTATE_SPEED_PATH, configText("terraprisma_rotate_speed"), configTooltip("terraprisma_rotate_speed"), ROTATE_SPEED_DEFAULT, ROTATE_SPEED_MIN, ROTATE_SPEED_MAX);
ConfigFactory.loadFloatConfig(DAMAGE_PATH, configText("terraprisma_damage"), configTooltip("terraprisma_damage"), DAMAGE_DEFAULT, DAMAGE_MIN, DAMAGE_MAX);
}
};
private static Component configText(String key) {
return Component.translatable(CONFIG_TRANSLATION_PREFIX + key);
}
private static Component configTooltip(String key) {
return Component.translatable(CONFIG_TRANSLATION_PREFIX + key + ".tooltip");
}
public static double getTargetRange() {
return Math.clamp(ConfigUtil.readDouble(TARGET_RANGE_PATH, TARGET_RANGE_DEFAULT), TARGET_RANGE_MIN, TARGET_RANGE_MAX);
}
public static double getFollowSpeed() {
return Math.clamp(ConfigUtil.readDouble(FOLLOW_SPEED_PATH, FOLLOW_SPEED_DEFAULT), FOLLOW_SPEED_MIN, FOLLOW_SPEED_MAX);
}
public static double getDashPreSpeed() {
return Math.clamp(ConfigUtil.readDouble(DASH_PRE_SPEED_PATH, DASH_PRE_SPEED_DEFAULT), DASH_PRE_SPEED_MIN, DASH_PRE_SPEED_MAX);
}
public static double getDashPreFriction() {
return Math.clamp(ConfigUtil.readDouble(DASH_PRE_FRICTION_PATH, DASH_PRE_FRICTION_DEFAULT), DASH_PRE_FRICTION_MIN, DASH_PRE_FRICTION_MAX);
}
public static double getDashSpeed() {
return Math.clamp(ConfigUtil.readDouble(DASH_SPEED_PATH, DASH_SPEED_DEFAULT), DASH_SPEED_MIN, DASH_SPEED_MAX);
}
public static double getDashFriction() {
return Math.clamp(ConfigUtil.readDouble(DASH_FRICTION_PATH, DASH_FRICTION_DEFAULT), DASH_FRICTION_MIN, DASH_FRICTION_MAX);
}
public static double getRotateSpeed() {
return Math.clamp(ConfigUtil.readDouble(ROTATE_SPEED_PATH, ROTATE_SPEED_DEFAULT), ROTATE_SPEED_MIN, ROTATE_SPEED_MAX);
}
public static float getDamage() {
return Math.clamp(ConfigUtil.readFloat(DAMAGE_PATH, DAMAGE_DEFAULT), DAMAGE_MIN, DAMAGE_MAX);
}
public static final ConfigListItem CONFIG_LIST_ITEM = new ConfigListItem(
"terraprisma",
ResourceLocation.fromNamespaceAndPath("lzxnoneterraria", "textures/item/terraprisma.png"),
Component.translatable("item.lzxnoneterraria.terraprisma"),
CONFIG_DATA
);
public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() { public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() {
public static final ResourceLocation RES = ResourceLocation.parse("lzxnoneterraria:textures/vfx/sword_trail.png"); public static final ResourceLocation RES = ResourceLocation.parse("lzxnoneterraria:textures/vfx/sword_trail.png");
@Override
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof StaticSummon summon) || summon.getOwner() == null) return;
ItemStack stack = summon.getEntityData().get(StaticSummon.ITEM);
if(stack.isEmpty()) return;
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
int idx = customData.contains("idx") ? customData.getInt("idx") : 0;
int state = customData.contains("state") ? customData.getInt("state") : 0;
float[] color = computeCrystalColor(summon.tickCount + partialTick, idx);
Vec3 currentPos = summon.position();
if(state == State.DASH_PRE.ordinal() || state == State.DASH.ordinal()) {
for(int i = summon.afterimageFrames.size() - 1; i >= 0; i--) {
StaticSummon.AfterimageFrame frame = summon.afterimageFrames.get(i);
float alpha = AFTERIMAGE_ALPHA * (1.0f - (float)i / AFTERIMAGE_MAX_LENGTH);
Vec3 offset = frame.position().subtract(currentPos);
poseStack.pushPose();
poseStack.translate(offset.x, offset.y, offset.z);
poseStack.mulPose(Axis.YP.rotationDegrees(-frame.yRot()));
poseStack.mulPose(Axis.XP.rotationDegrees(frame.xRot()));
poseStack.mulPose(Axis.ZP.rotationDegrees(90));
poseStack.mulPose(Axis.YP.rotationDegrees(90));
poseStack.scale(
summon.getEntityData().get(StaticSummon.SCALE_X) * AFTERIMAGE_SCALE,
summon.getEntityData().get(StaticSummon.SCALE_Y) * AFTERIMAGE_SCALE,
summon.getEntityData().get(StaticSummon.SCALE_Z) * AFTERIMAGE_SCALE
);
Minecraft.getInstance().getItemRenderer().renderStatic(
stack,
ItemDisplayContext.NONE,
LightTexture.FULL_BRIGHT,
OverlayTexture.NO_OVERLAY,
poseStack,
renderType -> {
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(InventoryMenu.BLOCK_ATLAS));
return new PureColorVertexConsumer(vertexConsumer,
frame.r(),
frame.g(),
frame.b(),
alpha);
},
entity.level(),
0
);
poseStack.popPose();
}
}
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.ZP.rotationDegrees(90));
poseStack.mulPose(Axis.YP.rotationDegrees(90));
poseStack.scale(
summon.getEntityData().get(StaticSummon.SCALE_X),
summon.getEntityData().get(StaticSummon.SCALE_Y),
summon.getEntityData().get(StaticSummon.SCALE_Z)
);
for(int i = 0;i < 3;i++) {
Minecraft.getInstance().getItemRenderer().renderStatic(
stack,
ItemDisplayContext.NONE,
LightTexture.FULL_BRIGHT,
OverlayTexture.NO_OVERLAY,
poseStack,
renderType -> {
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(InventoryMenu.BLOCK_ATLAS));
return new TintedVertexConsumer(vertexConsumer,
color[0],
color[1],
color[2],
summon.getEntityData().get(StaticSummon.COLOR_A));
},
entity.level(),
0
);
}
poseStack.popPose();
if(state == State.ROTATE.ordinal()) {
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES));
float mainAlpha = TRAIL_ALPHA;
int quadCount = summon.trailPositions.size() / 2 - 1;
for(int j = 0; j < 3; j++) {
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 radio1 = (float) i / quadCount;
float radio2 = (float) (i + 1) / quadCount;
vertexConsumer.addVertex(poseStack.last().pose(), (float)x1, (float)y1, (float)z1)
.setColor(color[0], color[1], color[2], mainAlpha).setUv(radio1, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float)x2, (float)y2, (float)z2)
.setColor(color[0], color[1], color[2], 0).setUv(radio1, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float)x3, (float)y3, (float)z3)
.setColor(color[0], color[1], color[2], 0).setUv(radio2, 1.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
vertexConsumer.addVertex(poseStack.last().pose(), (float)x4, (float)y4, (float)z4)
.setColor(color[0], color[1], color[2], mainAlpha).setUv(radio2, 0.0f)
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
}
}
}
}
@Override @Override
public void tick(StaticSummon summon) { public void tick(StaticSummon summon) {
@@ -275,22 +223,23 @@ public class Terraprisma extends SummonWeapon {
summon.setXRot(Mth.rotLerp(ROTATION_LERP, summon.getXRot(), targetXYRot[0])); summon.setXRot(Mth.rotLerp(ROTATION_LERP, summon.getXRot(), targetXYRot[0]));
summon.setYRot(Mth.rotLerp(ROTATION_LERP, summon.getYRot(), targetXYRot[1])); summon.setYRot(Mth.rotLerp(ROTATION_LERP, summon.getYRot(), targetXYRot[1]));
} }
summon.setDeltaMovement(summon.getDeltaMovement().scale(DASH_PRE_FRICTION)); summon.setDeltaMovement(summon.getDeltaMovement().scale(getDashPreFriction()));
}else if(state == State.DASH.ordinal()) { }else if(state == State.DASH.ordinal()) {
int dashTime = customData.contains("dashTime") ? customData.getInt("dashTime") : 0; int dashTime = customData.contains("dashTime") ? customData.getInt("dashTime") : 0;
customData.putInt("dashTime", dashTime - 1); customData.putInt("dashTime", dashTime - 1);
if(dashTime > 0) { if(dashTime > 0) {
summon.setDeltaMovement(summon.getLookAngle().normalize().scale(DASH_SPEED)); summon.setDeltaMovement(summon.getLookAngle().normalize().scale(getDashSpeed()));
}else { }else {
summon.setDeltaMovement(summon.getDeltaMovement().scale(DASH_FRICTION)); summon.setDeltaMovement(summon.getDeltaMovement().scale(getDashFriction()));
} }
List<Entity> targets = summon.level().getEntitiesOfClass( List<Entity> targets = summon.level().getEntitiesOfClass(
Entity.class, Entity.class,
summon.getBoundingBox(), summon.getBoundingBox(),
FilterUtil.createTargetFilter(summon, player) FilterUtil.createTargetFilter(summon, player)
); );
ItemStack sourceStack = summon.getEntityData().get(StaticSummon.STACK_SOURCE);
for(Entity target : targets) { for(Entity target : targets) {
if(DamageUtil.normalAttack(summon, target, DAMAGE, 1.0f)) target.invulnerableTime = 15; if(DamageUtil.summonAttack(summon, target, sourceStack, getDamage(customData), 1.0f)) target.invulnerableTime = 15;
} }
}else if(state == State.ROTATE.ordinal()) { }else if(state == State.ROTATE.ordinal()) {
int time = customData.contains("rotateTime") ? customData.getInt("rotateTime") : 0; int time = customData.contains("rotateTime") ? customData.getInt("rotateTime") : 0;
@@ -339,8 +288,9 @@ public class Terraprisma extends SummonWeapon {
FilterUtil.createTargetFilter(summon, player) FilterUtil.createTargetFilter(summon, player)
); );
ItemStack sourceStack = summon.getEntityData().get(StaticSummon.STACK_SOURCE);
for(Entity target : targets) { for(Entity target : targets) {
if(DamageUtil.normalAttack(summon, target, DAMAGE, 1.0f)) target.invulnerableTime = 15; if(DamageUtil.summonAttack(summon, target, sourceStack, getDamage(customData), 1.0f)) target.invulnerableTime = 15;
} }
customData.putInt("rotateTime", time + 1); customData.putInt("rotateTime", time + 1);
@@ -404,7 +354,7 @@ public class Terraprisma extends SummonWeapon {
if(to == State.DASH_PRE.ordinal()) { if(to == State.DASH_PRE.ordinal()) {
Entity target = getTarget(summon); Entity target = getTarget(summon);
if(target != null) { if(target != null) {
summon.setDeltaMovement(target.getBoundingBox().getCenter().subtract(summon.position()).normalize().scale(DASH_PRE_SPEED)); summon.setDeltaMovement(target.getBoundingBox().getCenter().subtract(summon.position()).normalize().scale(getDashPreSpeed()));
} }
}else if(to == State.DASH.ordinal()) { }else if(to == State.DASH.ordinal()) {
Entity target = getTarget(summon); Entity target = getTarget(summon);
@@ -412,7 +362,8 @@ public class Terraprisma extends SummonWeapon {
summon.setDeltaMovement(Vec3.ZERO); summon.setDeltaMovement(Vec3.ZERO);
Vec3 distV = target.getBoundingBox().getCenter().subtract(summon.position()); Vec3 distV = target.getBoundingBox().getCenter().subtract(summon.position());
double dist = distV.length(); double dist = distV.length();
int dashTime = (int) (dist / DASH_SPEED) + DASH_MORE_TIME; int dashTime = (int) (dist / getDashSpeed()) + DASH_MORE_TIME;
if(summon.getRandom().nextInt(2) == 0) dashTime++;
customData.putInt("dashTime", dashTime); customData.putInt("dashTime", dashTime);
} }
}else if(to == State.ROTATE.ordinal()) { }else if(to == State.ROTATE.ordinal()) {
@@ -441,7 +392,7 @@ public class Terraprisma extends SummonWeapon {
double circumference = Math.PI * (a + b) * (1 + (3 * h) / (10 + Math.sqrt(4 - 3 * h))); double circumference = Math.PI * (a + b) * (1 + (3 * h) / (10 + Math.sqrt(4 - 3 * h)));
double range = 0.5 + Math.random() * 0.5; double range = 0.5 + Math.random() * 0.5;
double arcLength = circumference * range; double arcLength = circumference * range;
int duration = (int)Math.ceil(arcLength / ROTATE_SPEED); int duration = (int)Math.ceil(arcLength / getRotateSpeed());
duration = Mth.clamp(duration, 8, 18); duration = Mth.clamp(duration, 8, 18);
double w = Math.PI * 2 * range / duration; double w = Math.PI * 2 * range / duration;
if(summon.getRandom().nextInt(2) == 0) w = -w; if(summon.getRandom().nextInt(2) == 0) w = -w;
@@ -493,8 +444,9 @@ public class Terraprisma extends SummonWeapon {
Vec3 basePos = summon.getOwner().getBoundingBox().getCenter(); Vec3 basePos = summon.getOwner().getBoundingBox().getCenter();
Vec3 pos = basePos.add(hDir.scale(-(idx + 1) * 0.25 - 1)); Vec3 pos = basePos.add(hDir.scale(-(idx + 1) * 0.25 - 1));
Vec3 dist = pos.subtract(summon.position()); Vec3 dist = pos.subtract(summon.position());
if(dist.length() > 4.0) { double followSpeed = getFollowSpeed();
summon.setDeltaMovement(dist.normalize().scale(Math.min(FOLLOW_SPEED, dist.length()))); if(dist.length() > followSpeed) {
summon.setDeltaMovement(dist.normalize().scale(Math.min(followSpeed, dist.length())));
}else { }else {
summon.setDeltaMovement(Vec3.ZERO); summon.setDeltaMovement(Vec3.ZERO);
summon.setPos(pos); summon.setPos(pos);
@@ -525,7 +477,7 @@ public class Terraprisma extends SummonWeapon {
List<Monster> monsters = summon.level().getEntitiesOfClass( List<Monster> monsters = summon.level().getEntitiesOfClass(
Monster.class, Monster.class,
AABB.ofSize(summon.position(), TARGET_RANGE * 2.0D, TARGET_RANGE * 2.0D, TARGET_RANGE * 2.0D), AABB.ofSize(summon.position(), getTargetRange() * 2.0D, getTargetRange() * 2.0D, getTargetRange() * 2.0D),
FilterUtil.createMonsterFilter(player) FilterUtil.createMonsterFilter(player)
); );
monsters.sort(Comparator.comparingDouble(monster -> monster.distanceToSqr(summon.position()))); monsters.sort(Comparator.comparingDouble(monster -> monster.distanceToSqr(summon.position())));
@@ -539,7 +491,7 @@ public class Terraprisma extends SummonWeapon {
private static boolean isValidTarget(StaticSummon summon, Player player, LivingEntity target) { private static boolean isValidTarget(StaticSummon summon, Player player, LivingEntity target) {
return target != null return target != null
&& target.level() == summon.level() && target.level() == summon.level()
&& target.distanceToSqr(summon) <= TARGET_RANGE * TARGET_RANGE && target.distanceToSqr(summon) <= getTargetRange() * getTargetRange()
&& FilterUtil.createLivingTargetFilter(summon, player).test(target); && FilterUtil.createLivingTargetFilter(summon, player).test(target);
} }
@@ -554,6 +506,10 @@ public class Terraprisma extends SummonWeapon {
return null; return null;
} }
private static float getDamage(CompoundTag customData) {
return customData.contains("damage") ? customData.getFloat("damage") : getDamage();
}
private static float[] computeCrystalColor(float time, int idx) { private static float[] computeCrystalColor(float time, int idx) {
float hue = (time * 0.015F + idx * 0.12F) % 1.0F; float hue = (time * 0.015F + idx * 0.12F) % 1.0F;
int rgb = Mth.hsvToRgb(hue, 0.85F, 1.0F); int rgb = Mth.hsvToRgb(hue, 0.85F, 1.0F);
@@ -576,6 +532,7 @@ public class Terraprisma extends SummonWeapon {
if(stack.is(ModItems.TERRAPRISMA.get()) && level instanceof ServerLevel serverLevel) { if(stack.is(ModItems.TERRAPRISMA.get()) && level instanceof ServerLevel serverLevel) {
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level); StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level);
summon.setOwner(player); summon.setOwner(player);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, stack.copy());
summon.setPos(player.position()); summon.setPos(player.position());
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.TERRAPRISMA); summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.TERRAPRISMA);
summon.getEntityData().set(StaticSummon.RENDER_MODE, "custom"); summon.getEntityData().set(StaticSummon.RENDER_MODE, "custom");
@@ -585,6 +542,9 @@ public class Terraprisma extends SummonWeapon {
summon.getEntityData().set(StaticSummon.SCALE_Z, 1.0f); summon.getEntityData().set(StaticSummon.SCALE_Z, 1.0f);
summon.getEntityData().set(StaticSummon.LIFETIME, 72000); summon.getEntityData().set(StaticSummon.LIFETIME, 72000);
summon.getEntityData().set(StaticSummon.GLOW, true); summon.getEntityData().set(StaticSummon.GLOW, true);
CompoundTag summonData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA).copy();
summonData.putFloat("damage", getDamage());
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, summonData);
summon.setNoGravity(true); summon.setNoGravity(true);
summon.noPhysics = true; summon.noPhysics = true;
@@ -1,6 +1,7 @@
package com.lzxnone.terraria.mixin; package com.lzxnone.terraria.mixin;
import com.lzxnone.terraria.effect.ModEffects; import com.lzxnone.terraria.effect.ModEffects;
import com.lzxnone.terraria.client.item.melee.ClientDevilsDevastation;
import com.lzxnone.terraria.entity.ModRenderTypes; import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.item.ModItems; import com.lzxnone.terraria.item.ModItems;
import com.lzxnone.terraria.item.weapon.melee.DevilsDevastation; import com.lzxnone.terraria.item.weapon.melee.DevilsDevastation;
@@ -139,7 +140,7 @@ public class ItemInHandRenderMixin {
if(itemStack.is(ModItems.DEVILS_DEVASTATION.get()) && entity instanceof Player player) { if(itemStack.is(ModItems.DEVILS_DEVASTATION.get()) && entity instanceof Player player) {
if(entity.getEffect(ModEffects.KILL_MODE) != null && !player.getCooldowns().isOnCooldown(itemStack.getItem())) { if(entity.getEffect(ModEffects.KILL_MODE) != null && !player.getCooldowns().isOnCooldown(itemStack.getItem())) {
poseStack.pushPose(); poseStack.pushPose();
DevilsDevastation.renderEnergyWave(buffer, poseStack, player); ClientDevilsDevastation.renderEnergyWave(buffer, poseStack, player);
poseStack.popPose(); poseStack.popPose();
} }
} }
@@ -43,5 +43,10 @@ public class ModNetwork {
ClearSummonPayload.CODEC, ClearSummonPayload.CODEC,
ClearSummonHandler::handle ClearSummonHandler::handle
); );
registrar.playToClient(
ScreenShakePayload.TYPE,
ScreenShakePayload.CODEC,
ScreenShakeHandler::handle
);
} }
} }
@@ -2,8 +2,10 @@ package com.lzxnone.terraria.network.handler;
import com.lzxnone.terraria.attachment.ModAttachments; import com.lzxnone.terraria.attachment.ModAttachments;
import com.lzxnone.terraria.entity.summon.StaticSummon; import com.lzxnone.terraria.entity.summon.StaticSummon;
import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors;
import com.lzxnone.terraria.item.weapon.SummonWeapon; import com.lzxnone.terraria.item.weapon.SummonWeapon;
import com.lzxnone.terraria.network.payload.ClearSummonPayload; import com.lzxnone.terraria.network.payload.ClearSummonPayload;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
@@ -37,6 +39,19 @@ public class ClearSummonHandler {
} }
player.setData(ModAttachments.SUMMON_WEAPON_SUMMONS, remainingSummons); player.setData(ModAttachments.SUMMON_WEAPON_SUMMONS, remainingSummons);
player.displayClientMessage(
clearAll
? Component.translatable("message.lzxnoneterraria.clear_all_summons")
: Component.translatable("message.lzxnoneterraria.clear_summon", getSummonName(id)),
true
);
}); });
}; };
private static Component getSummonName(String id) {
if(StaticSummonBehaviors.TERRAPRISMA.equals(id)) {
return Component.translatable("item.lzxnoneterraria.terraprisma");
}
return Component.literal(id);
}
} }
@@ -0,0 +1,21 @@
package com.lzxnone.terraria.network.handler;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.network.payload.ScreenShakePayload;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.neoforge.network.handling.IPayloadContext;
public class ScreenShakeHandler {
public static void handle(final ScreenShakePayload payload, final IPayloadContext context) {
context.enqueueWork(() -> {
if(FMLEnvironment.dist != Dist.CLIENT) return;
try {
Class<?> handler = Class.forName("com.lzxnone.terraria.client.event.ScreenShakeHandler");
handler.getMethod("startShake", int.class, float.class).invoke(null, payload.duration(), payload.power());
}catch (ReflectiveOperationException e) {
LzxnoneTerraria.LOGGER.warn("Failed to start screen shake", e);
}
});
}
}
@@ -0,0 +1,24 @@
package com.lzxnone.terraria.network.payload;
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 ScreenShakePayload(int duration, float power) implements CustomPacketPayload {
public static final Type<ScreenShakePayload> TYPE = new Type<>(
ResourceLocation.fromNamespaceAndPath("lzxnoneterraria", "screen_shake_payload")
);
public static final StreamCodec<FriendlyByteBuf, ScreenShakePayload> CODEC = StreamCodec.composite(
ByteBufCodecs.INT, ScreenShakePayload::duration,
ByteBufCodecs.FLOAT, ScreenShakePayload::power,
ScreenShakePayload::new
);
@Override
public Type<? extends CustomPacketPayload> type() {
return TYPE;
}
}
@@ -2,6 +2,8 @@ package com.lzxnone.terraria.ui.config;
import com.lzxnone.terraria.effect.BloodButcheredEffect; import com.lzxnone.terraria.effect.BloodButcheredEffect;
import com.lzxnone.terraria.effect.DemonicFlamesEffect; import com.lzxnone.terraria.effect.DemonicFlamesEffect;
import com.lzxnone.terraria.effect.SummonEffect;
import com.lzxnone.terraria.enchantment.ModEnchantmentConfigs;
import com.lzxnone.terraria.item.weapon.magic.LastPrism; import com.lzxnone.terraria.item.weapon.magic.LastPrism;
import com.lzxnone.terraria.item.weapon.melee.BeeKeeper; import com.lzxnone.terraria.item.weapon.melee.BeeKeeper;
import com.lzxnone.terraria.item.weapon.melee.BladeOfGrass; import com.lzxnone.terraria.item.weapon.melee.BladeOfGrass;
@@ -26,6 +28,7 @@ import com.lzxnone.terraria.item.weapon.melee.TrueExcalibur;
import com.lzxnone.terraria.item.weapon.melee.TrueNightsEdge; import com.lzxnone.terraria.item.weapon.melee.TrueNightsEdge;
import com.lzxnone.terraria.item.weapon.melee.Volcano; import com.lzxnone.terraria.item.weapon.melee.Volcano;
import com.lzxnone.terraria.item.weapon.melee.Zenith; import com.lzxnone.terraria.item.weapon.melee.Zenith;
import com.lzxnone.terraria.item.weapon.summon.Terraprisma;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -33,6 +36,7 @@ import java.util.Map;
public class ConfigList { public class ConfigList {
public static final String WEAPON = "weapon"; public static final String WEAPON = "weapon";
public static final String EFFECT = "effect"; public static final String EFFECT = "effect";
public static final String ENCHANTMENT = "enchantment";
private static final Map<String, ConfigListItem[]> ITEMS = new HashMap<>(); private static final Map<String, ConfigListItem[]> ITEMS = new HashMap<>();
@@ -61,11 +65,21 @@ public class ConfigList {
FirstFractal.CONFIG_LIST_ITEM, FirstFractal.CONFIG_LIST_ITEM,
Mace.CONFIG_LIST_ITEM, Mace.CONFIG_LIST_ITEM,
DevilsDevastation.CONFIG_LIST_ITEM, DevilsDevastation.CONFIG_LIST_ITEM,
Terraprisma.CONFIG_LIST_ITEM,
LastPrism.CONFIG_LIST_ITEM LastPrism.CONFIG_LIST_ITEM
}); });
ITEMS.put(EFFECT, new ConfigListItem[]{ ITEMS.put(EFFECT, new ConfigListItem[]{
BloodButcheredEffect.CONFIG_LIST_ITEM, BloodButcheredEffect.CONFIG_LIST_ITEM,
DemonicFlamesEffect.CONFIG_LIST_ITEM DemonicFlamesEffect.CONFIG_LIST_ITEM,
SummonEffect.CONFIG_LIST_ITEM
});
ITEMS.put(ENCHANTMENT, new ConfigListItem[]{
ModEnchantmentConfigs.MANA_LEAK_CONFIG_LIST_ITEM,
ModEnchantmentConfigs.MANA_EFFICIENCY_CONFIG_LIST_ITEM,
ModEnchantmentConfigs.MANA_GATHERING_CONFIG_LIST_ITEM,
ModEnchantmentConfigs.MANA_GATHERING_CURSE_CONFIG_LIST_ITEM,
ModEnchantmentConfigs.ARCANE_AMPLIFICATION_CONFIG_LIST_ITEM,
ModEnchantmentConfigs.SUMMON_AMPLIFICATION_CONFIG_LIST_ITEM
}); });
} }
@@ -20,7 +20,7 @@ import java.util.Map;
public class ConfigScreen { public class ConfigScreen {
private static final ResourceLocation UI_PATH = ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "ui/config.xml"); private static final ResourceLocation UI_PATH = ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "ui/config.xml");
private static final String[] NAV_KEYS = {"weapon", "effect"}; private static final String[] NAV_KEYS = {ConfigList.WEAPON, ConfigList.EFFECT, ConfigList.ENCHANTMENT};
private static String selectedNavKey = ConfigList.WEAPON; private static String selectedNavKey = ConfigList.WEAPON;
private static final Map<String, Integer> NAV_SELECTED_INDEXES = new HashMap<>(); private static final Map<String, Integer> NAV_SELECTED_INDEXES = new HashMap<>();
@@ -33,6 +33,7 @@ public class ConfigScreen {
//为头部导航按钮设置回调 //为头部导航按钮设置回调
findElement(ui, "nav-button-weapon", Button.class).setOnClick(event -> onNavSelected(ui, ConfigList.WEAPON)); findElement(ui, "nav-button-weapon", Button.class).setOnClick(event -> onNavSelected(ui, ConfigList.WEAPON));
findElement(ui, "nav-button-effect", Button.class).setOnClick(event -> onNavSelected(ui, ConfigList.EFFECT)); findElement(ui, "nav-button-effect", Button.class).setOnClick(event -> onNavSelected(ui, ConfigList.EFFECT));
findElement(ui, "nav-button-enchantment", Button.class).setOnClick(event -> onNavSelected(ui, ConfigList.ENCHANTMENT));
//底部回调 //底部回调
findElement(ui, "button-cancel", Button.class).setOnClick(event -> discardAndReturn(parent)); findElement(ui, "button-cancel", Button.class).setOnClick(event -> discardAndReturn(parent));
@@ -5,9 +5,10 @@ import com.lzxnone.terraria.entity.beam.SwordBeam;
import com.lzxnone.terraria.entity.projectile.StaticProjectile; import com.lzxnone.terraria.entity.projectile.StaticProjectile;
import com.lzxnone.terraria.entity.summon.BeeSummon; import com.lzxnone.terraria.entity.summon.BeeSummon;
import com.lzxnone.terraria.entity.summon.StaticSummon; import com.lzxnone.terraria.entity.summon.StaticSummon;
import com.lzxnone.terraria.item.weapon.MagicWeapon;
import com.lzxnone.terraria.item.weapon.SummonWeapon;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageType; import net.minecraft.world.damagesource.DamageType;
import net.minecraft.world.effect.MobEffects; import net.minecraft.world.effect.MobEffects;
@@ -15,105 +16,94 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import java.util.Objects; import java.util.Objects;
public class DamageUtil { public class DamageUtil {
public static boolean attack(Player player, Entity target, float damage) { public enum DamageCategory {
float finalDamage = damage; MELEE,
if(player.hasEffect(MobEffects.DAMAGE_BOOST) && player.getEffect(MobEffects.DAMAGE_BOOST) != null) { RANGED,
int amplifier = Objects.requireNonNull(player.getEffect(MobEffects.DAMAGE_BOOST)).getAmplifier(); SUMMON,
finalDamage += (amplifier + 1) * 3.0F; MAGIC,
REAL
} }
if(player.hasEffect(MobEffects.WEAKNESS) && player.getEffect(MobEffects.WEAKNESS) != null) { public static boolean meleeAttack(Entity attackEntity, Entity target, ItemStack sourceStack, float damage, float knockbackScale) {
int amplifier = Objects.requireNonNull(player.getEffect(MobEffects.WEAKNESS)).getAmplifier(); return entityAttack(attackEntity, target, sourceStack, damage, knockbackScale, ModDamageTypes.PLAYER_NORMAL_ATTACK, DamageCategory.MELEE);
finalDamage -= (amplifier + 1) * 4.0F;
}
finalDamage = Math.max(0.0F, finalDamage);
DamageSource source = player.level().damageSources().playerAttack(player);
float knockbackLevel = (float) player.getAttributeValue(Attributes.ATTACK_KNOCKBACK);
boolean isSprinting = player.isSprinting();
if(isSprinting) {
knockbackLevel += 1.0F;
} }
if(player.level() instanceof ServerLevel serverLevel) { public static boolean rangedAttack(Entity attackEntity, Entity target, ItemStack sourceStack, float damage, float knockbackScale) {
finalDamage = EnchantmentHelper.modifyDamage(serverLevel, player.getWeaponItem(), target, source, finalDamage); return entityAttack(attackEntity, target, sourceStack, damage, knockbackScale, ModDamageTypes.PLAYER_NORMAL_ATTACK, DamageCategory.RANGED);
knockbackLevel = EnchantmentHelper.modifyKnockback(serverLevel, player.getWeaponItem(), target, source, knockbackLevel);
}
finalDamage = Math.max(0.0F, finalDamage);
boolean hasHurt = target.hurt(source, finalDamage);
if(hasHurt) {
if(knockbackLevel > 0.0F && target instanceof LivingEntity livingTarget) {
livingTarget.knockback(
knockbackLevel * 0.5F,
Mth.sin(player.getYRot() * ((float) Math.PI / 180F)),
-Mth.cos(player.getYRot() * ((float) Math.PI / 180F))
);
if(isSprinting) {
player.setDeltaMovement(player.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D));
player.setSprinting(false);
}
}
if(player.level() instanceof ServerLevel serverLevel) {
EnchantmentHelper.doPostAttackEffects(serverLevel, target, source);
}
} }
return hasHurt; public static boolean summonAttack(Entity attackEntity, Entity target, ItemStack sourceStack, float damage, float knockbackScale) {
return entityAttack(attackEntity, target, sourceStack, damage, knockbackScale, ModDamageTypes.PLAYER_NORMAL_ATTACK, DamageCategory.SUMMON);
} }
public static boolean normalAttack(Entity attackEntity, Entity target, float damage, float knockbackScale) { public static boolean magicAttack(Entity attackEntity, Entity target, ItemStack sourceStack, float damage, float knockbackScale) {
return entityAttack(attackEntity, target, damage, knockbackScale, ModDamageTypes.PLAYER_NORMAL_ATTACK, false); return entityAttack(attackEntity, target, sourceStack, damage, knockbackScale, ModDamageTypes.PLAYER_NORMAL_ATTACK, DamageCategory.MAGIC);
}
public static boolean realAttack(Entity attackEntity, Entity target, float damage) {
return realAttack(attackEntity, target, damage, 0.0F);
} }
public static boolean realAttack(Entity attackEntity, Entity target, float damage, float knockbackScale) { public static boolean realAttack(Entity attackEntity, Entity target, float damage, float knockbackScale) {
return entityAttack(attackEntity, target, damage, knockbackScale, ModDamageTypes.PLAYER_REAL_ATTACK, true); return entityAttack(attackEntity, target, ItemStack.EMPTY, damage, knockbackScale, ModDamageTypes.PLAYER_REAL_ATTACK, DamageCategory.REAL);
} }
private static boolean entityAttack( private static boolean entityAttack(
Entity attackEntity, Entity attackEntity,
Entity target, Entity target,
ItemStack sourceStack,
float damage, float damage,
float knockbackScale, float knockbackScale,
ResourceKey<DamageType> damageType, ResourceKey<DamageType> damageType,
boolean realDamage DamageCategory category
) { ) {
Player player = getAttackOwner(attackEntity); Player player = getAttackOwner(attackEntity);
if(player == null || !(attackEntity.level() instanceof ServerLevel serverLevel)) return false; if(player == null || !(attackEntity.level() instanceof ServerLevel serverLevel)) return false;
DamageSource source = attackEntity.level().damageSources().source(damageType, attackEntity, player); DamageSource source = attackEntity.level().damageSources().source(damageType, attackEntity, player);
float finalDamage = realDamage ? Math.max(0.0F, damage) : applyPlayerDamageEffects(player, damage); ItemStack itemSource = sourceStack == null ? ItemStack.EMPTY : sourceStack;
float knockbackLevel = (float) player.getAttributeValue(Attributes.ATTACK_KNOCKBACK);
if(!realDamage) { //应用药水
finalDamage = EnchantmentHelper.modifyDamage(serverLevel, player.getWeaponItem(), target, source, finalDamage); float finalDamage = category == DamageCategory.REAL ? Math.max(0.0F, damage) : applyPlayerDamageEffects(player, damage);
knockbackLevel = EnchantmentHelper.modifyKnockback(serverLevel, player.getWeaponItem(), target, source, knockbackLevel); float knockbackLevel = (float) player.getAttributeValue(Attributes.ATTACK_KNOCKBACK);
//
//应用附魔
if(category == DamageCategory.MELEE && !itemSource.isEmpty()) {
finalDamage = EnchantmentHelper.modifyDamage(serverLevel, itemSource, target, source, finalDamage);
knockbackLevel = EnchantmentHelper.modifyKnockback(serverLevel, itemSource, target, source, knockbackLevel);
}else if(category == DamageCategory.SUMMON && !itemSource.isEmpty()) {
finalDamage = SummonWeapon.applySummonDamageBonus(itemSource, player, finalDamage);
}else if(category == DamageCategory.MAGIC && !itemSource.isEmpty()) {
finalDamage = MagicWeapon.applyMagicDamageBonus(itemSource, player, finalDamage);
} }
finalDamage = Math.max(0.0F, finalDamage); finalDamage = Math.max(0.0F, finalDamage);
Vec3 beforeHurtMovement = target instanceof LivingEntity livingTarget ? livingTarget.getDeltaMovement() : Vec3.ZERO;
boolean hasHurt = target.hurt(source, finalDamage); boolean hasHurt = target.hurt(source, finalDamage);
if(hasHurt) { if(hasHurt) {
float finalKnockback = knockbackLevel * knockbackScale; if(category != DamageCategory.SUMMON && target instanceof LivingEntity livingTarget) {
if(finalKnockback > 0.0F && target instanceof LivingEntity livingTarget) { player.setLastHurtMob(livingTarget);
}
if(target instanceof LivingEntity livingTarget) {
Vec3 hurtKnockback = livingTarget.getDeltaMovement().subtract(beforeHurtMovement);
Vec3 extraKnockback = Vec3.ZERO;
if(knockbackLevel > 0.0F) {
livingTarget.setDeltaMovement(beforeHurtMovement);
Vec3 knockbackDirection = getAttackKnockbackDirection(attackEntity, target); Vec3 knockbackDirection = getAttackKnockbackDirection(attackEntity, target);
livingTarget.knockback(finalKnockback * 0.5F, knockbackDirection.x, knockbackDirection.z); livingTarget.knockback(knockbackLevel * 0.5F, -knockbackDirection.x, -knockbackDirection.z);
extraKnockback = livingTarget.getDeltaMovement().subtract(beforeHurtMovement);
} }
if(!realDamage) {
EnchantmentHelper.doPostAttackEffects(serverLevel, target, source); livingTarget.setDeltaMovement(beforeHurtMovement.add(hurtKnockback.add(extraKnockback).scale(knockbackScale)));
} }
DamageSource postSource = attackEntity == player
? source
: attackEntity.level().damageSources().source(damageType, player, player);
EnchantmentHelper.doPostAttackEffectsWithItemSource(serverLevel, target, postSource, itemSource.isEmpty() ? null : itemSource);
} }
return hasHurt; return hasHurt;
@@ -121,10 +111,12 @@ public class DamageUtil {
private static float applyPlayerDamageEffects(Player player, float damage) { private static float applyPlayerDamageEffects(Player player, float damage) {
float finalDamage = damage; float finalDamage = damage;
//力量
if(player.hasEffect(MobEffects.DAMAGE_BOOST) && player.getEffect(MobEffects.DAMAGE_BOOST) != null) { if(player.hasEffect(MobEffects.DAMAGE_BOOST) && player.getEffect(MobEffects.DAMAGE_BOOST) != null) {
int amplifier = Objects.requireNonNull(player.getEffect(MobEffects.DAMAGE_BOOST)).getAmplifier(); int amplifier = Objects.requireNonNull(player.getEffect(MobEffects.DAMAGE_BOOST)).getAmplifier();
finalDamage += (amplifier + 1) * 3.0F; finalDamage += (amplifier + 1) * 3.0F;
} }
//虚弱
if(player.hasEffect(MobEffects.WEAKNESS) && player.getEffect(MobEffects.WEAKNESS) != null) { if(player.hasEffect(MobEffects.WEAKNESS) && player.getEffect(MobEffects.WEAKNESS) != null) {
int amplifier = Objects.requireNonNull(player.getEffect(MobEffects.WEAKNESS)).getAmplifier(); int amplifier = Objects.requireNonNull(player.getEffect(MobEffects.WEAKNESS)).getAmplifier();
finalDamage -= (amplifier + 1) * 4.0F; finalDamage -= (amplifier + 1) * 4.0F;
@@ -38,6 +38,7 @@
"enchantment.lzxnoneterraria.mana_gathering": "Mana Gathering", "enchantment.lzxnoneterraria.mana_gathering": "Mana Gathering",
"enchantment.lzxnoneterraria.mana_gathering_curse": "Mana Gathering Curse", "enchantment.lzxnoneterraria.mana_gathering_curse": "Mana Gathering Curse",
"enchantment.lzxnoneterraria.arcane_amplification": "Arcane Amplification", "enchantment.lzxnoneterraria.arcane_amplification": "Arcane Amplification",
"enchantment.lzxnoneterraria.summon_amplification": "Summon Amplification",
"death.attack.lzxnoneterraria.player_normal": "%1$s was slain by %2$s", "death.attack.lzxnoneterraria.player_normal": "%1$s was slain by %2$s",
"death.attack.lzxnoneterraria.player_normal.item": "%1$s was slain by %2$s using %3$s", "death.attack.lzxnoneterraria.player_normal.item": "%1$s was slain by %2$s using %3$s",
@@ -61,23 +62,46 @@
"effect.lzxnoneterraria.kill_mode_cooldown": "Kill Mode Cooldown", "effect.lzxnoneterraria.kill_mode_cooldown": "Kill Mode Cooldown",
"effect.lzxnoneterraria.demonic_flames": "Demonic Flames", "effect.lzxnoneterraria.demonic_flames": "Demonic Flames",
"effect.lzxnoneterraria.summon": "Summon", "effect.lzxnoneterraria.summon": "Summon",
"item.minecraft.potion.effect.summon": "Potion of Summon",
"item.minecraft.splash_potion.effect.summon": "Splash Potion of Summon",
"item.minecraft.lingering_potion.effect.summon": "Lingering Potion of Summon",
"item.minecraft.tipped_arrow.effect.summon": "Arrow of Summon",
"key.categories.lzxnoneterraria": "lzxnoneterraria", "key.categories.lzxnoneterraria": "lzxnoneterraria",
"key.lzxnoneterraria.kill_mode": "Kill Mode", "key.lzxnoneterraria.kill_mode": "Kill Mode",
"key.lzxnoneterraria.clear_summon": "Clear Selected Summons", "key.lzxnoneterraria.clear_summon": "Clear Selected Summons",
"key.lzxnoneterraria.clear_all_summons": "Clear All Summons", "key.lzxnoneterraria.clear_all_summons": "Clear All Summons",
"message.lzxnoneterraria.current_summons": "Current summons %s/%s",
"message.lzxnoneterraria.clear_all_summons": "Cleared all summons",
"message.lzxnoneterraria.clear_summon": "Cleared %s",
"lzxnoneterraria.configuration.title": "LzxnoneTerraria Config", "lzxnoneterraria.configuration.title": "LzxnoneTerraria Config",
"lzxnoneterraria.configuration.nav_weapon": "Weapon", "lzxnoneterraria.configuration.nav_weapon": "Weapon",
"lzxnoneterraria.configuration.nav_effect": "Effect", "lzxnoneterraria.configuration.nav_effect": "Effect",
"lzxnoneterraria.configuration.nav_enchantment": "Enchantment",
"lzxnoneterraria.configuration.reset_button": "Reset", "lzxnoneterraria.configuration.reset_button": "Reset",
"lzxnoneterraria.configuration.cancel_button": "Cancel", "lzxnoneterraria.configuration.cancel_button": "Cancel",
"lzxnoneterraria.configuration.confirm_button": "Confirm", "lzxnoneterraria.configuration.confirm_button": "Confirm",
"lzxnoneterraria.configuration.mana_leak_consume_multiplier": "Mana Consume Multiplier",
"lzxnoneterraria.configuration.mana_leak_consume_multiplier.tooltip": "Mana consume rate multiplier per Mana Leak level",
"lzxnoneterraria.configuration.mana_efficiency_consume_multiplier": "Mana Consume Multiplier",
"lzxnoneterraria.configuration.mana_efficiency_consume_multiplier.tooltip": "Mana consume rate multiplier per Mana Efficiency level",
"lzxnoneterraria.configuration.mana_gathering_recover_multiplier": "Mana Recover Multiplier",
"lzxnoneterraria.configuration.mana_gathering_recover_multiplier.tooltip": "Mana recover rate multiplier per Mana Gathering level",
"lzxnoneterraria.configuration.mana_gathering_curse_recover_multiplier": "Mana Recover Multiplier",
"lzxnoneterraria.configuration.mana_gathering_curse_recover_multiplier.tooltip": "Mana recover rate multiplier per Mana Gathering Curse level",
"lzxnoneterraria.configuration.arcane_amplification_damage_multiplier": "Magic Damage Multiplier",
"lzxnoneterraria.configuration.arcane_amplification_damage_multiplier.tooltip": "Magic damage multiplier per Arcane Amplification level",
"lzxnoneterraria.configuration.summon_amplification_damage_multiplier": "Summon Damage Multiplier",
"lzxnoneterraria.configuration.summon_amplification_damage_multiplier.tooltip": "Summon damage multiplier per Summon Amplification level",
"lzxnoneterraria.configuration.effect_settings": "Effect Settings", "lzxnoneterraria.configuration.effect_settings": "Effect Settings",
"lzxnoneterraria.configuration.blood_butcherer_damage_per_level": "Blood Butcherer Effect Damage Per Level", "lzxnoneterraria.configuration.blood_butcherer_damage_per_level": "Blood Butcherer Effect Damage Per Level",
"lzxnoneterraria.configuration.blood_butcherer_damage_per_level.tooltip": "Damage dealt per effect level", "lzxnoneterraria.configuration.blood_butcherer_damage_per_level.tooltip": "Damage dealt per effect level",
"lzxnoneterraria.configuration.demonic_flames_damage_per_level": "Demonic Flames Damage Per Level", "lzxnoneterraria.configuration.demonic_flames_damage_per_level": "Demonic Flames Damage Per Level",
"lzxnoneterraria.configuration.demonic_flames_damage_per_level.tooltip": "Damage dealt per effect level", "lzxnoneterraria.configuration.demonic_flames_damage_per_level.tooltip": "Damage dealt per effect level",
"lzxnoneterraria.configuration.summon_settings": "Summon Settings",
"lzxnoneterraria.configuration.summon_summon_count_per_level": "Summon Count Per Level",
"lzxnoneterraria.configuration.summon_summon_count_per_level.tooltip": "Extra summon count granted by each level of the summon effect",
"lzxnoneterraria.configuration.enchanted_sword_settings": "Enchanted Sword Settings", "lzxnoneterraria.configuration.enchanted_sword_settings": "Enchanted Sword Settings",
"lzxnoneterraria.configuration.enchanted_sword_damage": "Projectile Damage", "lzxnoneterraria.configuration.enchanted_sword_damage": "Projectile Damage",
"lzxnoneterraria.configuration.enchanted_sword_damage.tooltip": "Damage per hit", "lzxnoneterraria.configuration.enchanted_sword_damage.tooltip": "Damage per hit",
@@ -327,6 +351,23 @@
"lzxnoneterraria.configuration.mace_fly_time.tooltip": "Maximum projectile fly time in ticks", "lzxnoneterraria.configuration.mace_fly_time.tooltip": "Maximum projectile fly time in ticks",
"lzxnoneterraria.configuration.mace_max_range": "Max Range", "lzxnoneterraria.configuration.mace_max_range": "Max Range",
"lzxnoneterraria.configuration.mace_max_range.tooltip": "Maximum projectile travel range", "lzxnoneterraria.configuration.mace_max_range.tooltip": "Maximum projectile travel range",
"lzxnoneterraria.configuration.terraprisma_settings": "Terraprisma Settings",
"lzxnoneterraria.configuration.terraprisma_target_range": "Target Acquisition Range",
"lzxnoneterraria.configuration.terraprisma_target_range.tooltip": "Maximum range for summons to search for and keep targets",
"lzxnoneterraria.configuration.terraprisma_follow_speed": "Follow Speed",
"lzxnoneterraria.configuration.terraprisma_follow_speed.tooltip": "Maximum speed while returning to the player in idle state",
"lzxnoneterraria.configuration.terraprisma_dash_pre_speed": "Pre-Dash Speed",
"lzxnoneterraria.configuration.terraprisma_dash_pre_speed.tooltip": "Initial speed when entering pre-dash, negative values move backward",
"lzxnoneterraria.configuration.terraprisma_dash_pre_friction": "Pre-Dash Friction",
"lzxnoneterraria.configuration.terraprisma_dash_pre_friction.tooltip": "Velocity retention per tick during pre-dash",
"lzxnoneterraria.configuration.terraprisma_dash_speed": "Dash Speed",
"lzxnoneterraria.configuration.terraprisma_dash_speed.tooltip": "Movement speed during dash attacks",
"lzxnoneterraria.configuration.terraprisma_dash_friction": "Dash Friction",
"lzxnoneterraria.configuration.terraprisma_dash_friction.tooltip": "Velocity retention per tick after dash ends",
"lzxnoneterraria.configuration.terraprisma_rotate_speed": "Rotate Attack Speed",
"lzxnoneterraria.configuration.terraprisma_rotate_speed.tooltip": "Approximate linear speed along the ellipse during rotate attacks",
"lzxnoneterraria.configuration.terraprisma_damage": "Damage",
"lzxnoneterraria.configuration.terraprisma_damage.tooltip": "Base damage dealt per summon hit",
"lzxnoneterraria.configuration.last_prism_settings": "Last Prism Settings", "lzxnoneterraria.configuration.last_prism_settings": "Last Prism Settings",
"lzxnoneterraria.configuration.last_prism_damage": "Damage", "lzxnoneterraria.configuration.last_prism_damage": "Damage",
"lzxnoneterraria.configuration.last_prism_damage.tooltip": "Damage per hit", "lzxnoneterraria.configuration.last_prism_damage.tooltip": "Damage per hit",
@@ -38,6 +38,7 @@
"enchantment.lzxnoneterraria.mana_gathering": "魔力聚集", "enchantment.lzxnoneterraria.mana_gathering": "魔力聚集",
"enchantment.lzxnoneterraria.mana_gathering_curse": "聚魔诅咒", "enchantment.lzxnoneterraria.mana_gathering_curse": "聚魔诅咒",
"enchantment.lzxnoneterraria.arcane_amplification": "奥术增幅", "enchantment.lzxnoneterraria.arcane_amplification": "奥术增幅",
"enchantment.lzxnoneterraria.summon_amplification": "召唤增幅",
"death.attack.lzxnoneterraria.player_normal": "%1$s 被 %2$s 击杀", "death.attack.lzxnoneterraria.player_normal": "%1$s 被 %2$s 击杀",
"death.attack.lzxnoneterraria.player_normal.item": "%1$s 被 %2$s 用 %3$s 击杀", "death.attack.lzxnoneterraria.player_normal.item": "%1$s 被 %2$s 用 %3$s 击杀",
@@ -60,23 +61,46 @@
"effect.lzxnoneterraria.kill_mode_cooldown": "杀戮模式 冷却", "effect.lzxnoneterraria.kill_mode_cooldown": "杀戮模式 冷却",
"effect.lzxnoneterraria.demonic_flames": "恶魔之焰", "effect.lzxnoneterraria.demonic_flames": "恶魔之焰",
"effect.lzxnoneterraria.summon": "召唤", "effect.lzxnoneterraria.summon": "召唤",
"item.minecraft.potion.effect.summon": "召唤药水",
"item.minecraft.splash_potion.effect.summon": "喷溅型召唤药水",
"item.minecraft.lingering_potion.effect.summon": "滞留型召唤药水",
"item.minecraft.tipped_arrow.effect.summon": "召唤之箭",
"key.categories.lzxnoneterraria": "lzxnoneterraria", "key.categories.lzxnoneterraria": "lzxnoneterraria",
"key.lzxnoneterraria.kill_mode": "进入杀戮模式", "key.lzxnoneterraria.kill_mode": "进入杀戮模式",
"key.lzxnoneterraria.clear_summon": "清除指定召唤物", "key.lzxnoneterraria.clear_summon": "清除指定召唤物",
"key.lzxnoneterraria.clear_all_summons": "清除所有召唤物", "key.lzxnoneterraria.clear_all_summons": "清除所有召唤物",
"message.lzxnoneterraria.current_summons": "当前召唤物 %s/%s",
"message.lzxnoneterraria.clear_all_summons": "已清除所有召唤物",
"message.lzxnoneterraria.clear_summon": "已清除%s",
"lzxnoneterraria.configuration.title": "LzxnoneTerraria 配置", "lzxnoneterraria.configuration.title": "LzxnoneTerraria 配置",
"lzxnoneterraria.configuration.nav_weapon": "武器", "lzxnoneterraria.configuration.nav_weapon": "武器",
"lzxnoneterraria.configuration.nav_effect": "药水效果", "lzxnoneterraria.configuration.nav_effect": "药水效果",
"lzxnoneterraria.configuration.nav_enchantment": "附魔",
"lzxnoneterraria.configuration.reset_button": "重置", "lzxnoneterraria.configuration.reset_button": "重置",
"lzxnoneterraria.configuration.cancel_button": "取消", "lzxnoneterraria.configuration.cancel_button": "取消",
"lzxnoneterraria.configuration.confirm_button": "确定", "lzxnoneterraria.configuration.confirm_button": "确定",
"lzxnoneterraria.configuration.mana_leak_consume_multiplier": "魔力消耗倍率",
"lzxnoneterraria.configuration.mana_leak_consume_multiplier.tooltip": "每级魔力泄露对魔力消耗速率的倍率",
"lzxnoneterraria.configuration.mana_efficiency_consume_multiplier": "魔力消耗倍率",
"lzxnoneterraria.configuration.mana_efficiency_consume_multiplier.tooltip": "每级魔力效率对魔力消耗速率的倍率",
"lzxnoneterraria.configuration.mana_gathering_recover_multiplier": "魔力恢复倍率",
"lzxnoneterraria.configuration.mana_gathering_recover_multiplier.tooltip": "每级魔力聚集对魔力恢复速率的倍率",
"lzxnoneterraria.configuration.mana_gathering_curse_recover_multiplier": "魔力恢复倍率",
"lzxnoneterraria.configuration.mana_gathering_curse_recover_multiplier.tooltip": "每级聚魔诅咒对魔力恢复速率的倍率",
"lzxnoneterraria.configuration.arcane_amplification_damage_multiplier": "魔法伤害倍率",
"lzxnoneterraria.configuration.arcane_amplification_damage_multiplier.tooltip": "每级奥术增幅对魔法伤害的倍率",
"lzxnoneterraria.configuration.summon_amplification_damage_multiplier": "召唤伤害倍率",
"lzxnoneterraria.configuration.summon_amplification_damage_multiplier.tooltip": "每级召唤增幅对召唤伤害的倍率",
"lzxnoneterraria.configuration.effect_settings": "药水效果 设置", "lzxnoneterraria.configuration.effect_settings": "药水效果 设置",
"lzxnoneterraria.configuration.blood_butcherer_damage_per_level": "血腥屠宰效果每级伤害", "lzxnoneterraria.configuration.blood_butcherer_damage_per_level": "血腥屠宰效果每级伤害",
"lzxnoneterraria.configuration.blood_butcherer_damage_per_level.tooltip": "每级造成的伤害", "lzxnoneterraria.configuration.blood_butcherer_damage_per_level.tooltip": "每级造成的伤害",
"lzxnoneterraria.configuration.demonic_flames_damage_per_level": "恶魔之焰效果每级伤害", "lzxnoneterraria.configuration.demonic_flames_damage_per_level": "恶魔之焰效果每级伤害",
"lzxnoneterraria.configuration.demonic_flames_damage_per_level.tooltip": "每级造成的伤害", "lzxnoneterraria.configuration.demonic_flames_damage_per_level.tooltip": "每级造成的伤害",
"lzxnoneterraria.configuration.summon_settings": "召唤 设置",
"lzxnoneterraria.configuration.summon_summon_count_per_level": "每级召唤数量",
"lzxnoneterraria.configuration.summon_summon_count_per_level.tooltip": "召唤效果每级额外增加的召唤物数量",
"lzxnoneterraria.configuration.enchanted_sword_settings": "附魔剑 设置", "lzxnoneterraria.configuration.enchanted_sword_settings": "附魔剑 设置",
"lzxnoneterraria.configuration.enchanted_sword_damage": "弹射伤害", "lzxnoneterraria.configuration.enchanted_sword_damage": "弹射伤害",
"lzxnoneterraria.configuration.enchanted_sword_damage.tooltip": "每次命中伤害", "lzxnoneterraria.configuration.enchanted_sword_damage.tooltip": "每次命中伤害",
@@ -326,6 +350,23 @@
"lzxnoneterraria.configuration.mace_fly_time.tooltip": "弹射物最大飞行时间(刻)", "lzxnoneterraria.configuration.mace_fly_time.tooltip": "弹射物最大飞行时间(刻)",
"lzxnoneterraria.configuration.mace_max_range": "最大范围", "lzxnoneterraria.configuration.mace_max_range": "最大范围",
"lzxnoneterraria.configuration.mace_max_range.tooltip": "弹射物最大飞行距离", "lzxnoneterraria.configuration.mace_max_range.tooltip": "弹射物最大飞行距离",
"lzxnoneterraria.configuration.terraprisma_settings": "泰拉棱镜 设置",
"lzxnoneterraria.configuration.terraprisma_target_range": "寻敌范围",
"lzxnoneterraria.configuration.terraprisma_target_range.tooltip": "召唤物搜索和维持目标的最大距离",
"lzxnoneterraria.configuration.terraprisma_follow_speed": "跟随速度",
"lzxnoneterraria.configuration.terraprisma_follow_speed.tooltip": "闲置状态下返回玩家身边的最大速度",
"lzxnoneterraria.configuration.terraprisma_dash_pre_speed": "预冲刺速度",
"lzxnoneterraria.configuration.terraprisma_dash_pre_speed.tooltip": "进入预冲刺时的初始速度,负值表示后撤",
"lzxnoneterraria.configuration.terraprisma_dash_pre_friction": "预冲刺阻力",
"lzxnoneterraria.configuration.terraprisma_dash_pre_friction.tooltip": "预冲刺状态下每刻速度保留比例",
"lzxnoneterraria.configuration.terraprisma_dash_speed": "冲刺速度",
"lzxnoneterraria.configuration.terraprisma_dash_speed.tooltip": "冲刺攻击的移动速度",
"lzxnoneterraria.configuration.terraprisma_dash_friction": "冲刺阻力",
"lzxnoneterraria.configuration.terraprisma_dash_friction.tooltip": "冲刺结束后每刻速度保留比例",
"lzxnoneterraria.configuration.terraprisma_rotate_speed": "旋转攻击速度",
"lzxnoneterraria.configuration.terraprisma_rotate_speed.tooltip": "旋转攻击沿椭圆轨迹移动的近似线速度",
"lzxnoneterraria.configuration.terraprisma_damage": "伤害",
"lzxnoneterraria.configuration.terraprisma_damage.tooltip": "召唤物每次命中造成的基础伤害",
"lzxnoneterraria.configuration.last_prism_settings": "终极棱镜 设置", "lzxnoneterraria.configuration.last_prism_settings": "终极棱镜 设置",
"lzxnoneterraria.configuration.last_prism_damage": "伤害", "lzxnoneterraria.configuration.last_prism_damage": "伤害",
"lzxnoneterraria.configuration.last_prism_damage.tooltip": "每次命中伤害", "lzxnoneterraria.configuration.last_prism_damage.tooltip": "每次命中伤害",
@@ -90,6 +90,10 @@
background: sprite(lzxnoneterraria:textures/ui/nav_effect_icon.png); background: sprite(lzxnoneterraria:textures/ui/nav_effect_icon.png);
} }
.nav-img-enchantment {
background: sprite(lzxnoneterraria:textures/ui/nav_enchantment_icon.png);
}
.main { .main {
flex: 1; flex: 1;
flex-direction: row; flex-direction: row;
Binary file not shown.

After

Width:  |  Height:  |  Size: 12 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

@@ -24,6 +24,13 @@
</button> </button>
<element class="nav-indicator"/> <element class="nav-indicator"/>
</element> </element>
<element id="nav-item-enchantment" class="nav-item">
<button id="nav-button-enchantment" class="nav-button" text="">
<element class="nav-img nav-img-enchantment"/>
<label class="nav-label"><lang key="lzxnoneterraria.configuration.nav_enchantment"/></label>
</button>
<element class="nav-indicator"/>
</element>
</element> </element>
</element> </element>
@@ -0,0 +1,21 @@
{
"anvil_cost": 6,
"description": {
"translate": "enchantment.lzxnoneterraria.summon_amplification"
},
"max_cost": {
"base": 60,
"per_level_above_first": 15
},
"max_level": 3,
"min_cost": {
"base": 15,
"per_level_above_first": 15
},
"primary_items": "#lzxnoneterraria:summon_weapons",
"slots": [
"mainhand"
],
"supported_items": "#lzxnoneterraria:summon_weapons",
"weight": 3
}
@@ -5,6 +5,7 @@
"lzxnoneterraria:mana_efficiency", "lzxnoneterraria:mana_efficiency",
"lzxnoneterraria:mana_gathering", "lzxnoneterraria:mana_gathering",
"lzxnoneterraria:mana_gathering_curse", "lzxnoneterraria:mana_gathering_curse",
"lzxnoneterraria:arcane_amplification" "lzxnoneterraria:arcane_amplification",
"lzxnoneterraria:summon_amplification"
] ]
} }
@@ -4,6 +4,7 @@
"lzxnoneterraria:mana_leak", "lzxnoneterraria:mana_leak",
"lzxnoneterraria:mana_efficiency", "lzxnoneterraria:mana_efficiency",
"lzxnoneterraria:mana_gathering", "lzxnoneterraria:mana_gathering",
"lzxnoneterraria:arcane_amplification" "lzxnoneterraria:arcane_amplification",
"lzxnoneterraria:summon_amplification"
] ]
} }
@@ -5,6 +5,7 @@
"lzxnoneterraria:mana_efficiency", "lzxnoneterraria:mana_efficiency",
"lzxnoneterraria:mana_gathering", "lzxnoneterraria:mana_gathering",
"lzxnoneterraria:mana_gathering_curse", "lzxnoneterraria:mana_gathering_curse",
"lzxnoneterraria:arcane_amplification" "lzxnoneterraria:arcane_amplification",
"lzxnoneterraria:summon_amplification"
] ]
} }
@@ -3,13 +3,13 @@
"minVersion": "0.8", "minVersion": "0.8",
"package": "com.lzxnone.terraria.mixin", "package": "com.lzxnone.terraria.mixin",
"compatibilityLevel": "JAVA_21", "compatibilityLevel": "JAVA_21",
"mixins": [ "mixins": [],
"client": [
"GuiGraphicsMixin", "GuiGraphicsMixin",
"GuiMixin", "GuiMixin",
"ItemInHandRenderMixin", "ItemInHandRenderMixin",
"UseSpeedMixin" "UseSpeedMixin"
], ],
"client": [],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1
} }