This commit is contained in:
LZX committed 2026-08-14 19:56:39 +08:00
1 parent 078c05cc0e
commit 071d422f82
22 files changed
+368 -77

No files matched your search

@@ -31,6 +31,10 @@ public class ModSounds {
SOUND_EVENTS.register("magic_shoot", SOUND_EVENTS.register("magic_shoot",
() -> SoundEvent.createVariableRangeEvent( () -> SoundEvent.createVariableRangeEvent(
ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "magic_shoot"))); ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "magic_shoot")));
public static final Supplier<SoundEvent> MAGIC_SHOOT2 =
SOUND_EVENTS.register("magic_shoot2",
() -> SoundEvent.createVariableRangeEvent(
ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "magic_shoot2")));
public static final Supplier<SoundEvent> BUBBLE = public static final Supplier<SoundEvent> BUBBLE =
SOUND_EVENTS.register("bubble", SOUND_EVENTS.register("bubble",
() -> SoundEvent.createVariableRangeEvent( () -> SoundEvent.createVariableRangeEvent(
@@ -7,6 +7,7 @@ import com.lzxnone.terraria.client.item.ranged.ClientBulletAmmo;
import com.lzxnone.terraria.client.item.magic.ClientBetsysWrath; import com.lzxnone.terraria.client.item.magic.ClientBetsysWrath;
import com.lzxnone.terraria.client.item.magic.ClientBubbleGun; import com.lzxnone.terraria.client.item.magic.ClientBubbleGun;
import com.lzxnone.terraria.client.item.magic.ClientLastPrism; import com.lzxnone.terraria.client.item.magic.ClientLastPrism;
import com.lzxnone.terraria.client.item.magic.ClientNebulaBlaze;
import com.lzxnone.terraria.client.item.melee.ClientDevilsDevastation; import com.lzxnone.terraria.client.item.melee.ClientDevilsDevastation;
import com.lzxnone.terraria.client.item.melee.ClientFirstFractal; import com.lzxnone.terraria.client.item.melee.ClientFirstFractal;
import com.lzxnone.terraria.client.item.melee.ClientLightsBane; import com.lzxnone.terraria.client.item.melee.ClientLightsBane;
@@ -57,6 +58,8 @@ public class ClientStaticSummonRenderBehaviors {
BEHAVIORS.put(StaticSummonBehaviors.LAST_PRISM_TRI, ClientLastPrism.SUMMON_BEHAVIOR); BEHAVIORS.put(StaticSummonBehaviors.LAST_PRISM_TRI, ClientLastPrism.SUMMON_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.LAST_PRISM_BEAM, ClientLastPrism.SUMMON_BEHAVIOR2); BEHAVIORS.put(StaticSummonBehaviors.LAST_PRISM_BEAM, ClientLastPrism.SUMMON_BEHAVIOR2);
BEHAVIORS.put(StaticSummonBehaviors.BETSY_WRATH, ClientBetsysWrath.SUMMON_BEHAVIOR); BEHAVIORS.put(StaticSummonBehaviors.BETSY_WRATH, ClientBetsysWrath.SUMMON_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.NEBULA_BLAZE, ClientNebulaBlaze.SUMMON_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.NEBULA_BLAZE_EXPLOSIVE, ClientNebulaBlaze.SUMMON_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.TERRAPRISMA, ClientTerraprisma.SUMMON_BEHAVIOR); BEHAVIORS.put(StaticSummonBehaviors.TERRAPRISMA, ClientTerraprisma.SUMMON_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.POSSESSION, ClientWhip.SUMMON_BEHAVIOR); BEHAVIORS.put(StaticSummonBehaviors.POSSESSION, ClientWhip.SUMMON_BEHAVIOR);
BEHAVIORS.put(StaticSummonBehaviors.POSSESSION_VISION, DEFAULT_BEHAVIOR); BEHAVIORS.put(StaticSummonBehaviors.POSSESSION_VISION, DEFAULT_BEHAVIOR);
@@ -0,0 +1,118 @@
package com.lzxnone.terraria.client.item.magic;
import com.lzxnone.terraria.client.entity.summon.IStaticSummonRenderBehavior;
import com.lzxnone.terraria.entity.ModRenderTypes;
import com.lzxnone.terraria.entity.summon.StaticSummon;
import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors;
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.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
public class ClientNebulaBlaze {
private static final ResourceLocation[] RES = {
ResourceLocation.parse("lzxnoneterraria:textures/vfx/nebula_blaze_projectile0.png"),
ResourceLocation.parse("lzxnoneterraria:textures/vfx/nebula_blaze_projectile1.png"),
ResourceLocation.parse("lzxnoneterraria:textures/vfx/nebula_blaze_projectile2.png"),
ResourceLocation.parse("lzxnoneterraria:textures/vfx/nebula_blaze_projectile3.png")
};
private static final ResourceLocation[] EXPLOSIVE_RES = {
ResourceLocation.parse("lzxnoneterraria:textures/vfx/nebula_blaze_ex_projectile0.png"),
ResourceLocation.parse("lzxnoneterraria:textures/vfx/nebula_blaze_ex_projectile1.png"),
ResourceLocation.parse("lzxnoneterraria:textures/vfx/nebula_blaze_ex_projectile2.png"),
ResourceLocation.parse("lzxnoneterraria:textures/vfx/nebula_blaze_ex_projectile3.png")
};
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;
boolean explosive = summon.getEntityData().get(StaticSummon.BEHAVIOR).equals(StaticSummonBehaviors.NEBULA_BLAZE_EXPLOSIVE);
ResourceLocation[] frames = explosive ? EXPLOSIVE_RES : RES;
float age = summon.getEntityData().get(StaticSummon.AGE) + partialTick;
int frame = Mth.floor(age * 0.625F) % frames.length;
float halfSize = explosive ? 0.55F : 0.42F;
poseStack.pushPose();
poseStack.mulPose(Minecraft.getInstance().getEntityRenderDispatcher().cameraOrientation());
poseStack.mulPose(Axis.ZP.rotationDegrees(age * 18.0F));
poseStack.scale(
summon.getEntityData().get(StaticSummon.SCALE_X),
summon.getEntityData().get(StaticSummon.SCALE_Y),
summon.getEntityData().get(StaticSummon.SCALE_Z)
);
VertexConsumer consumer = bufferSource.getBuffer(ModRenderTypes.entityAdditiveEmissive(frames[frame]));
consumer.addVertex(poseStack.last().pose(), -halfSize, -halfSize, 0.0F)
.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);
consumer.addVertex(poseStack.last().pose(), halfSize, -halfSize, 0.0F)
.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);
consumer.addVertex(poseStack.last().pose(), halfSize, halfSize, 0.0F)
.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);
consumer.addVertex(poseStack.last().pose(), -halfSize, halfSize, 0.0F)
.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);
poseStack.popPose();
}
};
public static void renderHandProjectile(MultiBufferSource bufferSource, PoseStack poseStack, Entity entity) {
float age = entity.tickCount + Minecraft.getInstance().getTimer().getGameTimeDeltaPartialTick(false);
int frame = Mth.floor(age * 0.625F) % RES.length;
float halfSize = 0.35F;
poseStack.pushPose();
poseStack.translate(0.0F, 0.0F, 0.08F);
poseStack.mulPose(Minecraft.getInstance().getEntityRenderDispatcher().cameraOrientation());
poseStack.mulPose(Axis.ZP.rotationDegrees(age * 18.0F));
VertexConsumer consumer = bufferSource.getBuffer(ModRenderTypes.entityAdditiveEmissive(RES[frame]));
consumer.addVertex(poseStack.last().pose(), -halfSize, -halfSize, 0.0F)
.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);
consumer.addVertex(poseStack.last().pose(), halfSize, -halfSize, 0.0F)
.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);
consumer.addVertex(poseStack.last().pose(), halfSize, halfSize, 0.0F)
.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);
consumer.addVertex(poseStack.last().pose(), -halfSize, halfSize, 0.0F)
.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);
poseStack.popPose();
}
}
@@ -41,7 +41,6 @@ import net.minecraft.world.phys.Vec3;
import org.joml.Vector3f; import org.joml.Vector3f;
public class LunarFlare extends MagicWeapon { public class LunarFlare extends MagicWeapon {
public static final double HITBOX_INFLATE = 0.75D;
public static final double SPAWN_HEIGHT = 20.0D; public static final double SPAWN_HEIGHT = 20.0D;
public static final double DELTA_HEIGHT = 10.0D; public static final double DELTA_HEIGHT = 10.0D;
public static final double SPAWN_OFFSET = 10.0D; public static final double SPAWN_OFFSET = 10.0D;
@@ -115,7 +114,7 @@ public class LunarFlare extends MagicWeapon {
return; return;
} }
EntityHitResult entityHitResult = CollisionUtil.checkEntityHit(summon, nextPos, HITBOX_INFLATE); EntityHitResult entityHitResult = CollisionUtil.checkEntityHit(summon, nextPos, 0.75);
if(entityHitResult != null) { if(entityHitResult != null) {
onDied(summon); onDied(summon);
return; return;
@@ -7,16 +7,14 @@ 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.weapon.MagicWeapon; import com.lzxnone.terraria.item.weapon.MagicWeapon;
import com.lzxnone.terraria.particle.CircleParticleOptions;
import com.lzxnone.terraria.particle.DustParticleOptions;
import com.lzxnone.terraria.ui.config.ConfigListItem; import com.lzxnone.terraria.ui.config.ConfigListItem;
import com.lzxnone.terraria.ui.config.IConfigData; import com.lzxnone.terraria.ui.config.IConfigData;
import com.lzxnone.terraria.ui.config.struct.ConfigDouble; import com.lzxnone.terraria.ui.config.struct.ConfigDouble;
import com.lzxnone.terraria.ui.config.struct.ConfigFloat; import com.lzxnone.terraria.ui.config.struct.ConfigFloat;
import com.lzxnone.terraria.ui.config.struct.ConfigStruct; import com.lzxnone.terraria.ui.config.struct.ConfigStruct;
import com.lzxnone.terraria.utils.CollisionUtil; import com.lzxnone.terraria.utils.*;
import com.lzxnone.terraria.utils.DamageUtil;
import com.lzxnone.terraria.utils.FilterUtil;
import com.lzxnone.terraria.utils.MathUtil;
import com.lzxnone.terraria.utils.SearchUtil;
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;
@@ -30,6 +28,7 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Rarity; import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.Tiers; import net.minecraft.world.item.Tiers;
import net.minecraft.world.level.ClipContext;
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.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
@@ -40,8 +39,7 @@ import org.joml.Vector3f;
import java.util.List; import java.util.List;
public class NebulaBlaze extends MagicWeapon { public class NebulaBlaze extends MagicWeapon {
public static final Vector3f OFFSET = new Vector3f(-0.25F, -0.1F, 1.2F); public static final Vector3f OFFSET = new Vector3f(-0.5F, -0.1F, 1.2F);
public static final double HITBOX_INFLATE = 0.35D;
public static final String TARGET_UUID_KEY = "target"; public static final String TARGET_UUID_KEY = "target";
public static final ConfigFloat DAMAGE = new ConfigFloat("weapon.nebula_blaze.damage", "nebula_blaze_damage", 10.0F, 0.0F, 8388600.0F); public static final ConfigFloat DAMAGE = new ConfigFloat("weapon.nebula_blaze.damage", "nebula_blaze_damage", 10.0F, 0.0F, 8388600.0F);
@@ -78,16 +76,35 @@ public class NebulaBlaze extends MagicWeapon {
CONFIG_DATA CONFIG_DATA
); );
public static final CircleParticleOptions TRAIL_PARTICLE = new CircleParticleOptions(0.075F, 16, new Vector3f(1.0F, 0.18F, 0.72F));
public static final CircleParticleOptions EXPLOSIVE_TRAIL_PARTICLE = new CircleParticleOptions(0.085F, 16, new Vector3f(0.24F, 0.7F, 1.0F));
public static final DustParticleOptions DUST_PARTICLE = new DustParticleOptions(
0.1F, 0.35F, 18, true,
new Vector3f[] {new Vector3f(1.0F, 0.16F, 0.62F), new Vector3f(0.86F, 0.08F, 1.0F)}
);
public static final DustParticleOptions EXPLOSIVE_DUST_PARTICLE = new DustParticleOptions(
0.15F, 0.35F, 18, true,
new Vector3f[] {new Vector3f(0.12F, 0.86F, 1.0F), new Vector3f(0.22F, 0.25F, 1.0F)}
);
public static final DustParticleOptions DEATH_PARTICLE = new DustParticleOptions(
0.15F, 0.45F, 32, true,
new Vector3f[] {new Vector3f(1.0F, 0.12F, 0.58F), new Vector3f(0.95F, 0.04F, 1.0F)}
);
public static final DustParticleOptions EXPLOSIVE_DEATH_PARTICLE = new DustParticleOptions(
0.3F, 0.5F, 36, true,
new Vector3f[] {new Vector3f(0.0F, 0.95F, 1.0F), new Vector3f(0.2F, 0.35F, 1.0F)}
);
public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() { public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() {
@Override @Override
public void tick(StaticSummon summon) { public void tick(StaticSummon summon) {
checkBeforeTick(summon); checkBeforeTick(summon);
tickProjectile(summon, SPEED.get(), TARGET_RANGE.get(), DAMAGE.get()); tickProjectile(summon, SPEED.get(), TARGET_RANGE.get(), DAMAGE.get(), false);
} }
@Override @Override
public void onDied(StaticSummon summon) { public void onDied(StaticSummon summon) {
explode(summon, DAMAGE.get()); explode(summon, DAMAGE.get(), false);
} }
}; };
@@ -95,12 +112,12 @@ public class NebulaBlaze extends MagicWeapon {
@Override @Override
public void tick(StaticSummon summon) { public void tick(StaticSummon summon) {
checkBeforeTick(summon); checkBeforeTick(summon);
tickProjectile(summon, EXPLOSIVE_SPEED.get(), EXPLOSIVE_TARGET_RANGE.get(), EXPLOSIVE_DAMAGE.get()); tickProjectile(summon, EXPLOSIVE_SPEED.get(), EXPLOSIVE_TARGET_RANGE.get(), EXPLOSIVE_DAMAGE.get(), true);
} }
@Override @Override
public void onDied(StaticSummon summon) { public void onDied(StaticSummon summon) {
explode(summon, EXPLOSIVE_DAMAGE.get()); explode(summon, EXPLOSIVE_DAMAGE.get(), true);
} }
}; };
@@ -128,7 +145,7 @@ public class NebulaBlaze extends MagicWeapon {
protected void shoot(Level level, Player player, InteractionHand hand, ItemStack stack) { protected void shoot(Level level, Player player, InteractionHand hand, ItemStack stack) {
if(level.isClientSide()) return; if(level.isClientSide()) return;
player.playNotifySound(ModSounds.MAGIC_SHOOT.get(), SoundSource.PLAYERS, 4.0F, 1.0F); player.playNotifySound(ModSounds.MAGIC_SHOOT2.get(), SoundSource.PLAYERS, 4.0F, 1.0F);
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player); Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
Vector3f offset = new Vector3f( Vector3f offset = new Vector3f(
@@ -151,7 +168,17 @@ public class NebulaBlaze extends MagicWeapon {
summon.setDeltaMovement(direction.scale(explosive ? EXPLOSIVE_SPEED.get() : SPEED.get())); summon.setDeltaMovement(direction.scale(explosive ? EXPLOSIVE_SPEED.get() : SPEED.get()));
summon.getEntityData().set(StaticSummon.STACK_SOURCE, stack.copy()); summon.getEntityData().set(StaticSummon.STACK_SOURCE, stack.copy());
summon.getEntityData().set(StaticSummon.BEHAVIOR, explosive ? StaticSummonBehaviors.NEBULA_BLAZE_EXPLOSIVE : StaticSummonBehaviors.NEBULA_BLAZE); summon.getEntityData().set(StaticSummon.BEHAVIOR, explosive ? StaticSummonBehaviors.NEBULA_BLAZE_EXPLOSIVE : StaticSummonBehaviors.NEBULA_BLAZE);
summon.getEntityData().set(StaticSummon.RENDER_MODE, "custom");
summon.getEntityData().set(StaticSummon.LIFETIME, 100); summon.getEntityData().set(StaticSummon.LIFETIME, 100);
if(explosive) {
summon.getEntityData().set(StaticSummon.SCALE_X, 2.0f);
summon.getEntityData().set(StaticSummon.SCALE_Y, 2.0f);
summon.getEntityData().set(StaticSummon.SCALE_Z, 2.0f);
}else {
summon.getEntityData().set(StaticSummon.SCALE_X, 1.5f);
summon.getEntityData().set(StaticSummon.SCALE_Y, 1.5f);
summon.getEntityData().set(StaticSummon.SCALE_Z, 1.5f);
}
summon.getEntityData().set(StaticSummon.GLOW, true); summon.getEntityData().set(StaticSummon.GLOW, true);
summon.setNoGravity(true); summon.setNoGravity(true);
summon.noPhysics = true; summon.noPhysics = true;
@@ -164,7 +191,7 @@ public class NebulaBlaze extends MagicWeapon {
level.addFreshEntity(summon); level.addFreshEntity(summon);
} }
private static void tickProjectile(StaticSummon summon, double speed, double targetRange, float damage) { private static void tickProjectile(StaticSummon summon, double speed, double targetRange, float damage, boolean explosive) {
Vec3 direction = summon.getDeltaMovement(); Vec3 direction = summon.getDeltaMovement();
if(direction.lengthSqr() < 1.0E-7D) direction = summon.getLookAngle(); if(direction.lengthSqr() < 1.0E-7D) direction = summon.getLookAngle();
if(direction.lengthSqr() < 1.0E-7D) direction = new Vec3(0.0D, 0.0D, 1.0D); if(direction.lengthSqr() < 1.0E-7D) direction = new Vec3(0.0D, 0.0D, 1.0D);
@@ -177,11 +204,36 @@ public class NebulaBlaze extends MagicWeapon {
if(target == null || !target.isAlive()) { if(target == null || !target.isAlive()) {
target = null; target = null;
customData.remove(TARGET_UUID_KEY); customData.remove(TARGET_UUID_KEY);
}else if(serverLevel.clip(new ClipContext(
summon.position(),
target.getBoundingBox().getCenter(),
ClipContext.Block.COLLIDER,
ClipContext.Fluid.NONE,
summon
)).getType() != HitResult.Type.MISS) {
target = null;
customData.remove(TARGET_UUID_KEY);
} }
} }
if(target == null) { if(target == null) {
List<Entity> targets = SearchUtil.searchNearestEnemies(summon, summon.getOwner(), summon.getBoundingBox().inflate(targetRange), 1); List<Entity> targets = SearchUtil.searchEnemies(summon, summon.getOwner(), summon.getBoundingBox().inflate(targetRange));
target = targets.isEmpty() ? null : targets.getFirst(); double bestDistance = Double.MAX_VALUE;
for(Entity candidate : targets) {
Vec3 targetCenter = candidate.getBoundingBox().getCenter();
if(serverLevel.clip(new ClipContext(
summon.position(),
targetCenter,
ClipContext.Block.COLLIDER,
ClipContext.Fluid.NONE,
summon
)).getType() != HitResult.Type.MISS) continue;
double distance = targetCenter.distanceToSqr(summon.position());
if(distance < bestDistance) {
bestDistance = distance;
target = candidate;
}
}
if(target != null) customData.putUUID(TARGET_UUID_KEY, target.getUUID()); if(target != null) customData.putUUID(TARGET_UUID_KEY, target.getUUID());
} }
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData); summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
@@ -204,15 +256,16 @@ public class NebulaBlaze extends MagicWeapon {
summon.yRotO = xyRot[1]; summon.yRotO = xyRot[1];
if(summon.level().isClientSide()) return; if(summon.level().isClientSide()) return;
addTrailParticles(summon, direction, explosive);
AABB hitBox = new AABB(start, end).inflate(HITBOX_INFLATE); AABB hitBox = new AABB(start, end).inflate(0.35);
List<Entity> hitTargets = summon.level().getEntitiesOfClass( List<Entity> hitTargets = summon.level().getEntitiesOfClass(
Entity.class, Entity.class,
hitBox, hitBox,
FilterUtil.createTargetFilter(summon, summon.getOwner()) FilterUtil.createTargetFilter(summon, summon.getOwner())
); );
if(!hitTargets.isEmpty()) { if(!hitTargets.isEmpty()) {
explode(summon, damage); explode(summon, damage, explosive);
return; return;
} }
@@ -220,14 +273,23 @@ public class NebulaBlaze extends MagicWeapon {
if(blockHitResult.getType() != HitResult.Type.MISS) { if(blockHitResult.getType() != HitResult.Type.MISS) {
summon.setPos(blockHitResult.getLocation()); summon.setPos(blockHitResult.getLocation());
summon.setDeltaMovement(Vec3.ZERO); summon.setDeltaMovement(Vec3.ZERO);
explode(summon, damage); explode(summon, damage, explosive);
} }
} }
private static void explode(StaticSummon summon, float damage) { private static void explode(StaticSummon summon, float damage, boolean explosive) {
if(!(summon.level() instanceof ServerLevel serverLevel)) return; if(!(summon.level() instanceof ServerLevel serverLevel)) return;
Vec3 pos = summon.position(); Vec3 pos = summon.position();
ParticleUtil.addParticles(
serverLevel,
explosive ? EXPLOSIVE_DEATH_PARTICLE : DEATH_PARTICLE,
pos,
new Vec3(explosive ? 0.75D : 0.55D, explosive ? 0.75D : 0.55D, explosive ? 0.75D : 0.55D),
0.03D,
explosive ? 28 : 20
);
SoundUtil.playServerSound(summon.level(), ModSounds.BOOM.get(), summon.position());
double explosionRange = EXPLOSION_RANGE.get(); double explosionRange = EXPLOSION_RANGE.get();
if(explosionRange > 0.0D) { if(explosionRange > 0.0D) {
ItemStack sourceStack = summon.getEntityData().get(StaticSummon.STACK_SOURCE); ItemStack sourceStack = summon.getEntityData().get(StaticSummon.STACK_SOURCE);
@@ -244,4 +306,38 @@ public class NebulaBlaze extends MagicWeapon {
summon.discard(); summon.discard();
} }
private static void addTrailParticles(StaticSummon summon, Vec3 direction, boolean explosive) {
if(!(summon.level() instanceof ServerLevel serverLevel)) return;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(direction.toVector3f(), summon.getYRot());
Vec3 up = MathUtil.toVec3(dirs[1]).normalize();
Vec3 right = MathUtil.toVec3(dirs[2]).normalize();
double phase = summon.getEntityData().get(StaticSummon.AGE) * 0.75D;
double radius = explosive ? 0.5D : 0.35D;
for(int i = 0; i < 2; i++) {
double angle = phase + Math.PI * i;
Vec3 particlePos = summon.position()
.add(up.scale(Math.cos(angle) * radius))
.add(right.scale(Math.sin(angle) * radius));
ParticleUtil.addParticles(
serverLevel,
explosive ? EXPLOSIVE_TRAIL_PARTICLE : TRAIL_PARTICLE,
particlePos,
Vec3.ZERO,
0.0D,
1
);
}
ParticleUtil.addParticles(
serverLevel,
explosive ? EXPLOSIVE_DUST_PARTICLE : DUST_PARTICLE,
summon.position(),
new Vec3(Math.random(), Math.random(), Math.random()),
0.2D,
1
);
}
} }
@@ -80,8 +80,8 @@ public class Possession extends Whip {
} }
@Override @Override
protected int getCooldown() { protected int getUseTime() {
return 3; return 12;
} }
@Override @Override
@@ -20,20 +20,20 @@ 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.Tier; import net.minecraft.world.item.Tier;
import net.minecraft.world.item.UseAnim;
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.Vector3f; import org.joml.Vector3f;
import org.jspecify.annotations.NonNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public abstract class Whip extends SummonWeapon { public abstract class Whip extends SummonWeapon {
public static final Vector3f OFFSET = new Vector3f(1.0F, -1.0F, 0.0F);
private static final int SEGMENTS = 24; private static final int SEGMENTS = 24;
private static final double HITBOX_INFLATE = 1.0D; private static final double HITBOX_INFLATE = 1.0D;
private static final double SUMMON_OFFSET_X = -1.0D;
private static final double SUMMON_OFFSET_Y = 1.0D;
private static final double SUMMON_OFFSET_Z = 0.0D;
protected Whip(Tier tier, Item.Properties properties) { protected Whip(Tier tier, Item.Properties properties) {
super(tier, properties); super(tier, properties);
@@ -61,7 +61,7 @@ public abstract class Whip extends SummonWeapon {
return getRange() * 0.25D; return getRange() * 0.25D;
} }
protected int getCooldown() { protected int getUseTime() {
return 20; return 20;
} }
@@ -90,11 +90,13 @@ public abstract class Whip extends SummonWeapon {
Entity owner = summon.getOwner(); Entity owner = summon.getOwner();
if(owner == null) return; if(owner == null) return;
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
Vec3 offset = readVec3(customData, "offset", new Vec3(OFFSET.x, OFFSET.y, OFFSET.z));
Vector3f[] dirs = MathUtil.computeCoordinateSystem(owner); Vector3f[] dirs = MathUtil.computeCoordinateSystem(owner);
summon.setPos(new Vec3( summon.setPos(new Vec3(
owner.getX() + dirs[0].x * SUMMON_OFFSET_Z + dirs[1].x * SUMMON_OFFSET_Y + dirs[2].x * SUMMON_OFFSET_X, owner.getX() + dirs[0].x * offset.z + dirs[1].x * offset.y + dirs[2].x * offset.x,
owner.getY() + dirs[0].y * SUMMON_OFFSET_Z + dirs[1].y * SUMMON_OFFSET_Y + dirs[2].y * SUMMON_OFFSET_X, owner.getY() + dirs[0].y * offset.z + dirs[1].y * offset.y + dirs[2].y * offset.x,
owner.getZ() + dirs[0].z * SUMMON_OFFSET_Z + dirs[1].z * SUMMON_OFFSET_Y + dirs[2].z * SUMMON_OFFSET_X owner.getZ() + dirs[0].z * offset.z + dirs[1].z * offset.y + dirs[2].z * offset.x
)); ));
Whip whip = getWhip(summon); Whip whip = getWhip(summon);
if(whip != null) whip.onTick(summon); if(whip != null) whip.onTick(summon);
@@ -123,53 +125,101 @@ public abstract class Whip extends SummonWeapon {
@Override @Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) { public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
ItemStack stack = player.getItemInHand(hand); ItemStack stack = player.getItemInHand(hand);
SoundUtil.playClientSound(player, ModSounds.WHIP_USE.get()); if(player.getCooldowns().isOnCooldown(stack.getItem()) || !tryShoot(level, player, hand, stack)) return InteractionResultHolder.fail(stack);
if(!level.isClientSide()) { player.startUsingItem(hand);
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player); player.getCooldowns().addCooldown(stack.getItem(), Math.max(1, getUseTime() / 3));
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level);
summon.setOwner(player);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, stack.copy());
summon.setPos(new Vec3(
player.getX() + dirs[0].x * SUMMON_OFFSET_Z + dirs[1].x * SUMMON_OFFSET_Y + dirs[2].x * SUMMON_OFFSET_X,
player.getY() + dirs[0].y * SUMMON_OFFSET_Z + dirs[1].y * SUMMON_OFFSET_Y + dirs[2].y * SUMMON_OFFSET_X,
player.getZ() + dirs[0].z * SUMMON_OFFSET_Z + dirs[1].z * SUMMON_OFFSET_Y + dirs[2].z * SUMMON_OFFSET_X
));
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.POSSESSION);
summon.getEntityData().set(StaticSummon.RENDER_MODE, "custom");
summon.getEntityData().set(StaticSummon.LIFETIME, getLifetime());
int rotateAngle = (int)((player.getRandom().nextFloat() * 2.0F - 1.0F) * getRotateAngle());
dirs = MathUtil.rotateCoordinateSystem(dirs[0], dirs[2], rotateAngle);
CompoundTag customData = new CompoundTag();
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);
customData.putDouble("range", getRange());
customData.putDouble("height", getHeight());
customData.putDouble("bend", getBend());
customData.putBoolean("reverse", summon.getRandom().nextInt(2) == 0);
customData.putString("res", getRes(summon));
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
summon.setNoGravity(true);
summon.noPhysics = true;
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
summon.setXRot(xyRot[0]);
summon.setYRot(xyRot[1]);
level.addFreshEntity(summon);
}
player.getCooldowns().addCooldown(stack.getItem(), getCooldown());
return InteractionResultHolder.sidedSuccess(stack, level.isClientSide()); return InteractionResultHolder.sidedSuccess(stack, level.isClientSide());
} }
@Override
public int getUseDuration(ItemStack stack, LivingEntity entity) {
return 72000;
}
@Override
public @NonNull UseAnim getUseAnimation(ItemStack stack) {
return UseAnim.BLOCK;
}
public boolean shouldShootThisTick(ItemStack weaponStack, LivingEntity entity, int remainingUseTicks) {
int useTime = Math.max(1, getUseTime());
int elapsedMinecraftTicks = getUseDuration(weaponStack, entity) - remainingUseTicks;
if(elapsedMinecraftTicks <= 0) return false;
int currentShot = elapsedMinecraftTicks * 3 / useTime;
int previousShot = (elapsedMinecraftTicks - 1) * 3 / useTime;
return currentShot > previousShot;
}
@Override
public void onUseTick(Level level, LivingEntity entity, ItemStack stack, int count) {
if(level.isClientSide()) return;
if(!(entity instanceof Player player)) return;
if(!shouldShootThisTick(stack, entity, count)) return;
if(!tryShoot(level, player, player.getUsedItemHand(), stack)) {
player.stopUsingItem();
}
}
protected boolean tryShoot(Level level, Player player, InteractionHand hand, ItemStack stack) {
shoot(level, player, hand, stack);
return true;
}
protected void shoot(Level level, Player player, InteractionHand hand, ItemStack stack) {
SoundUtil.playClientSound(player, ModSounds.WHIP_USE.get());
if(level.isClientSide()) return;
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level);
summon.setOwner(player);
summon.getEntityData().set(StaticSummon.STACK_SOURCE, stack.copy());
Vector3f offset = new Vector3f(
hand == InteractionHand.OFF_HAND ? -OFFSET.x : OFFSET.x,
OFFSET.y,
OFFSET.z
);
summon.setPos(new Vec3(
player.getX() + dirs[0].x * offset.z + dirs[1].x * offset.y + dirs[2].x * offset.x,
player.getY() + dirs[0].y * offset.z + dirs[1].y * offset.y + dirs[2].y * offset.x,
player.getZ() + dirs[0].z * offset.z + dirs[1].z * offset.y + dirs[2].z * offset.x
));
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.POSSESSION);
summon.getEntityData().set(StaticSummon.RENDER_MODE, "custom");
summon.getEntityData().set(StaticSummon.LIFETIME, getLifetime());
int rotateAngle = (int)((player.getRandom().nextFloat() * 2.0F - 1.0F) * getRotateAngle());
dirs = MathUtil.rotateCoordinateSystem(dirs[0], dirs[2], rotateAngle);
CompoundTag customData = new CompoundTag();
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);
customData.putFloat("offsetX", offset.x);
customData.putFloat("offsetY", offset.y);
customData.putFloat("offsetZ", offset.z);
customData.putDouble("range", getRange());
customData.putDouble("height", getHeight());
customData.putDouble("bend", getBend());
customData.putBoolean("reverse", summon.getRandom().nextInt(2) == 0);
customData.putString("res", getRes(summon));
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
summon.setNoGravity(true);
summon.noPhysics = true;
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
summon.setXRot(xyRot[0]);
summon.setYRot(xyRot[1]);
level.addFreshEntity(summon);
}
private static void hurtTargets(StaticSummon summon) { private static void hurtTargets(StaticSummon summon) {
if(summon.level().isClientSide()) return; if(summon.level().isClientSide()) return;
@@ -2,11 +2,13 @@ package com.lzxnone.terraria.mixin;
import com.lzxnone.terraria.effect.ModEffects; import com.lzxnone.terraria.effect.ModEffects;
import com.lzxnone.terraria.client.config.RenderConfigs; import com.lzxnone.terraria.client.config.RenderConfigs;
import com.lzxnone.terraria.client.item.magic.ClientNebulaBlaze;
import com.lzxnone.terraria.client.item.melee.ClientDevilsDevastation; 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;
import com.lzxnone.terraria.item.weapon.melee.Mace; import com.lzxnone.terraria.item.weapon.melee.Mace;
import com.lzxnone.terraria.item.weapon.summon.whip.Whip;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.player.AbstractClientPlayer;
@@ -105,8 +107,14 @@ public class ItemInHandRenderMixin {
boolean leftHand, PoseStack poseStack, MultiBufferSource buffer, boolean leftHand, PoseStack poseStack, MultiBufferSource buffer,
int seed, CallbackInfo ci) { int seed, CallbackInfo ci) {
if(!RenderConfigs.ENABLE_RENDER_ITEM.get()) return; if(!RenderConfigs.ENABLE_RENDER_ITEM.get()) return;
if(itemStack.getItem() instanceof Whip && entity instanceof Player player) {
if((itemStack.is(ModItems.ZENITH.get()) if(player.isUsingItem()) {
ItemStack usingStack = player.getUseItem();
if(usingStack.is(itemStack.getItem())) {
ci.cancel();
}
}
}else if((itemStack.is(ModItems.ZENITH.get())
|| itemStack.is(ModItems.TRUE_COPPER_SHORTSWORD.get()) || itemStack.is(ModItems.TRUE_COPPER_SHORTSWORD.get())
|| itemStack.is(ModItems.FIRST_FRACTAL.get()) || itemStack.is(ModItems.FIRST_FRACTAL.get())
|| itemStack.is(ModItems.TERRAGRIM.get())) && entity instanceof Player player) { || itemStack.is(ModItems.TERRAGRIM.get())) && entity instanceof Player player) {
@@ -133,6 +141,14 @@ public class ItemInHandRenderMixin {
ci.cancel(); ci.cancel();
} }
} }
}else if(itemStack.is(ModItems.NEBULA_BLAZE.get()) && entity instanceof Player player) {
if(player.isUsingItem()) {
ItemStack usingStack = player.getUseItem();
if(usingStack.is(itemStack.getItem())) {
ClientNebulaBlaze.renderHandProjectile(buffer, poseStack, player);
ci.cancel();
}
}
} }
} }
@@ -5,6 +5,7 @@ import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.lzxnone.terraria.item.ModItems; import com.lzxnone.terraria.item.ModItems;
import com.lzxnone.terraria.item.weapon.MagicWeapon; import com.lzxnone.terraria.item.weapon.MagicWeapon;
import com.lzxnone.terraria.item.weapon.RangedWeapon; import com.lzxnone.terraria.item.weapon.RangedWeapon;
import com.lzxnone.terraria.item.weapon.summon.whip.Whip;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -22,7 +23,8 @@ public abstract class UseSpeedMixin {
|| usingItem.is(ModItems.TERRAGRIM.get()) || usingItem.is(ModItems.TERRAGRIM.get())
|| usingItem.is(ModItems.MACE.get()) || usingItem.is(ModItems.MACE.get())
|| usingItem.getItem() instanceof MagicWeapon || usingItem.getItem() instanceof MagicWeapon
|| usingItem.getItem() instanceof RangedWeapon; || usingItem.getItem() instanceof RangedWeapon
|| usingItem.getItem() instanceof Whip;
} }
@WrapOperation( @WrapOperation(
@@ -40,6 +40,9 @@
"magic_shoot": { "magic_shoot": {
"sounds": ["lzxnoneterraria:magic_shoot"] "sounds": ["lzxnoneterraria:magic_shoot"]
}, },
"magic_shoot2": {
"sounds": ["lzxnoneterraria:magic_shoot2"]
},
"bubble": { "bubble": {
"sounds": ["lzxnoneterraria:bubble"] "sounds": ["lzxnoneterraria:bubble"]
}, },
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 589 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 618 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 598 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 607 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 743 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 B