v1.1-pre2

This commit is contained in:
LZX committed 2026-07-04 21:14:32 +08:00
1 parent 71dcdaa10a
commit 72a15c93ae
24 files changed
+313 -89

No files matched your search

@@ -50,5 +50,8 @@ public class LzxnoneTerrariaClient {
modEventBus.addListener(RegisterParticleProvidersEvent.class, event -> {
event.registerSpriteSet(ModParticles.INFLUX_WAVER_DROP_PARTICLE.get(), InfluxWaverDropParticle.Provider::new);
});
modEventBus.addListener(RegisterParticleProvidersEvent.class, event -> {
event.registerSpriteSet(ModParticles.TERRA_BEAM_HIT_PARTICLE.get(), TerraBeamHitParticle.Provider::new);
});
}
}
@@ -1,5 +1,6 @@
package com.lzxnone.terraria.entity.beam;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.utils.MathUtil;
import com.mojang.blaze3d.vertex.PoseStack;
@@ -13,6 +14,7 @@ import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
@@ -46,8 +48,7 @@ public interface ISwordBeamBehavior {
float progress = (age + partialTick) / (float) lifetime;
if(progress > 1.0f) progress = 1.0f;
Vec3 look = owner.getLookAngle().normalize();
Vector3f[] dirs = MathUtil.computeDir(MathUtil.toVector3f(look));
Vector3f[] dirs = MathUtil.computeCoordinateSystem(beam.getOwner());
VertexConsumer vertexConsumer0 = bufferSource.getBuffer(RenderType.entityTranslucentEmissive(RES0));
VertexConsumer vertexConsumer1 = bufferSource.getBuffer(RenderType.entityTranslucentEmissive(RES0));
@@ -154,11 +155,9 @@ public interface ISwordBeamBehavior {
Quaternionf rotation = new Quaternionf().fromAxisAngleRad(up, angle);
poseStack.mulPose(rotation);
float xzLen0 = (float) Math.sqrt(dir.x * dir.x + dir.z * dir.z);
float pitch0 = (float) (Math.atan2(-dir.y, xzLen0) * (180.0 / Math.PI));
float yaw0 = (float) (Math.atan2(-dir.x, dir.z) * (180.0 / Math.PI));
poseStack.mulPose(Axis.YP.rotationDegrees(-yaw0));
poseStack.mulPose(Axis.XP.rotationDegrees(pitch0));
float[] xyRot = MathUtil.computeXYRot(dir, up);
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));
@@ -205,6 +204,7 @@ public interface ISwordBeamBehavior {
Vec3 pos = new Vec3(entity.getX(), entity.getY() + entity.getBbHeight() / 2, entity.getZ());
beam.setPos(pos);
if(beamData.contains("behavior")) beam.getEntityData().set(SwordBeam.BEHAVIOR, beamData.getString("behavior"));
if(beamData.contains("color0R") && beamData.contains("color0G") && beamData.contains("color0B")) {
beam.getEntityData().set(SwordBeam.COLOR0, new Vector3f(beamData.getFloat("color0R"), beamData.getFloat("color0G"), beamData.getFloat("color0B")));
}
@@ -1,6 +1,7 @@
package com.lzxnone.terraria.entity.beam;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.entity.projectile.StaticProjectile;
import com.lzxnone.terraria.utils.FilterUtil;
import com.lzxnone.terraria.utils.MathUtil;
import net.minecraft.nbt.CompoundTag;
@@ -10,6 +11,7 @@ import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.*;
@@ -107,12 +109,11 @@ public class SwordBeam extends Entity {
}
public void checkCollision() {
if(owner == null) return;
Entity owner = getOwner();
float progress = (float) this.entityData.get(AGE) / (float) this.entityData.get(LIFETIME);
if(progress > 1.0f) progress = 1.0f;
Vec3 look = owner.getLookAngle().normalize();
this.dirs = MathUtil.computeDir(MathUtil.toVector3f(look));
this.dirs = MathUtil.computeCoordinateSystem(owner);
Vector3f dir = dirs[0];
Vector3f up = dirs[1];
Vector3f right = dirs[2];
@@ -46,7 +46,7 @@ public interface IStaticProjectileBehavior {
velForRot = new Vector3f(proj.getEntityData().get(StaticProjectile.DIRECTION));
}
Vector3f[] dirs = MathUtil.computeDir(velForRot);
Vector3f[] dirs = MathUtil.computeCoordinateSystem(velForRot, 0);
Matrix3f rotMatrix = new Matrix3f().set(dirs[2], dirs[1], dirs[0]);
poseStack.mulPose(new Quaternionf().setFromNormalized(rotMatrix));
@@ -105,7 +105,7 @@ public interface IStaticProjectileBehavior {
velForRot = new Vector3f(proj.getEntityData().get(StaticProjectile.DIRECTION));
}
Vector3f[] dirs = MathUtil.computeDir(velForRot);
Vector3f[] dirs = MathUtil.computeCoordinateSystem(velForRot, 0);
Matrix3f rotMatrix = new Matrix3f().set(dirs[2], dirs[1], dirs[0]);
poseStack.mulPose(new Quaternionf().setFromNormalized(rotMatrix));
@@ -18,6 +18,7 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.joml.Vector3f;
public class BeeSummon extends Bee {
public static final int LIFETIME = 1200;
@@ -91,14 +92,16 @@ public class BeeSummon extends Bee {
this.setDeltaMovement(this.getDeltaMovement().normalize().scale(FRICTION));
this.doHurtTarget(target);
}
float[] xyRot = MathUtil.computeXYRot(MathUtil.toVector3f(this.getDeltaMovement()));
Vector3f[] dirs = MathUtil.computeCoordinateSystem(this.getDeltaMovement().toVector3f(), this.getYRot());
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
this.setXRot(xyRot[0]);
this.setYRot(xyRot[1]);
}else {
if(this.tickCount % 40 == 0) {
Vec3 targetPos = MathUtil.getRandomPosInRadius(this.position(), 16);
this.setDeltaMovement(targetPos.subtract(this.position()).normalize().scale(SPEED / 4));
float[] xyRot = MathUtil.computeXYRot(MathUtil.toVector3f(this.getDeltaMovement()));
Vector3f[] dirs = MathUtil.computeCoordinateSystem(this.getDeltaMovement().toVector3f(), this.getYRot());
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
this.setXRot(xyRot[0]);
this.setYRot(xyRot[1]);
}
@@ -20,9 +20,7 @@ public class ModItems {
public static final DeferredItem<Item> STAR_WRATH = ITEMS.register("star_wrath", StarWrath::new);
public static final DeferredItem<Item> MEOWMERE = ITEMS.register("meowmere", Meowmere::new);
public static final DeferredItem<Item> TERRA_BLADE = ITEMS.register("terra_blade", TerraBlade::new);
public static final DeferredItem<Item> ZENITH = ITEMS.register("zenith",
() -> new Item(new Item.Properties()));
public static final DeferredItem<Item> ZENITH = ITEMS.register("zenith", Zenith::new);
//弹射物
public static final DeferredItem<Item> ENCHANTED_SWORD_BEAM = ITEMS.register("enchanted_sword_beam", EnchantedSwordBeam::new);
@@ -70,6 +70,7 @@ public class EnchantedSword extends SwordItem {
if(owner == null) return;
if(!FilterUtil.createLivingTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(target.hurt(projectile.damageSources().playerAttack(player), 5.5f)) {
target.invulnerableTime = 5;
ParticleUtil.addParticles(
(ServerLevel) projectile.level(), ModParticles.COLORFUL_PARTICLE,
projectile.position(), new Vec3(0.2, 0.2, 0.2),
@@ -94,11 +95,7 @@ public class EnchantedSword extends SwordItem {
ItemStack stack = player.getItemInHand(hand);
if(!level.isClientSide()) {
Vec3 lookVec = player.getLookAngle();
Vector3f[] dirs = MathUtil.computeDir(
MathUtil.toVector3f(lookVec)
);
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level);
projectile.setOwner(player);
Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ());
@@ -129,11 +129,13 @@ public class InfluxWaver extends SwordItem {
}
}
if(idx > 0) {
float[] xyRot = MathUtil.computeXYRot(MathUtil.toVector3f(summon.getDeltaMovement()));
summon.setXRot(xyRot[0]);
summon.xRotO = xyRot[0];
summon.setYRot(xyRot[1]);
summon.yRotO = xyRot[1];
}
//碰撞逻辑
if(!summon.level().isClientSide()) {
@@ -154,6 +156,8 @@ public class InfluxWaver extends SwordItem {
if(target != null && !hitTarget.getUUID().equals(target.getUUID())) return;
if(hitTarget instanceof LivingEntity livingEntity && summon.getOwner() instanceof Player player && FilterUtil.createLivingTargetFilter(player).test(livingEntity)) {
if(livingEntity.hurt(summon.damageSources().playerAttack(player), 12.0f)) {
livingEntity.invulnerableTime = 2;
}
customData.putBoolean("dead", false);
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
return;
@@ -162,7 +166,6 @@ public class InfluxWaver extends SwordItem {
}
}
}
}
@Override
public void onDied(StaticSummon summon) {
@@ -188,7 +191,9 @@ public class InfluxWaver extends SwordItem {
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), player.level());
summon.setOwner(player);
summon.setPos(pos);
float[] xyRot = MathUtil.computeXYRot(MathUtil.toVector3f(dir));
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
summon.setXRot(xyRot[0]);
summon.xRotO = xyRot[0];
summon.setYRot(xyRot[1]);
@@ -137,7 +137,7 @@ public class Meowmere extends SwordItem {
this.checkBeforeTick(summon);
Vec3 motion = summon.getDeltaMovement();
motion = motion.add(0, -GRAVITY, 0);
Vec3 up = MathUtil.toVec3(MathUtil.computeDir(MathUtil.toVector3f(motion))[1]).normalize();
Vec3 up = MathUtil.toVec3(MathUtil.computeCoordinateSystem(motion.toVector3f(), 0)[1]).normalize();
summon.trailPositions.addFirst(summon.position().add(up.scale(0.5)));
summon.trailPositions.addFirst(summon.position().add(up.scale(-0.5)));
@@ -157,6 +157,7 @@ public class Meowmere extends SwordItem {
onDied(summon);
return;
}
livingEntity.invulnerableTime = 2;
}
}
return;
@@ -173,7 +174,7 @@ public class Meowmere extends SwordItem {
if(summon.level().isClientSide()) {
Vec3 dir = summon.getDeltaMovement();
Vector3f[] dirs = MathUtil.computeDir(MathUtil.toVector3f(dir));
Vector3f[] dirs = MathUtil.computeCoordinateSystem(dir.toVector3f(), 0);
int count = (hitBlock + 1) * 15;
double deltaAngle = 360.0 / count;
for(int i = 0;i < count;i++) {
@@ -291,7 +292,8 @@ public class Meowmere extends SwordItem {
summon.setNoGravity(true);
summon.noPhysics = true;
float[] xyRot = MathUtil.computeXYRot(MathUtil.toVector3f(player.getLookAngle()));
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
summon.setXRot(xyRot[0]);
summon.setYRot(xyRot[1]);
summon.setDeltaMovement(player.getLookAngle().normalize().scale(VZ));
@@ -63,7 +63,11 @@ public class Seedler extends SwordItem {
EntityHitResult entityHitResult = CollisionUtil.checkEntityHit(summon, summon.position().add(motion));
if(entityHitResult != null) {
Entity target = entityHitResult.getEntity();
if(summon.getOwner() instanceof Player player && target instanceof LivingEntity livingEntity) livingEntity.hurt(summon.damageSources().playerAttack(player), 7.0f);
if(summon.getOwner() instanceof Player player && target instanceof LivingEntity livingEntity) {
if(livingEntity.hurt(summon.damageSources().playerAttack(player), 7.0f)) {
livingEntity.invulnerableTime = 2;
}
}
onDied(summon);
return;
}
@@ -116,14 +120,14 @@ public class Seedler extends SwordItem {
Vec3 tPos = i < targets.size() ? new Vec3(targets.get(i).getX(), targets.get(i).getEyeY(), targets.get(i).getZ()) : MathUtil.getRandomPosInRadius(summon.position(), 4);
Vec3 dir = new Vec3(tPos.x - summon.getX(), tPos.y - summon.getY(), tPos.z - summon.getZ()).normalize();
Vector3f[] dirs = MathUtil.computeDir(MathUtil.toVector3f(dir));
Vector3f[] dirs = MathUtil.computeCoordinateSystem(dir.toVector3f(), 0);
StaticProjectile proj = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), summon.level());
proj.setOwner(summon.getOwner());
proj.setPos(summon.position());
proj.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.SEEDLER_THORN);
proj.getEntityData().set(StaticProjectile.RENDER_MODE, "item");
proj.getEntityData().set(StaticProjectile.ORIGIN, MathUtil.toVector3f(summon.position()));
proj.getEntityData().set(StaticProjectile.ORIGIN, summon.position().toVector3f());
proj.getEntityData().set(StaticProjectile.DIRECTION, dirs[0]);
proj.getEntityData().set(StaticProjectile.UP, dirs[1]);
proj.getEntityData().set(StaticProjectile.RIGHT, dirs[2]);
@@ -176,7 +180,10 @@ public class Seedler extends SwordItem {
Entity owner = projectile.getOwner();
if(owner == null) return;
if(!FilterUtil.createLivingTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
if(target.hurt(projectile.damageSources().playerAttack(player), 7f)) onDied(projectile);
if(target.hurt(projectile.damageSources().playerAttack(player), 7f)) {
target.invulnerableTime = 2;
onDied(projectile);
}
}
}
}
@@ -209,7 +216,8 @@ public class Seedler extends SwordItem {
summon.setNoGravity(true);
summon.noPhysics = true;
float[] xyRot = MathUtil.computeXYRot(MathUtil.toVector3f(player.getLookAngle()));
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
summon.setXRot(xyRot[0]);
summon.setYRot(xyRot[1]);
summon.setDeltaMovement(player.getLookAngle().normalize().scale(VZ));
@@ -54,7 +54,7 @@ public class StarWrath extends SwordItem {
);
public static final DustParticleOptions PARTICLE2 = new DustParticleOptions(
0.2f, 0.5f, 40, true, new Vector3f[]{
0.1f, 0.5f, 40, true, new Vector3f[]{
new Vector3f(1.0F, 0.0F, 1.0F),
new Vector3f(1.0F, 0.6F, 0.8F),
new Vector3f(0.7F, 0.7F, 0.7F)
@@ -84,7 +84,9 @@ public class StarWrath extends SwordItem {
if(result.getEntity() instanceof LivingEntity target) {
Entity owner = projectile.getOwner();
if(!FilterUtil.createLivingTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
target.hurt(projectile.damageSources().playerAttack(player), 16f);
if(target.hurt(projectile.damageSources().playerAttack(player), 16f)) {
target.invulnerableTime = 2;
}
}
}
}
@@ -97,8 +99,8 @@ public class StarWrath extends SwordItem {
int age = projectile.getEntityData().get(StaticProjectile.AGE);
if(!projectile.level().isClientSide()) {
if(age < targetLifetime + 1) {
EntityHitResult entityHit = CollisionUtil.checkEntityHit(projectile);
if(age < targetLifetime) {
EntityHitResult entityHit = CollisionUtil.checkEntityHit(projectile, 3.0);
if(entityHit != null) {
this.onHitEntity(projectile, entityHit);
}
@@ -160,9 +162,7 @@ public class StarWrath extends SwordItem {
targetPos.z + HIT_OFFSET * (Math.random() * 2 - 1)
);
Vector3f[] dirs = MathUtil.computeDir(
MathUtil.toVector3f(new Vec3(hitPos.x - spawnPos.x, hitPos.y - spawnPos.y, hitPos.z - spawnPos.z))
);
Vector3f[] dirs = MathUtil.computeCoordinateSystem(new Vec3(hitPos.x - spawnPos.x, hitPos.y - spawnPos.y, hitPos.z - spawnPos.z).toVector3f(), 0);
StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level);
projectile.setOwner(player);
@@ -64,7 +64,9 @@ public class Starfury extends SwordItem {
Entity owner = projectile.getOwner();
if(owner == null) return;
if(!FilterUtil.createLivingTargetFilter(owner).test(target) || !(owner instanceof Player player)) return;
target.hurt(projectile.damageSources().playerAttack(player), 8f);
if(target.hurt(projectile.damageSources().playerAttack(player), 8f)) {
target.invulnerableTime = 5;
}
}
}
}
@@ -77,8 +79,8 @@ public class Starfury extends SwordItem {
int age = projectile.getEntityData().get(StaticProjectile.AGE);
if(!projectile.level().isClientSide()) {
if(age < targetLifetime + 1) {
EntityHitResult entityHit = CollisionUtil.checkEntityHit(projectile);
if(age < targetLifetime) {
EntityHitResult entityHit = CollisionUtil.checkEntityHit(projectile, 3.0);
if(entityHit != null) {
this.onHitEntity(projectile, entityHit);
}
@@ -119,9 +121,7 @@ public class Starfury extends SwordItem {
targetPos.z + SPAWN_OFFSET * (Math.random() * 2 - 1)
);
Vector3f[] dirs = MathUtil.computeDir(
MathUtil.toVector3f(new Vec3(targetPos.x - spawnPos.x, targetPos.y - spawnPos.y, targetPos.z - spawnPos.z))
);
Vector3f[] dirs = MathUtil.computeCoordinateSystem(new Vec3(targetPos.x - spawnPos.x, targetPos.y - spawnPos.y, targetPos.z - spawnPos.z).toVector3f(), 0);
StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level);
projectile.setOwner(player);
@@ -142,7 +142,7 @@ public class Starfury extends SwordItem {
projectile.getEntityData().set(StaticProjectile.EXPRESSION_Z, "t*2");
CompoundTag customData = new CompoundTag();
customData.putInt("targetLifetime", (int) Math.round(targetPos.distanceTo(spawnPos) / 2.0D));
customData.putInt("targetLifetime", (int) Math.floor(targetPos.distanceTo(spawnPos) / 2.0D));
projectile.getEntityData().set(StaticProjectile.CUSTOM_DATA, customData);
projectile.setDeltaMovement(MathUtil.toVec3(dirs[0]));
@@ -12,6 +12,7 @@ import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors;
import com.lzxnone.terraria.item.IItemWaveBehavior;
import com.lzxnone.terraria.network.payload.SwordBeamPayload;
import com.lzxnone.terraria.particle.DustParticleOptions;
import com.lzxnone.terraria.particle.ModParticles;
import com.lzxnone.terraria.utils.*;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
@@ -23,6 +24,7 @@ import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.LivingEntity;
@@ -61,7 +63,8 @@ public class TerraBlade extends SwordItem {
public static final CompoundTag BEAM_DATA = Util.make(new CompoundTag(), tag -> {
tag.putString("behavior", "terra_blade");
tag.putInt("cooldown", 8);
tag.putInt("lifetime", 5);
tag.putInt("cooldown", 5);
tag.putFloat("color0R", 0.173f);
tag.putFloat("color0G", 0.482f);
tag.putFloat("color0B", 0.796f);
@@ -107,6 +110,7 @@ public class TerraBlade extends SwordItem {
int count = custom_data.getInt("hitEntityCount");
if(count < MAX_HIT_ENTITY_COUNT) {
if(target.hurt(beam.level().damageSources().playerAttack(player), 11.0f)) {
target.invulnerableTime = 20;
count++;
custom_data.putInt("hitEntityCount", count);
beam.getEntityData().set(SwordBeam.CUSTOM_DATA, custom_data);
@@ -136,7 +140,7 @@ public class TerraBlade extends SwordItem {
public static final float FADE_IN = 0.33f;
public static final float FADE_OUT = 0.67f;
public static final double SPEED = 1.5;
public static final double SPEED = 2;
public static final float DAMAGE = 11;
public static final float DAMAGE_PUNISHMENT = 0.75f;
@@ -168,11 +172,22 @@ public class TerraBlade extends SwordItem {
if(alpha < 0.01f) return;
Quaternionf rotationX = new Quaternionf().fromAxisAngleRad(MathUtil.toVector3f(summon.getLookAngle()), (float) Math.toRadians(summon.getEntityData().get(StaticSummon.RZP)));
Vector3f[] dirs = MathUtil.computeDir(
MathUtil.toVector3f(summon.getLookAngle()),
MathUtil.computeDir(MathUtil.toVector3f(summon.getLookAngle()))[2].rotate(rotationX)
);
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};
poseStack.pushPose();
@@ -187,6 +202,7 @@ public class TerraBlade extends SwordItem {
COLOR0.x(), COLOR0.y(), COLOR0.z(), alpha, halfWidth, halfHeight, 0f, 0, -0.01f);
poseStack.popPose();
//中间
poseStack.pushPose();
this.applyTranslate(poseStack, dirs[0], dirs[2], 90, SwordBeam.DIST);
@@ -196,6 +212,7 @@ public class TerraBlade extends SwordItem {
poseStack.popPose();
//右边
poseStack.pushPose();
this.applyTranslate(poseStack, dirs[0], dirs[2], 108, SwordBeam.DIST);
this.applyRotate(summon, poseStack, dirs[0], dirs[1], -9 * (1.0f - progress));
@@ -239,6 +256,7 @@ public class TerraBlade extends SwordItem {
}
poseStack.popPose();
float sparkleAlpha;
if(progress < FADE_IN) {
sparkleAlpha = 0;
@@ -322,14 +340,15 @@ public class TerraBlade extends SwordItem {
}
public void applyRotate(StaticSummon summon, PoseStack poseStack, Vector3f dir, Vector3f up, double angle) {
Quaternionf rotation = new Quaternionf().fromAxisAngleRad(up, (float) Math.toRadians(angle));
Quaternionf rotation = new Quaternionf()
.fromAxisAngleRad(up, (float) Math.toRadians(angle))
.fromAxisAngleRad(dir, (float) Math.toRadians(Math.abs(dir.y) > 0.999 ? 0 : summon.getEntityData().get(StaticSummon.RZP)));
poseStack.mulPose(rotation);
float[] xyRot = MathUtil.computeXYRot(dir);
float[] xyRot = MathUtil.computeXYRot(dir, up);
poseStack.mulPose(Axis.YP.rotationDegrees(-xyRot[1]));
poseStack.mulPose(Axis.XP.rotationDegrees(xyRot[0]));
poseStack.mulPose(Axis.ZP.rotationDegrees(summon.getEntityData().get(StaticSummon.RZP)));
poseStack.mulPose(Axis.XP.rotationDegrees(-90.0F));
poseStack.mulPose(Axis.ZP.rotationDegrees(-90.0F));
}
@@ -341,7 +360,7 @@ public class TerraBlade extends SwordItem {
cos * right.x + sin * dir.x,
cos * right.y + sin * dir.y,
cos * right.z + sin * dir.z
);
).normalize();
poseStack.translate(current.x * dist, current.y * dist, current.z * dist);
}
@@ -380,7 +399,7 @@ public class TerraBlade extends SwordItem {
summon.setDeltaMovement(summon.getLookAngle().normalize().scale(SPEED));
}
}else {
summon.setDeltaMovement(summon.getLookAngle().normalize().scale(0.5));
summon.setDeltaMovement(summon.getLookAngle().normalize().scale(0.1));
return;
}
@@ -396,12 +415,16 @@ public class TerraBlade extends SwordItem {
//碰撞计算
if(!summon.level().isClientSide() && customData.contains("hitCount") && summon.getOwner() instanceof Player player) {
int count = customData.getInt("hitCount");
LzxnoneTerraria.LOGGER.info("11w111");
List<LivingEntity> targets = summon.level().getEntitiesOfClass(LivingEntity.class, summon.getBoundingBox(), FilterUtil.createTargetFilter(summon, summon.getOwner()));
for(LivingEntity target : targets) {
if(target.hurt(summon.damageSources().playerAttack(player), DAMAGE * (float) Math.pow(DAMAGE_PUNISHMENT, count))) {
count++;
//粒子效果
ParticleUtil.addParticles(
(ServerLevel) summon.level(), ModParticles.TERRA_BEAM_HIT_PARTICLE.get(),
new Vec3(target.getX(), target.getY() + target.getBbHeight() / 2.0, target.getZ()), new Vec3(0, 0, 0),
0, 1
);
target.invulnerableTime = 12;
}
}
if(!targets.isEmpty()) customData.putInt("hitCount", count);
@@ -421,15 +444,20 @@ public class TerraBlade extends SwordItem {
//粒子
if(summon.level().isClientSide() && summon.tickCount % 4 == 0) {
Quaternionf rotationX = new Quaternionf().fromAxisAngleRad(MathUtil.toVector3f(summon.getLookAngle()), (float) Math.toRadians(summon.getEntityData().get(StaticSummon.RZP)));
Vector3f[] dirs = MathUtil.computeDir(
MathUtil.toVector3f(summon.getLookAngle()),
MathUtil.computeDir(MathUtil.toVector3f(summon.getLookAngle()))[2].rotate(rotationX)
Vec3 dir = new Vec3(
customData.contains("dirX") ? customData.getFloat("dirX") : 0,
customData.contains("dirY") ? customData.getFloat("dirY") : 0,
customData.contains("dirZ") ? customData.getFloat("dirZ") : 0
);
Vec3 right = MathUtil.toVec3(dirs[2]).normalize();
Vec3 speed = MathUtil.toVec3(dirs[0]).normalize().scale(summon.getDeltaMovement().length() / 2);
Vec3 right = new Vec3(
customData.contains("rightX") ? customData.getFloat("rightX") : 0,
customData.contains("rightY") ? customData.getFloat("rightY") : 0,
customData.contains("rightZ") ? customData.getFloat("rightZ") : 0
);
Vec3 speed = dir.scale(summon.getDeltaMovement().length() / 4);
for(int i = 0;i < 5;i++) {
Vec3 delta = right.scale((Math.random() - 0.5) * 4);
Vec3 delta = right.scale((Math.random() - 0.5) * 6);
ParticleUtil.addParticle(
summon.level(), PARTICLE,
summon.position().add(delta), 0.0,
@@ -439,7 +467,6 @@ public class TerraBlade extends SwordItem {
}
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
}
};
@@ -449,14 +476,15 @@ public class TerraBlade extends SwordItem {
Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ());
summon.setPos(pos);
float[] xyRot = MathUtil.computeXYRot(MathUtil.toVector3f(player.getLookAngle()));
int randomAngle = (int) ((Math.random() * 2 - 1) * 60);
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
dirs = MathUtil.rotateCoordinateSystem(dirs[0], dirs[2], randomAngle);
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
summon.setXRot(xyRot[0]);
summon.xRotO = xyRot[0];
summon.setYRot(xyRot[1]);
summon.yRotO = xyRot[1];
int randomAngle = (int) ((Math.random() * 2 - 1) * 60);
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.TERRA_BLADE_BEAM);
summon.getEntityData().set(StaticSummon.RENDER_MODE, "custom");
summon.getEntityData().set(StaticSummon.LIFETIME, 40);
@@ -468,9 +496,9 @@ public class TerraBlade extends SwordItem {
CompoundTag customData = new CompoundTag();
Quaternionf rotation = new Quaternionf()
.fromAxisAngleRad(dirs[0], (float) Math.toRadians(Math.abs(dirs[0].y) > 0.999 ? 0 : randomAngle))
.rotateY((float) Math.toRadians(-xyRot[1]))
.rotateX((float) Math.toRadians(xyRot[0]))
.rotateZ((float) Math.toRadians(randomAngle))
.rotateX((float) Math.toRadians(-90.0))
.rotateZ((float) Math.toRadians(-90.0));
@@ -486,6 +514,15 @@ public class TerraBlade extends SwordItem {
customData.putFloat("extX", extX);
customData.putFloat("extY", extY);
customData.putFloat("extZ", extZ);
customData.putFloat("dirX", dirs[0].x);
customData.putFloat("dirY", dirs[0].y);
customData.putFloat("dirZ", dirs[0].z);
customData.putFloat("upX", dirs[1].x);
customData.putFloat("upY", dirs[1].y);
customData.putFloat("upZ", dirs[1].z);
customData.putFloat("rightX", dirs[2].x);
customData.putFloat("rightY", dirs[2].y);
customData.putFloat("rightZ", dirs[2].z);
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
summon.setDeltaMovement(player.getLookAngle().normalize().scale(SPEED));
@@ -502,7 +539,6 @@ public class TerraBlade extends SwordItem {
if(item instanceof TerraBlade && !player.getCooldowns().isOnCooldown(item)) {
PacketDistributor.sendToServer(new SwordBeamPayload("terra_blade", BEAM_DATA));
SoundUtil.playClientSound(player, ModSounds.WAVE.get());
summon(player);
}
}
public void onAttackEntity(AttackEntityEvent event) {
@@ -513,7 +549,6 @@ public class TerraBlade extends SwordItem {
if(item instanceof TerraBlade && !player.getCooldowns().isOnCooldown(item)) {
if(!player.level().isClientSide()) {
SwordBeamBehaviors.getBehavior("terra_blade").generate(player, BEAM_DATA);
summon(player);
}else {
SoundUtil.playClientSound(player, ModSounds.WAVE.get());
}
@@ -110,6 +110,7 @@ public class TheHorsemansBlade extends SwordItem {
int count = custom_data.getInt("hitEntityCount");
if(count < MAX_HIT_ENTITY_COUNT) {
if(target.hurt(beam.level().damageSources().playerAttack(player), 15.0f)) {
target.invulnerableTime = 20;
count++;
custom_data.putInt("hitEntityCount", count);
beam.getEntityData().set(SwordBeam.CUSTOM_DATA, custom_data);
@@ -249,7 +250,11 @@ public class TheHorsemansBlade extends SwordItem {
if(!hitEntities.isEmpty()) {
for(Entity hitEntity : hitEntities) {
if(target != null && hitEntity.getUUID() == target.getUUID()) continue;
if(summon.getOwner() instanceof Player player) hitEntity.hurt(summon.damageSources().playerAttack(player), DAMAGE);
if(summon.getOwner() instanceof Player player) {
if(hitEntity.hurt(summon.damageSources().playerAttack(player), DAMAGE)) {
hitEntity.invulnerableTime = 2;
}
}
}
}
}else {
@@ -0,0 +1,25 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.LzxnoneTerraria;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.component.ItemAttributeModifiers;
public class Zenith extends SwordItem {
public Zenith() {
super(Tiers.DIAMOND, new Item.Properties().attributes(ItemAttributeModifiers.builder()
.add(Attributes.ATTACK_DAMAGE,
new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_damage"), 20, AttributeModifier.Operation.ADD_VALUE),
EquipmentSlotGroup.MAINHAND)
.add(Attributes.ATTACK_SPEED,
new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_speed"), -2.4, AttributeModifier.Operation.ADD_VALUE),
EquipmentSlotGroup.MAINHAND)
.build()
));
}
}
@@ -71,4 +71,6 @@ public class ModParticles {
PARTICLE_TYPES.register("seedler_thorn_particle", () -> new SimpleParticleType(true));
public static final Supplier<SimpleParticleType> INFLUX_WAVER_DROP_PARTICLE =
PARTICLE_TYPES.register("influx_waver_drop_particle", () -> new SimpleParticleType(true));
public static final Supplier<SimpleParticleType> TERRA_BEAM_HIT_PARTICLE =
PARTICLE_TYPES.register("terra_beam_hit_particle", () -> new SimpleParticleType(true));
}
@@ -5,6 +5,7 @@ import net.minecraft.client.particle.*;
import net.minecraft.core.particles.SimpleParticleType;
public class SeedlerThornParticle extends TextureSheetParticle {
private final SpriteSet spriteSet;
private final float baseSize;
protected SeedlerThornParticle(ClientLevel level, double x, double y, double z,
@@ -23,7 +24,8 @@ public class SeedlerThornParticle extends TextureSheetParticle {
this.lifetime = 25;
this.pickSprite(spriteSet);
this.spriteSet = spriteSet;
this.setSpriteFromAge(this.spriteSet);
}
@Override
@@ -34,6 +36,8 @@ public class SeedlerThornParticle extends TextureSheetParticle {
this.quadSize = this.baseSize * (1.0F - lifeRatio);
this.alpha = 1.0F - lifeRatio;
this.setSpriteFromAge(spriteSet);
}
@Override
@@ -0,0 +1,99 @@
package com.lzxnone.terraria.particle;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.*;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.core.particles.SimpleParticleType;
public class TerraBeamHitParticle extends TextureSheetParticle {
private final float rotSpeed;
private final float baseSize;
private final SpriteSet spriteSet;
private final Float INCREASE = 0.5f;
private final Float MUL = 5.0f;
protected TerraBeamHitParticle(ClientLevel level, double x, double y, double z,
double xSpeed, double ySpeed, double zSpeed, SpriteSet spriteSet) {
super(level, x, y, z, xSpeed, ySpeed, zSpeed);
this.hasPhysics = false;
this.friction = 0.9F;
this.gravity = 0.0F;
this.xd = xSpeed;
this.yd = ySpeed;
this.zd = zSpeed;
this.baseSize = 0.2f + (this.random.nextFloat() * 0.2f);
this.quadSize = baseSize;
this.roll = this.random.nextFloat() * ((float)Math.PI * 2F);
this.oRoll = this.roll;
this.rotSpeed = 0;
this.lifetime = 15;
this.spriteSet = spriteSet;
this.setSpriteFromAge(spriteSet);
}
@Override
public void tick() {
super.tick();
this.oRoll = this.roll;
this.roll += this.rotSpeed;
this.setSpriteFromAge(this.spriteSet);
float lifeRatio = (float) this.age / (float) this.lifetime;
if(lifeRatio <= INCREASE) {
// [0, INCREASE] 从 0 线性增长到 baseSize * MUL
this.quadSize = this.baseSize * MUL * (lifeRatio / INCREASE);
this.alpha = 1.0F;
}else {
// [INCREASE, 1] 从 baseSize * MUL 线性缩小到 0
this.quadSize = this.baseSize * MUL * (1.0f - lifeRatio) / (1.0f - INCREASE);
this.alpha = 1.0f - (lifeRatio - 0.5f) / 0.5f;
}
}
@Override
public void render(VertexConsumer buffer, Camera camera, float partialTick) {
if(this.alpha <= 0.01F) return;
float lifeRatio = (float) this.age / (float) this.lifetime - 0.5f;
for(int i = 0;i < 10 + (int) lifeRatio * 5;i++) {
super.render(buffer, camera, partialTick);
}
}
@Override
public int getLightColor(float partialTick) {
return LightTexture.FULL_BRIGHT;
}
@Override
public ParticleRenderType getRenderType() {
return ModParticleRenderTypes.TRANSLUCENT_EMISSIVE;
}
public static class Provider implements ParticleProvider<SimpleParticleType> {
private final SpriteSet spriteSet;
public Provider(SpriteSet spriteSet) {
this.spriteSet = spriteSet;
}
@Override
public Particle createParticle(SimpleParticleType type, ClientLevel level,
double x, double y, double z,
double xSpeed, double ySpeed, double zSpeed) {
return new TerraBeamHitParticle(level, x, y, z, xSpeed, ySpeed, zSpeed, this.spriteSet);
}
}
}
@@ -1,38 +1,67 @@
package com.lzxnone.terraria.utils;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ProjectileUtil;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.*;
import org.joml.Quaternionf;
import org.joml.Vector3f;
public class MathUtil {
public static Vector3f[] computeDir(Vector3f tempDir) {
Vector3f dir = new Vector3f(tempDir.x, tempDir.y, tempDir.z).normalize();
// 方向接近垂直时用 X 轴,否则用 Y 轴做参考向量
Vector3f ref = Math.abs(dir.y) > 0.999f ? new Vector3f(1, 0, 0) : new Vector3f(0, 1, 0);
Vector3f right = new Vector3f();
ref.cross(dir, right).normalize();
public static Vector3f[] computeCoordinateSystem(Vector3f lookAngle, double yRot) {
Vector3f dir = lookAngle.normalize();
Vector3f up = new Vector3f();
Vector3f right = new Vector3f();
if(Math.abs(dir.y) > 0.999f) {
float yawRad = (float) Math.toRadians(yRot);
Vector3f facing = new Vector3f(-Mth.sin(yawRad), 0, Mth.cos(yawRad));
up.set(dir.y > 0 ? facing.negate() : facing);
up.cross(dir, right).normalize();
dir.cross(right, up).normalize();
}else {
Vector3f ref = new Vector3f(0, 1, 0);
ref.cross(dir, right).normalize();
dir.cross(right, up).normalize();
}
return new Vector3f[]{dir, up, right};
}
public static Vector3f[] computeDir(Vector3f tempDir, Vector3f tempRight) {
Vector3f dir = new Vector3f(tempDir.x, tempDir.y, tempDir.z).normalize();
Vector3f right = new Vector3f(tempRight.x, tempRight.y, tempRight.z).normalize();
//计算实体的局部坐标系(z轴为视线前方),当抬头时会出错
public static Vector3f[] computeCoordinateSystem(Entity entity) {
return computeCoordinateSystem(entity.getLookAngle().toVector3f(), entity.getYRot());
}
//让右轴绕方向轴旋转
public static Vector3f[] rotateCoordinateSystem(Vector3f dir, Vector3f right, float angle) {
Quaternionf rotation = new Quaternionf().fromAxisAngleRad(dir, (float) Math.toRadians(angle));
right = right.rotate(rotation);
Vector3f up = new Vector3f();
dir.cross(right, up).normalize();
return new Vector3f[]{dir.normalize(), up, right.normalize()};
}
up.cross(dir, right).normalize();
return new Vector3f[]{dir, up, right};
public static float[] computeXYRot(Vector3f dir, Vector3f up) {
if(Math.abs(dir.y) > 0.999) {
if(dir.y > 0) {
return new float[]{-90, (float) (Math.atan2(up.x(), -up.z()) * (180.0 / Math.PI))};
}else {
return new float[]{90, (float) (Math.atan2(-up.x(), up.z()) * (180.0 / Math.PI))};
}
}
float xzLen = (float) Math.sqrt(dir.x() * dir.x() + dir.z() * dir.z());
return new float[]{
(float) (Math.atan2(-dir.y(), xzLen) * (180.0 / Math.PI)),
(float) (Math.atan2(-dir.x(), dir.z()) * (180.0 / Math.PI))
};
}
public static float[] computeXYRot(Vector3f dir) {
@@ -0,0 +1,8 @@
{
"textures": [
"lzxnoneterraria:terra_beam_hit_particle0",
"lzxnoneterraria:terra_beam_hit_particle1",
"lzxnoneterraria:terra_beam_hit_particle2",
"lzxnoneterraria:terra_beam_hit_particle3"
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 B