This commit is contained in:
LZX committed 2026-06-28 16:37:02 +08:00
commit 8593736bf4
117 files changed
+3577

No files matched your search

@@ -0,0 +1,10 @@
package com.lzxnone.terraria;
import net.neoforged.neoforge.common.ModConfigSpec;
public class Config {
private static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder();
static final ModConfigSpec SPEC = BUILDER.build();
}
@@ -0,0 +1,45 @@
package com.lzxnone.terraria;
import com.lzxnone.terraria.block.ModBlocks;
import com.lzxnone.terraria.creative_mode_tab.ModCreativeModeTabs;
import com.lzxnone.terraria.effect.ModEffects;
import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.summon.BeeSummon;
import com.lzxnone.terraria.item.ModItems;
import com.lzxnone.terraria.particle.ModParticles;
import net.neoforged.neoforge.event.entity.EntityAttributeCreationEvent;
import org.slf4j.Logger;
import com.mojang.logging.LogUtils;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.ModContainer;
@Mod(LzxnoneTerraria.MODID)
public class LzxnoneTerraria {
public static final String MODID = "lzxnoneterraria";
public static final Logger LOGGER = LogUtils.getLogger();
public LzxnoneTerraria(IEventBus modEventBus, ModContainer modContainer) {
//注册
ModBlocks.BLOCKS.register(modEventBus);
ModItems.ITEMS.register(modEventBus);
ModEffects.MOB_EFFECTS.register(modEventBus);
ModEntities.ENTITY_TYPES.register(modEventBus);
ModParticles.PARTICLE_TYPES.register(modEventBus);
ModSounds.SOUND_EVENTS.register(modEventBus);
ModCreativeModeTabs.CREATIVE_MODE_TABS.register(modEventBus);
//实体属性创建
modEventBus.addListener(this::onEntityAttributeCreation);
//配置
modContainer.registerConfig(ModConfig.Type.COMMON, Config.SPEC);
}
public void onEntityAttributeCreation(EntityAttributeCreationEvent event) {
event.put(ModEntities.BEE_SUMMON.get(), BeeSummon.createAttributes().build());
}
}
@@ -0,0 +1,43 @@
package com.lzxnone.terraria;
import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.projectile.TextureProjectileRenderer;
import com.lzxnone.terraria.particle.*;
import net.minecraft.client.renderer.entity.BeeRenderer;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
import net.neoforged.neoforge.client.event.RegisterParticleProvidersEvent;
import net.neoforged.neoforge.client.gui.ConfigurationScreen;
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
@Mod(value = LzxnoneTerraria.MODID, dist = Dist.CLIENT)
public class LzxnoneTerrariaClient {
public LzxnoneTerrariaClient(ModContainer container, IEventBus modEventBus) {
container.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new);
//Entity渲染
modEventBus.addListener(EntityRenderersEvent.RegisterRenderers.class, event -> {
event.registerEntityRenderer(ModEntities.TEXTURE_PROJECTILE.get(), TextureProjectileRenderer::new);
});
modEventBus.addListener(EntityRenderersEvent.RegisterRenderers.class, event -> {
event.registerEntityRenderer(ModEntities.BEE_SUMMON.get(), BeeRenderer::new);
});
//粒子渲染
modEventBus.addListener(RegisterParticleProvidersEvent.class, event -> {
event.registerSpriteSet(ModParticles.DUST_PARTICLE.get(), DustParticle.Provider::new);
});
modEventBus.addListener(RegisterParticleProvidersEvent.class, event -> {
event.registerSpriteSet(ModParticles.STAR_PARTICLE.get(), StarParticle.Provider::new);
});
modEventBus.addListener(RegisterParticleProvidersEvent.class, event -> {
event.registerSpriteSet(ModParticles.EXPLODE_PARTICLE.get(), ExplodeParticle.Provider::new);
});
modEventBus.addListener(RegisterParticleProvidersEvent.class, event -> {
event.registerSpriteSet(ModParticles.SEEDLER_THORN_PARTICLE.get(), SeedlerThornParticle.Provider::new);
});
}
}
@@ -0,0 +1,38 @@
package com.lzxnone.terraria;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.neoforged.neoforge.registries.DeferredRegister;
import java.util.function.Supplier;
public class ModSounds {
public static final DeferredRegister<SoundEvent> SOUND_EVENTS =
DeferredRegister.create(Registries.SOUND_EVENT, LzxnoneTerraria.MODID);
public static final Supplier<SoundEvent> BEAM =
SOUND_EVENTS.register("beam",
() -> SoundEvent.createVariableRangeEvent(
ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "beam")));
public static final Supplier<SoundEvent> MAX_MANA =
SOUND_EVENTS.register("max_mana",
() -> SoundEvent.createVariableRangeEvent(
ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "max_mana")));
public static final Supplier<SoundEvent> WAVE =
SOUND_EVENTS.register("wave",
() -> SoundEvent.createVariableRangeEvent(
ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "wave")));
public static final Supplier<SoundEvent> STAR_FALL =
SOUND_EVENTS.register("star_fall",
() -> SoundEvent.createVariableRangeEvent(
ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "star_fall")));
public static final Supplier<SoundEvent> STAR_COLLIDE =
SOUND_EVENTS.register("star_collide",
() -> SoundEvent.createVariableRangeEvent(
ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "star_collide")));
public static final Supplier<SoundEvent> BOOM =
SOUND_EVENTS.register("boom",
() -> SoundEvent.createVariableRangeEvent(
ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "boom")));
}
@@ -0,0 +1,8 @@
package com.lzxnone.terraria.block;
import com.lzxnone.terraria.LzxnoneTerraria;
import net.neoforged.neoforge.registries.DeferredRegister;
public class ModBlocks {
public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(LzxnoneTerraria.MODID);
}
@@ -0,0 +1,32 @@
package com.lzxnone.terraria.creative_mode_tab;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.item.ModItems;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
public class ModCreativeModeTabs {
public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, LzxnoneTerraria.MODID);
public static final DeferredHolder<CreativeModeTab, CreativeModeTab> WEAPON_TAB = CREATIVE_MODE_TABS.register("weapon_tab", () -> CreativeModeTab.builder()
.title(Component.translatable("itemGroup.lzxnoneterraria.weapon"))
.withTabsBefore(CreativeModeTabs.COMBAT)
.icon(() -> ModItems.TERRA_BLADE.get().getDefaultInstance())
.displayItems((parameters, output) -> {
output.accept(ModItems.COPPER_SHORTSWORD.get());
output.accept(ModItems.ENCHANTED_SWORD.get());
output.accept(ModItems.BEE_KEEPER.get());
output.accept(ModItems.STARFURY.get());
output.accept(ModItems.SEEDLER.get());
output.accept(ModItems.THE_HORSEMANS_BLADE.get());
output.accept(ModItems.INFLUX_WAVER.get());
output.accept(ModItems.STAR_WRATH.get());
output.accept(ModItems.MEOWMERE.get());
output.accept(ModItems.TERRA_BLADE.get());
output.accept(ModItems.ZENITH.get());
}).build());
}
@@ -0,0 +1,10 @@
package com.lzxnone.terraria.effect;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
public class ConfusedEffect extends MobEffect {
public ConfusedEffect() {
super(MobEffectCategory.HARMFUL, 0xFF00FF);
}
}
@@ -0,0 +1,67 @@
package com.lzxnone.terraria.effect;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
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.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.LivingEntity;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.RenderLivingEvent;
import org.joml.Matrix4f;
@EventBusSubscriber(modid = LzxnoneTerraria.MODID, value = Dist.CLIENT)
public class EffectIconRenderer {
private static final ResourceLocation CONFUSED_ICON =
ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "textures/mob_effect_display/confused.png");
@SubscribeEvent
public static void onRenderLiving(RenderLivingEvent.Post<?, ?> event) {
LivingEntity entity = event.getEntity();
if(entity.hasEffect(ModEffects.CONFUSED)) {
renderIcon(event, CONFUSED_ICON);
}
}
public static void renderIcon(RenderLivingEvent.Post<?, ?> event, ResourceLocation icon) {
LivingEntity entity = event.getEntity();
PoseStack poseStack = event.getPoseStack();
MultiBufferSource buffer = event.getMultiBufferSource();
poseStack.pushPose();
float heightOffset = entity.getBbHeight() + 0.8F;
poseStack.translate(0.0F, heightOffset, 0.0F);
float partialTicks = event.getPartialTick();
float headYaw = net.minecraft.util.Mth.rotLerp(partialTicks, entity.yHeadRotO, entity.yHeadRot);
poseStack.mulPose(com.mojang.math.Axis.YP.rotationDegrees(-headYaw));
float scale = 0.5F;
poseStack.scale(scale, -scale, scale);
Matrix4f matrix = poseStack.last().pose();
VertexConsumer builder = buffer.getBuffer(RenderType.entityCutoutNoCull(icon));
// 光照
int light = event.getPackedLight();
builder.addVertex(matrix, -0.5F, -0.5F, 0).setColor(255, 255, 255, 255)
.setUv(0, 0).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(0, 0, -1);
builder.addVertex(matrix, -0.5F, 0.5F, 0).setColor(255, 255, 255, 255)
.setUv(0, 1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(0, 0, -1);
builder.addVertex(matrix, 0.5F, 0.5F, 0).setColor(255, 255, 255, 255)
.setUv(1, 1).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(0, 0, -1);
builder.addVertex(matrix, 0.5F, -0.5F, 0).setColor(255, 255, 255, 255)
.setUv(1, 0).setOverlay(OverlayTexture.NO_OVERLAY).setLight(light).setNormal(0, 0, -1);
poseStack.popPose();
}
}
@@ -0,0 +1,58 @@
package com.lzxnone.terraria.effect;
import com.lzxnone.terraria.LzxnoneTerraria;
import net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket;
import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.player.Player;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.entity.living.MobEffectEvent;
import net.neoforged.neoforge.event.tick.EntityTickEvent;
@EventBusSubscriber(modid = LzxnoneTerraria.MODID)
public class EffectLogicHandler {
@SubscribeEvent
public static void onEffectAdded(MobEffectEvent.Added event) {
LivingEntity entity = event.getEntity();
if(!entity.level().isClientSide() && !(entity instanceof Player)) {
if(entity.level() instanceof ServerLevel serverLevel) {
serverLevel.getChunkSource().broadcast(entity,
new ClientboundUpdateMobEffectPacket(entity.getId(), event.getEffectInstance(), false));
}
}
}
@SubscribeEvent
public static void onEffectRemoved(MobEffectEvent.Remove event) {
LivingEntity entity = event.getEntity();
if(!entity.level().isClientSide() && !(entity instanceof Player)) {
if(entity.level() instanceof ServerLevel serverLevel) {
serverLevel.getChunkSource().broadcast(entity,
new ClientboundRemoveMobEffectPacket(entity.getId(), event.getEffectInstance().getEffect()));
}
}
}
@SubscribeEvent
public static void onEffectExpired(MobEffectEvent.Expired event) {
LivingEntity entity = event.getEntity();
if (!entity.level().isClientSide() && !(entity instanceof Player)) {
if (entity.level() instanceof ServerLevel serverLevel) {
serverLevel.getChunkSource().broadcast(entity,
new ClientboundRemoveMobEffectPacket(entity.getId(), event.getEffectInstance().getEffect()));
}
}
}
@SubscribeEvent
public static void onLivingTick(EntityTickEvent.Post event) {
if(!event.getEntity().level().isClientSide() && event.getEntity() instanceof PathfinderMob mob) {
}
}
}
@@ -0,0 +1,15 @@
package com.lzxnone.terraria.effect;
import com.lzxnone.terraria.LzxnoneTerraria;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.effect.MobEffect;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
public class ModEffects {
public static final DeferredRegister<MobEffect> MOB_EFFECTS =
DeferredRegister.create(BuiltInRegistries.MOB_EFFECT, LzxnoneTerraria.MODID);
public static final DeferredHolder<MobEffect, ConfusedEffect> CONFUSED =
MOB_EFFECTS.register("confused", ConfusedEffect::new);
}
@@ -0,0 +1,33 @@
package com.lzxnone.terraria.entity;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.entity.projectile.TextureProjectile;
import com.lzxnone.terraria.entity.summon.BeeSummon;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.neoforged.neoforge.registries.DeferredRegister;
import java.util.function.Supplier;
public class ModEntities {
public static final DeferredRegister<EntityType<?>> ENTITY_TYPES =
DeferredRegister.create(Registries.ENTITY_TYPE, LzxnoneTerraria.MODID);
public static final Supplier<EntityType<TextureProjectile>> TEXTURE_PROJECTILE =
ENTITY_TYPES.register("texture_projectile", () -> EntityType.Builder.of(
TextureProjectile::new, MobCategory.MISC)
.sized(0.5f, 0.5f)
.clientTrackingRange(1024)
.updateInterval(1)
.build("texture_projectile")
);
public static final Supplier<EntityType<BeeSummon>> BEE_SUMMON =
ENTITY_TYPES.register("bee_summon", () -> EntityType.Builder.of(
BeeSummon::new, MobCategory.MISC)
.sized(0.7F, 0.6F)
.clientTrackingRange(8)
.build("bee_summon")
);
}
@@ -0,0 +1,15 @@
package com.lzxnone.terraria.entity.projectile;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult;
public interface IProjectileBehavior {
default void onMoving(TextureProjectile projectile) {}
default void onHitEntity(TextureProjectile projectile, EntityHitResult result) {}
default void onHitBlock(TextureProjectile projectile, BlockHitResult result) {}
default void onDied(TextureProjectile projectile) {
if(!projectile.level().isClientSide()) {
projectile.discard();
}
}
}
@@ -0,0 +1,49 @@
package com.lzxnone.terraria.entity.projectile;
import com.lzxnone.terraria.item.weapon.melee.EnchantedSword;
import com.lzxnone.terraria.item.weapon.melee.Seedler;
import com.lzxnone.terraria.item.weapon.melee.Starfury;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult;
import java.util.HashMap;
import java.util.Map;
public class ProjectileBehaviors {
private static final Map<String, IProjectileBehavior> BEHAVIORS = new HashMap<>();
public static final String DEFAULT = "default";
public static final String ENCHANTED_SWORD_BEAM = "enchanted_sword_beam";
public static final String STARFURY_STAR = "starfury_star";
public static final String SEEDLER_NUT = "seedler_nut";
public static final String SEEDLER_THORN = "seedler_thorn";
static {
BEHAVIORS.put(DEFAULT, new IProjectileBehavior() {
@Override
public void onHitEntity(TextureProjectile projectile, EntityHitResult result) {
if(projectile.level().isClientSide()) return;
projectile.discard();
}
@Override
public void onHitBlock(TextureProjectile projectile, BlockHitResult result) {
if(projectile.level().isClientSide()) return;
if(!projectile.level().getBlockState(result.getBlockPos()).getCollisionShape(projectile.level(), result.getBlockPos()).isEmpty()) {
projectile.discard();
}
}
@Override
public void onDied(TextureProjectile projectile) {
projectile.discard();
}
});
BEHAVIORS.put(ENCHANTED_SWORD_BEAM, EnchantedSword.PROJECTILE_BEHAVIOR);
BEHAVIORS.put(STARFURY_STAR, Starfury.PROJECTILE_BEHAVIOR);
BEHAVIORS.put(SEEDLER_NUT, Seedler.NUT_PROJECTILE_BEHAVIOR);
BEHAVIORS.put(SEEDLER_THORN, Seedler.THORN_PROJECTILE_BEHAVIOR);
}
public static IProjectileBehavior getBehavior(String id) {
return BEHAVIORS.getOrDefault(id, BEHAVIORS.get(DEFAULT));
}
}
@@ -0,0 +1,260 @@
package com.lzxnone.terraria.entity.projectile;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.entity.projectile.ProjectileUtil;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.*;
import net.objecthunter.exp4j.Expression;
import net.objecthunter.exp4j.ExpressionBuilder;
import org.joml.Vector3f;
public class TextureProjectile extends Projectile {
public static final EntityDataAccessor<String> BEHAVIOR =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.STRING);
public static final EntityDataAccessor<ItemStack> ITEM =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.ITEM_STACK);
public static final EntityDataAccessor<Vector3f> ORIGIN =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.VECTOR3);
public static final EntityDataAccessor<Vector3f> DIRECTION =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.VECTOR3);
public static final EntityDataAccessor<Vector3f> UP =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.VECTOR3);
public static final EntityDataAccessor<Vector3f> RIGHT =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.VECTOR3);
public static final EntityDataAccessor<Float> SCALE_X =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> SCALE_Y =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Integer> RXP =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> RYP =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> RZP =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> RXPS =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> RYPS =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> RZPS =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Boolean> GLOW =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<Integer> AGE =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> LIFETIME =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<String> EXPRESSION_X =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.STRING); //右
public static final EntityDataAccessor<String> EXPRESSION_Y =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.STRING); //上
public static final EntityDataAccessor<String> EXPRESSION_Z =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.STRING); //前
public static final EntityDataAccessor<CompoundTag> CUSTOM_DATA =
SynchedEntityData.defineId(TextureProjectile.class, EntityDataSerializers.COMPOUND_TAG);
public boolean isInit = false;
public Expression exprX;
public Expression exprY;
public Expression exprZ;
public Vec3 prevPos;
public Vec3 prevDeltaMovement;
public boolean positionOverridden = false;
public TextureProjectile(EntityType<TextureProjectile> type, Level level) {
super(type, level);
this.setNoGravity(true);
}
@Override
protected void defineSynchedData(SynchedEntityData.Builder builder) {
builder.define(BEHAVIOR, "default");
builder.define(ITEM, ItemStack.EMPTY);
builder.define(ORIGIN, new Vector3f(0, 0, 0));
builder.define(DIRECTION, new Vector3f(0, 0, 1));
builder.define(UP, new Vector3f(0, 1, 0));
builder.define(RIGHT, new Vector3f(1, 0, 0));
builder.define(SCALE_X, 1.0f);
builder.define(SCALE_Y, 1.0f);
builder.define(RXP, 0);
builder.define(RYP, 0);
builder.define(RZP, 0);
builder.define(RXPS, 0);
builder.define(RYPS, 0);
builder.define(RZPS, 0);
builder.define(GLOW, false);
builder.define(AGE, 0);
builder.define(LIFETIME, 60);
builder.define(EXPRESSION_X, "0");
builder.define(EXPRESSION_Y, "0");
builder.define(EXPRESSION_Z, "0");
builder.define(CUSTOM_DATA, new CompoundTag());
}
@Override
public void onSyncedDataUpdated(EntityDataAccessor<?> key) {
super.onSyncedDataUpdated(key);
if(!isInit) return;
if(key.equals(TextureProjectile.EXPRESSION_Y) && exprY != null) {
this.exprY = new ExpressionBuilder(this.entityData.get(TextureProjectile.EXPRESSION_Y)).variables("t").build();
}else if (key.equals(TextureProjectile.EXPRESSION_Z) && exprZ != null) {
this.exprZ = new ExpressionBuilder(this.entityData.get(TextureProjectile.EXPRESSION_Z)).variables("t").build();
}else if (key.equals(TextureProjectile.EXPRESSION_X) && exprX != null) {
this.exprX = new ExpressionBuilder(this.entityData.get(TextureProjectile.EXPRESSION_X)).variables("t").build();
}
}
@Override
public void tick() {
super.tick();
if(!isInit) {
this.exprX = new ExpressionBuilder(this.entityData.get(EXPRESSION_X)).variables("t").build();
this.exprY = new ExpressionBuilder(this.entityData.get(EXPRESSION_Y)).variables("t").build();
this.exprZ = new ExpressionBuilder(this.entityData.get(EXPRESSION_Z)).variables("t").build();
isInit = true;
}
this.prevPos = this.position();
this.prevDeltaMovement = this.getDeltaMovement();
double valX = this.exprX.setVariable("t", this.entityData.get(AGE)).evaluate();
double valY = this.exprY.setVariable("t", this.entityData.get(AGE)).evaluate();
double valZ = this.exprZ.setVariable("t", this.entityData.get(AGE)).evaluate();
Vector3f origin = this.entityData.get(ORIGIN);
Vector3f right = this.entityData.get(RIGHT);
Vector3f up = this.entityData.get(UP);
Vector3f dir = this.entityData.get(DIRECTION);
double newX = origin.x + (valX * right.x) + (valY * up.x) + (valZ * dir.x);
double newY = origin.y + (valX * right.y) + (valY * up.y) + (valZ * dir.y);
double newZ = origin.z + (valX * right.z) + (valY * up.z) + (valZ * dir.z);
Vec3 nextPos = new Vec3(newX, newY, newZ);
this.setDeltaMovement(nextPos.subtract(this.position()));
HitResult hitResult = ProjectileUtil.getHitResultOnMoveVector(this, this::canHitEntity);
if(hitResult.getType() != HitResult.Type.MISS) {
this.onHit(hitResult);
}
if(!this.positionOverridden) {
this.setPos(nextPos);
}
this.positionOverridden = false;
ProjectileBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onMoving(this);
if(this.entityData.get(AGE) > this.entityData.get(LIFETIME)) {
ProjectileBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onDied(this);
}
this.entityData.set(AGE, this.entityData.get(AGE) + 1);
}
@Override
protected void addAdditionalSaveData(CompoundTag tag) {
tag.putString("behavior", this.entityData.get(BEHAVIOR));
ItemStack stack = this.entityData.get(ITEM);
if(!stack.isEmpty()) tag.put("item", stack.save(this.level().registryAccess()));
tag.putFloat("originX", this.entityData.get(ORIGIN).x);
tag.putFloat("originY", this.entityData.get(ORIGIN).y);
tag.putFloat("originZ", this.entityData.get(ORIGIN).z);
tag.putFloat("dirX", this.entityData.get(DIRECTION).x);
tag.putFloat("dirY", this.entityData.get(DIRECTION).y);
tag.putFloat("dirZ", this.entityData.get(DIRECTION).z);
tag.putFloat("upX", this.entityData.get(UP).x);
tag.putFloat("upY", this.entityData.get(UP).y);
tag.putFloat("upZ", this.entityData.get(UP).z);
tag.putFloat("rightX", this.entityData.get(RIGHT).x);
tag.putFloat("rightY", this.entityData.get(RIGHT).y);
tag.putFloat("rightZ", this.entityData.get(RIGHT).z);
tag.putFloat("scaleX", this.entityData.get(SCALE_X));
tag.putFloat("scaleY", this.entityData.get(SCALE_Y));
tag.putInt("rxp", this.entityData.get(RXP));
tag.putInt("ryp", this.entityData.get(RYP));
tag.putInt("rzp", this.entityData.get(RZP));
tag.putInt("rxps", this.entityData.get(RXPS));
tag.putInt("ryps", this.entityData.get(RYPS));
tag.putInt("rzps", this.entityData.get(RZPS));
tag.putBoolean("glow", this.entityData.get(GLOW));
tag.putInt("age", this.entityData.get(AGE));
tag.putInt("lifetime", this.entityData.get(LIFETIME));
tag.putString("expressionX", this.entityData.get(EXPRESSION_X));
tag.putString("expressionY", this.entityData.get(EXPRESSION_Y));
tag.putString("expressionZ", this.entityData.get(EXPRESSION_Z));
tag.put("customData", this.entityData.get(CUSTOM_DATA));
}
@Override
protected void readAdditionalSaveData(CompoundTag tag) {
if(tag.contains("behavior")) this.entityData.set(BEHAVIOR, tag.getString("behavior"));
if(tag.contains("item")) {
ItemStack.parse(this.level().registryAccess(), tag.getCompound("item"))
.ifPresent(stack -> this.entityData.set(ITEM, stack));
}
Vector3f origin = new Vector3f();
if(tag.contains("originX")) origin.x = tag.getFloat("originX");
if(tag.contains("originY")) origin.y = tag.getFloat("originY");
if(tag.contains("originZ")) origin.z = tag.getFloat("originZ");
this.entityData.set(ORIGIN, origin);
Vector3f dir = new Vector3f();
if(tag.contains("dirX")) dir.x = tag.getFloat("dirX");
if(tag.contains("dirY")) dir.y = tag.getFloat("dirY");
if(tag.contains("dirZ")) dir.z = tag.getFloat("dirZ");
this.entityData.set(DIRECTION, dir);
Vector3f up = this.entityData.get(UP);
tag.putFloat("upX", up.x);
tag.putFloat("upY", up.y);
tag.putFloat("upZ", up.z);
this.entityData.set(UP, up);
Vector3f right = this.entityData.get(RIGHT);
tag.putFloat("rightX", right.x);
tag.putFloat("rightY", right.y);
tag.putFloat("rightZ", right.z);
this.entityData.set(RIGHT, right);
if(tag.contains("scaleX")) this.entityData.set(SCALE_X, tag.getFloat("scaleX"));
if(tag.contains("scaleY")) this.entityData.set(SCALE_Y, tag.getFloat("scaleY"));
if(tag.contains("rxp")) this.entityData.set(RXP, tag.getInt("rxp"));
if(tag.contains("ryp")) this.entityData.set(RYP, tag.getInt("ryp"));
if(tag.contains("rzp")) this.entityData.set(RZP, tag.getInt("rzp"));
if(tag.contains("rxps")) this.entityData.set(RXPS, tag.getInt("rxps"));
if(tag.contains("ryps")) this.entityData.set(RYPS, tag.getInt("ryps"));
if(tag.contains("rzps")) this.entityData.set(RZPS, tag.getInt("rzps"));
if(tag.contains("glow")) this.entityData.set(GLOW, tag.getBoolean("glow"));
if(tag.contains("age")) this.entityData.set(AGE, tag.getInt("age"));
if(tag.contains("lifetime")) this.entityData.set(LIFETIME, tag.getInt("lifetime"));
if(tag.contains("expressionX")) this.entityData.set(EXPRESSION_X, tag.getString("expressionX"));
if(tag.contains("expressionY")) this.entityData.set(EXPRESSION_Y, tag.getString("expressionY"));
if(tag.contains("expressionZ")) this.entityData.set(EXPRESSION_Z, tag.getString("expressionZ"));
if(tag.contains("customData")) this.entityData.set(CUSTOM_DATA, tag.getCompound("customData"));
}
@Override
public void lerpTo(double x, double y, double z, float yaw, float pitch, int posRotationIncrements) {}
@Override
protected void onHitEntity(EntityHitResult result) {
super.onHitEntity(result);
Entity target = result.getEntity();
Entity owner = this.getOwner();
if(owner != null && target.getUUID().equals(owner.getUUID())) return;
ProjectileBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onHitEntity(this, result);
}
@Override
protected void onHitBlock(BlockHitResult result) {
super.onHitBlock(result);
ProjectileBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).onHitBlock(this, result);
}
}
@@ -0,0 +1,89 @@
package com.lzxnone.terraria.entity.projectile;
import com.lzxnone.terraria.utils.MathUtil;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
import org.joml.Matrix3f;
import org.joml.Quaternionf;
import org.joml.Vector3f;
public class TextureProjectileRenderer extends EntityRenderer<Entity> {
public TextureProjectileRenderer(EntityRendererProvider.Context context) {
super(context);
}
@Override
public void render(Entity entity, float entityYaw, float partialTick,
PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
if(!(entity instanceof TextureProjectile proj)) return;
if(!proj.isInit || proj.getEntityData().get(TextureProjectile.AGE) < 2) return;
ItemStack stack = proj.getEntityData().get(TextureProjectile.ITEM);
if(stack.isEmpty()) return;
float scaleX = proj.getEntityData().get(TextureProjectile.SCALE_X);
float scaleY = proj.getEntityData().get(TextureProjectile.SCALE_Y);
poseStack.pushPose();
// 缩放
poseStack.scale(scaleX, scaleY, scaleX);
// 朝飞行方向旋转
Vec3 velCurrent = entity.getDeltaMovement();
Vec3 velOld = proj.prevDeltaMovement;
Vector3f velForRot;
if(velCurrent.lengthSqr() > 0.0001) {
velForRot = new Vector3f(
(float) Mth.lerp(partialTick, velOld.x, velCurrent.x),
(float) Mth.lerp(partialTick, velOld.y, velCurrent.y),
(float) Mth.lerp(partialTick, velOld.z, velCurrent.z)
);
} else {
velForRot = new Vector3f(proj.getEntityData().get(TextureProjectile.DIRECTION));
}
Vector3f[] dirs = MathUtil.computeProjectileDir(velForRot);
Matrix3f rotMatrix = new Matrix3f().set(dirs[2], dirs[1], dirs[0]);
poseStack.mulPose(new Quaternionf().setFromNormalized(rotMatrix));
poseStack.mulPose(Axis.XP.rotationDegrees(proj.getEntityData().get(TextureProjectile.RXP) + proj.getEntityData().get(TextureProjectile.RXPS) * proj.getEntityData().get(TextureProjectile.AGE)));
poseStack.mulPose(Axis.YP.rotationDegrees(proj.getEntityData().get(TextureProjectile.RYP) + proj.getEntityData().get(TextureProjectile.RYPS) * proj.getEntityData().get(TextureProjectile.AGE)));
poseStack.mulPose(Axis.ZP.rotationDegrees(proj.getEntityData().get(TextureProjectile.RZP) + proj.getEntityData().get(TextureProjectile.RZPS) * proj.getEntityData().get(TextureProjectile.AGE)));
Minecraft.getInstance().getItemRenderer().renderStatic(
stack,
ItemDisplayContext.NONE,
proj.getEntityData().get(TextureProjectile.GLOW) ? LightTexture.FULL_BRIGHT : packedLight,
OverlayTexture.NO_OVERLAY,
poseStack,
bufferSource,
entity.level(),
0
);
poseStack.popPose();
super.render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight);
}
@Override
public ResourceLocation getTextureLocation(Entity entity) {
return ResourceLocation.parse("lzxnoneterraria:textures/particle/enchanted_sword_beam.png");
}
}
@@ -0,0 +1,184 @@
package com.lzxnone.terraria.entity.summon;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.control.FlyingMoveControl;
import net.minecraft.world.entity.ai.control.LookControl;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.animal.Bee;
import net.minecraft.world.entity.monster.Monster;
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 java.util.UUID;
public class BeeSummon extends Bee {
public static final int LIFETIME = 1200;
public static final int MAX_ATTACK_COUNT = 2;
public int customAge = 0;
public int customAttackCount = 0;
public UUID owner = null;
public BeeSummon(EntityType<? extends Bee> entityType, Level level) {
super(entityType, level);
this.moveControl = new FlyingMoveControl(this, 45, true);
this.lookControl = new LookControl(this);
this.navigation = createNavigation(level);
}
public static AttributeSupplier.@NotNull Builder createAttributes() {
return Bee.createAttributes()
.add(Attributes.MAX_HEALTH, MAX_ATTACK_COUNT)
.add(Attributes.SCALE, 0.5)
.add(Attributes.ATTACK_DAMAGE, 2.0)
.add(Attributes.FOLLOW_RANGE, 32);
}
@Override
public void tick() {
super.tick();
if(!this.level().isClientSide()) {
if(owner == null || this.level().getPlayerByUUID(owner) == null) {
discard();
}
this.customAge++;
if(this.customAge >= LIFETIME) {
this.discard();
}
Player player = this.level().getPlayerByUUID(owner);
LivingEntity target = null;
if(player != null) {
LivingEntity playerAttackTarget = player.getLastHurtMob();
if(playerAttackTarget != null && playerAttackTarget.isAlive() && this.distanceToSqr(playerAttackTarget) <= 1024) {
target = playerAttackTarget;
}
if(target == null) {
LivingEntity playerAttacker = player.getLastHurtByMob();
if(playerAttacker != null && playerAttacker.isAlive() && this.distanceToSqr(playerAttacker) <= 1024) {
target = playerAttacker;
}
}
}
if(target != null) {
this.setTarget(target);
}
target = this.getTarget();
if(target != null && target.isAlive()) {
double dist = this.distanceToSqr(target);
if(dist > 256) {
flyTowards(target.getBoundingBox().getCenter(), 1, 0.5);
}else if(dist > 64) {
flyTowards(target.getBoundingBox().getCenter(), 0.75, 0.5);
}else if(dist > 4) {
flyTowards(target.getBoundingBox().getCenter(), 0.5, 0.5);
}else {
this.doHurtTarget(target);
}
}else if(player != null) {
Vec3 hoverPos = player.position().add(0, 1.5, 0);
if(this.distanceToSqr(player) > 64) {
flyTowards(hoverPos, 0.75, 0.5);
}else {
this.setDeltaMovement(this.getDeltaMovement().scale(0.8));
}
}
}
}
private void flyTowards(Vec3 destination, double acceleration, double friction) {
Vec3 myPos = this.getBoundingBox().getCenter();
Vec3 dir = destination.subtract(myPos);
if(dir.lengthSqr() > 0.05) {
dir = dir.normalize().scale(acceleration);
Vec3 newMovement = this.getDeltaMovement().add(dir).scale(friction);
this.setDeltaMovement(newMovement);
this.getLookControl().setLookAt(destination.x, destination.y, destination.z, 30.0F, 30.0F);
this.setYRot((float)(Math.atan2(newMovement.z, newMovement.x) * (180F / Math.PI)) - 90.0F);
}
}
@Override
protected void registerGoals() {
super.registerGoals();
this.goalSelector.removeAllGoals(goal -> true);
this.targetSelector.removeAllGoals(goal -> true);
this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, Monster.class, false));
}
@Override
public boolean doHurtTarget(Entity target) {
if(owner == null) return false;
Player player = this.level().getPlayerByUUID(owner);
if(player == null) return false;
DamageSource damageSource = this.damageSources().mobAttack(player);
boolean isHurt = target.hurt(damageSource, (float) this.getAttributeValue(Attributes.ATTACK_DAMAGE));
if(isHurt) {
this.customAttackCount++;
if(this.customAttackCount >= MAX_ATTACK_COUNT) {
this.discard();
}else {
this.setHealth(this.getHealth() - 1);
}
}
return isHurt;
}
@Override
public boolean isInvulnerable() {
return true;
}
@Override
public boolean isAttackable() {
return false;
}
@Override
public boolean isPickable() {
return false;
}
@Override
public boolean hurt(DamageSource source, float amount) {
return false;
}
@Override
public boolean isPushable() {
return false;
}
@Override
public void addAdditionalSaveData(@NotNull CompoundTag tag) {
super.addAdditionalSaveData(tag);
tag.putInt("customAttackCount", this.customAttackCount);
tag.putInt("customAge", this.customAge);
if(this.owner != null) tag.putUUID("owner", this.owner);
}
@Override
public void readAdditionalSaveData(@NotNull CompoundTag tag) {
super.readAdditionalSaveData(tag);
if(tag.contains("customAttackCount")) this.customAttackCount = tag.getInt("customAttackCount");
if(tag.contains("customAge")) this.customAge = tag.getInt("customAge");
if(tag.contains("owner")) this.owner = tag.getUUID("owner");
}
}
@@ -0,0 +1,64 @@
package com.lzxnone.terraria.goal;
import com.lzxnone.terraria.effect.ModEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.phys.Vec3;
import java.util.EnumSet;
public class ConfusedEffectGoal extends Goal {
private final PathfinderMob mob;
private Vec3 fleePos;
public ConfusedEffectGoal(PathfinderMob mob) {
this.mob = mob;
this.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.LOOK));
}
@Override
public boolean canUse() {
return this.mob.hasEffect(ModEffects.CONFUSED) && this.mob.getTarget() != null;
}
@Override
public void start() {
this.updateFleePosition();
}
@Override
public boolean canContinueToUse() {
return this.canUse() && !this.mob.getNavigation().isDone();
}
@Override
public void tick() {
LivingEntity target = this.mob.getTarget();
if(target == null) return;
this.updateFleePosition();
if(this.fleePos != null) {
this.mob.getLookControl().setLookAt(this.fleePos.x, this.fleePos.y, this.fleePos.z);
}
}
private void updateFleePosition() {
LivingEntity target = this.mob.getTarget();
if(target == null) return;
//Vec3 pos = DefaultRandomPos.getPosAway(this.mob, 16, 7, target.position());
//if(pos == null) {
Vec3 revertDirection = this.mob.position().subtract(target.position()).normalize();
Vec3 pos = this.mob.position().add(revertDirection.scale(5.0));
//}
this.fleePos = pos;
this.mob.getNavigation().moveTo(this.fleePos.x, this.fleePos.y, this.fleePos.z, 1);
}
@Override
public void stop() {
this.fleePos = null;
this.mob.getNavigation().stop();
}
}
@@ -0,0 +1,17 @@
package com.lzxnone.terraria.goal;
import com.lzxnone.terraria.LzxnoneTerraria;
import net.minecraft.world.entity.PathfinderMob;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent;
@EventBusSubscriber(modid = LzxnoneTerraria.MODID)
public class GoalManager {
@SubscribeEvent
public static void onEntityJoin(EntityJoinLevelEvent event) {
if(!event.getLevel().isClientSide() && event.getEntity() instanceof PathfinderMob mob) {
mob.goalSelector.addGoal(0, new ConfusedEffectGoal(mob));
}
}
}
@@ -0,0 +1,10 @@
package com.lzxnone.terraria.item;
import net.neoforged.neoforge.event.entity.player.AttackEntityEvent;
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
public interface IItemWaveBehavior {
default void onLeftClickAir(PlayerInteractEvent.LeftClickEmpty event) {}
default void onLeftClickBlock(PlayerInteractEvent.LeftClickBlock event) {}
default void onAttackEntity(AttackEntityEvent event) {}
}
@@ -0,0 +1,23 @@
package com.lzxnone.terraria.item;
import com.lzxnone.terraria.item.weapon.melee.BeeKeeper;
import java.util.HashMap;
import java.util.Map;
public class ItemWaveBehaviors {
private static final Map<String, IItemWaveBehavior> BEHAVIORS = new HashMap<>();
public static final String DEFAULT = "default";
public static final String BEE_KEEPER = "bee_keeper";
static {
BEHAVIORS.put(DEFAULT, new IItemWaveBehavior() {
});
BEHAVIORS.put(BEE_KEEPER, BeeKeeper.ITEM_WAVE_BEHAVIOR);
}
public static IItemWaveBehavior getBehavior(String id) {
return BEHAVIORS.getOrDefault(id, BEHAVIORS.get(DEFAULT));
}
}
@@ -0,0 +1,30 @@
package com.lzxnone.terraria.item;
import com.lzxnone.terraria.LzxnoneTerraria;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.entity.player.AttackEntityEvent;
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
@EventBusSubscriber(modid = LzxnoneTerraria.MODID)
public class ModItemEvents {
@SubscribeEvent
public static void onLeftClickAir(PlayerInteractEvent.LeftClickEmpty event) {
ResourceLocation id = BuiltInRegistries.ITEM.getKey(event.getEntity().getMainHandItem().getItem());
if(id.getNamespace().equals("lzxnoneterraria")) ItemWaveBehaviors.getBehavior(id.getPath()).onLeftClickAir(event);
}
@SubscribeEvent
public static void onLeftClickBlock(PlayerInteractEvent.LeftClickBlock event) {
ResourceLocation id = BuiltInRegistries.ITEM.getKey(event.getEntity().getMainHandItem().getItem());
if(id.getNamespace().equals("lzxnoneterraria")) ItemWaveBehaviors.getBehavior(id.getPath()).onLeftClickBlock(event);
}
@SubscribeEvent
public static void onAttackEntity(AttackEntityEvent event) {
ResourceLocation id = BuiltInRegistries.ITEM.getKey(event.getEntity().getMainHandItem().getItem());
if(id.getNamespace().equals("lzxnoneterraria")) ItemWaveBehaviors.getBehavior(id.getPath()).onAttackEntity(event);
}
}
@@ -0,0 +1,40 @@
package com.lzxnone.terraria.item;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.item.projectile.EnchantedSwordBeam;
import com.lzxnone.terraria.item.projectile.SeedlerNut;
import com.lzxnone.terraria.item.projectile.SeedlerThorn;
import com.lzxnone.terraria.item.projectile.StarfuryStar;
import com.lzxnone.terraria.item.weapon.melee.*;
import net.minecraft.world.item.Item;
import net.neoforged.neoforge.registries.DeferredItem;
import net.neoforged.neoforge.registries.DeferredRegister;
public class ModItems {
public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(LzxnoneTerraria.MODID);
public static final DeferredItem<CopperShortsword> COPPER_SHORTSWORD = ITEMS.register("copper_shortsword", CopperShortsword::new);
public static final DeferredItem<EnchantedSword> ENCHANTED_SWORD = ITEMS.register("enchanted_sword", EnchantedSword::new);
public static final DeferredItem<Item> BEE_KEEPER = ITEMS.register("bee_keeper", BeeKeeper::new);
public static final DeferredItem<Item> STARFURY = ITEMS.register("starfury", Starfury::new);
public static final DeferredItem<Item> SEEDLER = ITEMS.register("seedler", Seedler::new);
public static final DeferredItem<Item> INFLUX_WAVER = ITEMS.register("influx_waver",
() -> new Item(new Item.Properties()));
public static final DeferredItem<Item> MEOWMERE = ITEMS.register("meowmere",
() -> new Item(new Item.Properties()));
public static final DeferredItem<Item> STAR_WRATH = ITEMS.register("star_wrath",
() -> new Item(new Item.Properties()));
public static final DeferredItem<Item> TERRA_BLADE = ITEMS.register("terra_blade",
() -> new Item(new Item.Properties()));
public static final DeferredItem<Item> THE_HORSEMANS_BLADE = ITEMS.register("the_horsemans_blade",
() -> new Item(new Item.Properties()));
public static final DeferredItem<Item> ZENITH = ITEMS.register("zenith",
() -> new Item(new Item.Properties()));
//弹射物
public static final DeferredItem<EnchantedSwordBeam> ENCHANTED_SWORD_BEAM = ITEMS.register("enchanted_sword_beam", EnchantedSwordBeam::new);
public static final DeferredItem<StarfuryStar> STARFURY_STAR = ITEMS.register("starfury_star", StarfuryStar::new);
public static final DeferredItem<SeedlerNut> SEEDLER_NUT = ITEMS.register("seedler_nut", SeedlerNut::new);
public static final DeferredItem<SeedlerThorn> SEEDLER_THORN = ITEMS.register("seedler_thorn", SeedlerThorn::new);
}
@@ -0,0 +1,58 @@
package com.lzxnone.terraria.item;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.block.Block;
public enum ModTiers implements Tier {
COPPER(BlockTags.INCORRECT_FOR_IRON_TOOL, 200, 4.0F, 1.0F, 5, Ingredient.EMPTY),
ENCHANTED_SWORD(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 500, 6.0F, 3.0F, 14, Ingredient.EMPTY);
private final TagKey<Block> tag;
private final int uses;
private final float speed;
private final float attackDamageBonus;
private final int enchantmentValue;
private final Ingredient repairIngredient;
ModTiers(TagKey<Block> tag, int uses, float speed, float attackDamageBonus, int enchantmentValue, Ingredient repairIngredient) {
this.tag = tag;
this.uses = uses;
this.speed = speed;
this.attackDamageBonus = attackDamageBonus;
this.enchantmentValue = enchantmentValue;
this.repairIngredient = repairIngredient;
}
@Override
public int getUses() {
return this.uses;
}
@Override
public float getSpeed() {
return this.speed;
}
@Override
public float getAttackDamageBonus() {
return this.attackDamageBonus;
}
@Override
public TagKey<Block> getIncorrectBlocksForDrops() {
return this.tag;
}
@Override
public int getEnchantmentValue() {
return this.enchantmentValue;
}
@Override
public Ingredient getRepairIngredient() {
return this.repairIngredient;
}
}
@@ -0,0 +1,9 @@
package com.lzxnone.terraria.item.projectile;
import net.minecraft.world.item.Item;
public class EnchantedSwordBeam extends Item {
public EnchantedSwordBeam() {
super(new Item.Properties());
}
}
@@ -0,0 +1,9 @@
package com.lzxnone.terraria.item.projectile;
import net.minecraft.world.item.Item;
public class SeedlerNut extends Item{
public SeedlerNut() {
super(new Item.Properties());
}
}
@@ -0,0 +1,9 @@
package com.lzxnone.terraria.item.projectile;
import net.minecraft.world.item.Item;
public class SeedlerThorn extends Item {
public SeedlerThorn() {
super(new Item.Properties());
}
}
@@ -0,0 +1,9 @@
package com.lzxnone.terraria.item.projectile;
import net.minecraft.world.item.Item;
public class StarfuryStar extends Item {
public StarfuryStar() {
super(new Item.Properties());
}
}
@@ -0,0 +1,67 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.effect.ModEffects;
import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.summon.BeeSummon;
import com.lzxnone.terraria.item.IItemWaveBehavior;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.neoforged.neoforge.event.entity.player.AttackEntityEvent;
public class BeeKeeper extends SwordItem {
public BeeKeeper() {
super(Tiers.IRON, new Item.Properties().attributes(ItemAttributeModifiers.builder()
.add(Attributes.ATTACK_DAMAGE,
new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_damage"), 5, AttributeModifier.Operation.ADD_VALUE),
EquipmentSlotGroup.MAINHAND)
.add(Attributes.ATTACK_SPEED,
new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_speed"), -2.4, AttributeModifier.Operation.ADD_VALUE),
EquipmentSlotGroup.MAINHAND)
.build()
));
}
public static final IItemWaveBehavior ITEM_WAVE_BEHAVIOR = new IItemWaveBehavior() {
@Override
public void onAttackEntity(AttackEntityEvent event) {
Player player = event.getEntity();
if(!player.level().isClientSide()) {
ItemStack itemStack = player.getMainHandItem();
if(itemStack.isEmpty()) return;
Item item = itemStack.getItem();
if(item instanceof BeeKeeper && !player.getCooldowns().isOnCooldown(item)) {
Entity target = event.getTarget();
if(target instanceof LivingEntity livingTarget) {
livingTarget.addEffect(new MobEffectInstance(
ModEffects.CONFUSED,
40,
0
));
}
int count = player.level().random.nextInt(3) + 1;
while(count-- > 0) {
BeeSummon bee = ModEntities.BEE_SUMMON.get().create(player.level());
if(bee != null) {
bee.owner = player.getUUID();
bee.setPos(target.position());
player.level().addFreshEntity(bee);
}
}
player.getCooldowns().addCooldown(item, 40);
}
}
}
};
}
@@ -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.SwordItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.component.ItemAttributeModifiers;
public class CopperShortsword extends SwordItem {
public CopperShortsword() {
super(Tiers.STONE, new Item.Properties().attributes(ItemAttributeModifiers.builder()
.add(Attributes.ATTACK_DAMAGE,
new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_damage"), 2, AttributeModifier.Operation.ADD_VALUE),
EquipmentSlotGroup.MAINHAND)
.add(Attributes.ATTACK_SPEED,
new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_speed"), -1, AttributeModifier.Operation.ADD_VALUE),
EquipmentSlotGroup.MAINHAND)
.build()
));
}
}
@@ -0,0 +1,160 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.projectile.IProjectileBehavior;
import com.lzxnone.terraria.entity.projectile.ProjectileBehaviors;
import com.lzxnone.terraria.entity.projectile.TextureProjectile;
import com.lzxnone.terraria.item.ModItems;
import com.lzxnone.terraria.particle.DustParticleOptions;
import com.lzxnone.terraria.particle.ModParticles;
import com.lzxnone.terraria.utils.MathUtil;
import net.minecraft.core.component.DataComponents;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3;
import org.joml.Vector3f;
public class EnchantedSword extends SwordItem {
public EnchantedSword() {
super(Tiers.IRON, new Item.Properties().attributes(ItemAttributeModifiers.builder()
.add(Attributes.ATTACK_DAMAGE,
new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_damage"), 4,
AttributeModifier.Operation.ADD_VALUE),
EquipmentSlotGroup.MAINHAND)
.add(Attributes.ATTACK_SPEED,
new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_speed"), -2.4,
AttributeModifier.Operation.ADD_VALUE),
EquipmentSlotGroup.MAINHAND)
.build()
));
}
public static final IProjectileBehavior PROJECTILE_BEHAVIOR = new IProjectileBehavior() {
@Override
public void onMoving(TextureProjectile projectile) {
projectile.level().addParticle(
ModParticles.COLORFUL_PARTICLE,
projectile.getX(), projectile.getY(), projectile.getZ(),
(Math.random() * 2 - 1) * 0.1, (Math.random() * 2 - 1) * 0.1, (Math.random() * 2 - 1) * 0.1
);
}
@Override
public void onHitEntity(TextureProjectile projectile, EntityHitResult result) {
if(!projectile.level().isClientSide()) {
if(result.getEntity() instanceof LivingEntity target) {
if(target.hurt(projectile.damageSources().thrown(projectile, projectile.getOwner()), 5.5f)) {
((ServerLevel) projectile.level()).sendParticles(
ModParticles.COLORFUL_PARTICLE,
projectile.getX(), projectile.getY(), projectile.getZ(),
25,
0.2, 0.2, 0.2,
0.2
);
projectile.discard();
}
}
}
}
@Override
public void onHitBlock(TextureProjectile projectile, BlockHitResult result) {
if(projectile.level().isClientSide()) return;
if(!projectile.level().getBlockState(result.getBlockPos()).getCollisionShape(projectile.level(), result.getBlockPos()).isEmpty()) {
projectile.discard();
}
}
};
@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
ItemStack stack = player.getItemInHand(hand);
if(!level.isClientSide()) {
Vec3 lookVec = player.getLookAngle();
Vector3f[] dirs = MathUtil.computeProjectileDir(
MathUtil.toVector3f(lookVec)
);
TextureProjectile projectile = new TextureProjectile(ModEntities.TEXTURE_PROJECTILE.get(), level);
projectile.setOwner(player);
Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ());
projectile.setPos(pos);
projectile.getEntityData().set(TextureProjectile.BEHAVIOR, ProjectileBehaviors.ENCHANTED_SWORD_BEAM);
projectile.getEntityData().set(TextureProjectile.ORIGIN, MathUtil.toVector3f(pos));
projectile.getEntityData().set(TextureProjectile.DIRECTION, dirs[0]);
projectile.getEntityData().set(TextureProjectile.UP, dirs[1]);
projectile.getEntityData().set(TextureProjectile.RIGHT, dirs[2]);
projectile.getEntityData().set(TextureProjectile.ITEM, new ItemStack(ModItems.ENCHANTED_SWORD_BEAM.get()));
projectile.getEntityData().set(TextureProjectile.SCALE_X, 0.5f);
projectile.getEntityData().set(TextureProjectile.SCALE_Y, 0.5f);
projectile.getEntityData().set(TextureProjectile.RXP, 90);
projectile.getEntityData().set(TextureProjectile.RZP, 45);
projectile.getEntityData().set(TextureProjectile.RYPS, 10);
projectile.getEntityData().set(TextureProjectile.GLOW, true);
projectile.getEntityData().set(TextureProjectile.EXPRESSION_Z, "t");
projectile.setDeltaMovement(MathUtil.toVec3(dirs[0]));
level.addFreshEntity(projectile);
((ServerLevel) player.level()).sendParticles(
ModParticles.COLORFUL_PARTICLE,
player.getX(), player.getY() + 0.5, player.getZ(),
25,
0.2, 0.2, 0.2,
0.2
);
player.level().playSound(null, player, ModSounds.BEAM.get(), SoundSource.PLAYERS, 4.0F, 1.0F);
}
player.getCooldowns().addCooldown(stack.getItem(), 15);
return InteractionResultHolder.sidedSuccess(stack, level.isClientSide());
}
@Override
public void inventoryTick(ItemStack stack, Level level, net.minecraft.world.entity.Entity entity, int slotId, boolean isSelected) {
super.inventoryTick(stack, level, entity, slotId, isSelected);
if(isSelected && entity instanceof Player player) {
boolean currentlyOnCooldown = player.getCooldowns().isOnCooldown(this);
boolean wasOnCooldown = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
.copyTag().getBoolean("WasOnCooldown");
if(wasOnCooldown && !currentlyOnCooldown) {
if(level.isClientSide()) {
player.playSound(ModSounds.MAX_MANA.get(), 4.0F, 1.0F);
}else {
((ServerLevel) player.level()).sendParticles(
ModParticles.MAX_MANA_PARTICLE,
player.getX(), player.getY() + 0.5, player.getZ(),
5,
0.2, 0.2, 0.2,
0.2
);
}
}
CustomData.update(DataComponents.CUSTOM_DATA, stack,
tag -> tag.putBoolean("WasOnCooldown", currentlyOnCooldown));
}
}
}
@@ -0,0 +1,303 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.projectile.IProjectileBehavior;
import com.lzxnone.terraria.entity.projectile.ProjectileBehaviors;
import com.lzxnone.terraria.entity.projectile.TextureProjectile;
import com.lzxnone.terraria.item.ModItems;
import com.lzxnone.terraria.particle.ModParticles;
import com.lzxnone.terraria.utils.MathUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3;
import net.objecthunter.exp4j.ExpressionBuilder;
import org.joml.Vector3f;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
public class Seedler extends SwordItem {
public Seedler() {
super(Tiers.DIAMOND, new Item.Properties().attributes(ItemAttributeModifiers.builder()
.add(Attributes.ATTACK_DAMAGE,
new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_damage"), 8, AttributeModifier.Operation.ADD_VALUE),
EquipmentSlotGroup.MAINHAND)
.add(Attributes.ATTACK_SPEED,
new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_speed"), -2.4, AttributeModifier.Operation.ADD_VALUE),
EquipmentSlotGroup.MAINHAND)
.build()
));
}
public static final double GRAVITY = 0.1; //重力
public static final double NORMAL_DAMPING = 0.6;
public static final double TANGENT_DAMPING = 0.9;
public static final IProjectileBehavior NUT_PROJECTILE_BEHAVIOR = new IProjectileBehavior() {
@Override
public void onHitBlock(TextureProjectile projectile, BlockHitResult result) {
if(projectile.level().isClientSide()) return;
int age = projectile.getEntityData().get(TextureProjectile.AGE);
int currentLifetime = projectile.getEntityData().get(TextureProjectile.LIFETIME);
int remainingLifetime = currentLifetime - age;
if(remainingLifetime <= 0) {
this.onDied(projectile);
return;
}
CompoundTag customData = projectile.getEntityData().get(TextureProjectile.CUSTOM_DATA);
double oldVy = customData.getDouble("vy");
double vz = customData.getDouble("vz");
double vy = oldVy - GRAVITY * age;
Vector3f dir = projectile.getEntityData().get(TextureProjectile.DIRECTION);
Vector3f up = projectile.getEntityData().get(TextureProjectile.UP);
Vec3 velocity = new Vec3(
vy * up.x() + vz * dir.x(),
vy * up.y() + vz * dir.y(),
vy * up.z() + vz * dir.z()
);
Vec3 normal = Vec3.atLowerCornerOf(result.getDirection().getNormal());
Vec3 reflected = velocity.subtract(normal.scale(2 * velocity.dot(normal)));
double normalMag = reflected.dot(normal);
Vec3 tangentDir = reflected.subtract(normal.scale(normalMag));
double tangentMag = tangentDir.length();
Vec3 finalVelocity = normal.scale(normalMag * NORMAL_DAMPING);
if(tangentMag > 0.0001) {
finalVelocity = finalVelocity.add(tangentDir.normalize().scale(tangentMag * TANGENT_DAMPING));
}
double newVz = Math.sqrt(finalVelocity.x * finalVelocity.x + finalVelocity.z * finalVelocity.z);
double newVy = finalVelocity.y;
boolean isBounced = false;
//竖直弹射时
if(newVy < 0.1 && newVy > 0.0001) {
newVy = 0;
String newExprY = String.format(Locale.US, "-%.4f*t*t", GRAVITY * 0.5);
projectile.getEntityData().set(TextureProjectile.EXPRESSION_Y, newExprY);
projectile.exprY = new ExpressionBuilder(newExprY).variables("t").build();
}else if(newVy >= 0.1) {
String newExprY = String.format(Locale.US, "%.3f*t - %.4f*t*t", newVy, GRAVITY * 0.5);
projectile.getEntityData().set(TextureProjectile.EXPRESSION_Y, newExprY);
projectile.exprY = new ExpressionBuilder(newExprY).variables("t").build();
}
if(Math.abs(normal.y) >= 0.999 && newVy >= 0.1) isBounced = true;
//水平弹射时
if(newVz < 0.1 && newVz > 0.0001) {
newVz = 0;
projectile.getEntityData().set(TextureProjectile.EXPRESSION_Z, "0");
projectile.exprZ = new ExpressionBuilder("0").variables("t").build();
Vec3 reflectedH = new Vec3(reflected.x, 0, reflected.z).normalize();
Vector3f[] newDirs = MathUtil.computeProjectileDir(MathUtil.toVector3f(reflectedH));
projectile.getEntityData().set(TextureProjectile.DIRECTION, newDirs[0]);
projectile.getEntityData().set(TextureProjectile.RIGHT, newDirs[2]);
}else if(newVz >= 0.1) {
String newExprZ = String.format(Locale.US, "%.3f*t", newVz);
projectile.getEntityData().set(TextureProjectile.EXPRESSION_Z, newExprZ);
projectile.exprZ = new ExpressionBuilder(newExprZ).variables("t").build();
Vec3 reflectedH = new Vec3(reflected.x, 0, reflected.z).normalize();
Vector3f[] newDirs = MathUtil.computeProjectileDir(MathUtil.toVector3f(reflectedH));
projectile.getEntityData().set(TextureProjectile.DIRECTION, newDirs[0]);
projectile.getEntityData().set(TextureProjectile.RIGHT, newDirs[2]);
}
if((Math.abs(normal.x) >= 0.999 || Math.abs(normal.z) >= 0.999) && newVz >= 0.1) isBounced = true;
Vec3 hitPos = result.getLocation();
Vec3 offsetPos = hitPos.add(normal.scale(isBounced ? 0.1 : 0));
projectile.getEntityData().set(TextureProjectile.ORIGIN, MathUtil.toVector3f(offsetPos));
projectile.getEntityData().set(TextureProjectile.AGE, 0);
projectile.getEntityData().set(TextureProjectile.LIFETIME, remainingLifetime);
customData.putDouble("vz", newVz);
customData.putDouble("vy", newVy);
projectile.getEntityData().set(TextureProjectile.CUSTOM_DATA, customData);
projectile.setPos(offsetPos);
projectile.positionOverridden = true;
}
@Override
public void onDied(TextureProjectile projectile) {
if(!projectile.level().isClientSide()) {
Vec3 pos = projectile.position();
Level level = projectile.level();
((ServerLevel) level).sendParticles(
ModParticles.EXPLODE_PARTICLE.get(),
pos.x, pos.y, pos.z, 1, 0.2, 0.2, 0.2, 0.2
);
((ServerLevel) level).sendParticles(
ModParticles.EXPLODE_FLAME_PARTICLE,
pos.x, pos.y, pos.z, 10, 0.2, 0.2, 0.2, 0.2
);
((ServerLevel) level).sendParticles(
ModParticles.SMOKE_PARTICLE,
pos.x, pos.y, pos.z, 10, 0.2, 0.2, 0.2, 0.2
);
level.playSound(null, pos.x, pos.y, pos.z,
ModSounds.BOOM.get(), SoundSource.PLAYERS, 4.0F, 1.0F);
Entity owner = projectile.getOwner();
List<LivingEntity> targets = level.getEntitiesOfClass(
LivingEntity.class,
AABB.ofSize(pos, 64, 64, 64),
e -> e.isAlive() && e != owner && !e.isSpectator()
);
targets.sort(Comparator.comparingDouble(e -> e.distanceToSqr(pos)));
int count = projectile.getRandom().nextInt(4) + 4;
for(int i = 0; i < count; i++) {
Vec3 dir;
if(i < targets.size()) {
Vec3 tPos = targets.get(i).getEyePosition();
dir = new Vec3(tPos.x - pos.x, tPos.y - pos.y, tPos.z - pos.z).normalize();
}else {
float yaw = projectile.getRandom().nextFloat() * (float)Math.PI * 2;
float pitch = (projectile.getRandom().nextFloat() - 0.5f) * 0.5f;
dir = new Vec3(-Math.sin(yaw) * Math.cos(pitch), Math.sin(pitch),
Math.cos(yaw) * Math.cos(pitch));
}
Vector3f[] dirs = MathUtil.computeProjectileDir(MathUtil.toVector3f(dir));
TextureProjectile proj = new TextureProjectile(ModEntities.TEXTURE_PROJECTILE.get(), level);
proj.setOwner(owner);
proj.setPos(pos);
proj.getEntityData().set(TextureProjectile.BEHAVIOR, ProjectileBehaviors.SEEDLER_THORN);
proj.getEntityData().set(TextureProjectile.ORIGIN, MathUtil.toVector3f(pos));
proj.getEntityData().set(TextureProjectile.DIRECTION, dirs[0]);
proj.getEntityData().set(TextureProjectile.UP, dirs[1]);
proj.getEntityData().set(TextureProjectile.RIGHT, dirs[2]);
proj.getEntityData().set(TextureProjectile.ITEM, new ItemStack(ModItems.SEEDLER_THORN.get()));
proj.getEntityData().set(TextureProjectile.SCALE_X, 0.5f);
proj.getEntityData().set(TextureProjectile.SCALE_Y, 0.5f);
proj.getEntityData().set(TextureProjectile.RXP, 90);
proj.getEntityData().set(TextureProjectile.LIFETIME, 30);
proj.getEntityData().set(TextureProjectile.EXPRESSION_Z, "t*2");
proj.setDeltaMovement(MathUtil.toVec3(dirs[0]));
level.addFreshEntity(proj);
}
projectile.discard();
}
}
@Override
public void onHitEntity(TextureProjectile projectile, EntityHitResult result) {
if(!projectile.level().isClientSide()) {
if(result.getEntity() instanceof LivingEntity target) {
this.onDied(projectile);
}
}
}
};
public static final IProjectileBehavior THORN_PROJECTILE_BEHAVIOR = new IProjectileBehavior() {
@Override
public void onMoving(TextureProjectile projectile) {
projectile.level().addParticle(
ModParticles.SEEDLER_THORN_PARTICLE.get(),
projectile.getX(), projectile.getY(), projectile.getZ(),
0, 0, 0
);
}
@Override
public void onHitEntity(TextureProjectile projectile, EntityHitResult result) {
if(!projectile.level().isClientSide()) {
if(result.getEntity() instanceof LivingEntity target) {
if(target.hurt(projectile.damageSources().thrown(projectile, projectile.getOwner()), 7f)) projectile.discard();
}
}
}
@Override
public void onHitBlock(TextureProjectile projectile, BlockHitResult result) {
if(projectile.level().isClientSide()) return;
if(!projectile.level().getBlockState(result.getBlockPos()).getCollisionShape(projectile.level(), result.getBlockPos()).isEmpty()) {
projectile.discard();
}
}
};
@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
ItemStack stack = player.getItemInHand(hand);
if(!level.isClientSide()) {
Vec3 lookVec = player.getLookAngle();
float yaw = player.getYRot();
Vec3 horizontalDir = new Vec3(
-Math.sin(yaw * Math.PI / 180),
0,
Math.cos(yaw * Math.PI / 180)
);
Vector3f[] dirs = MathUtil.computeProjectileDir(
MathUtil.toVector3f(horizontalDir)
);
double vz = Math.sqrt(lookVec.x * lookVec.x + lookVec.z * lookVec.z) * 1.5;
double vy = lookVec.y * 1.5;
String exprZ = String.format(Locale.US, "%.3f*t", vz);
String exprY = String.format(Locale.US, "%.3f*t - %.4f*t*t", vy, GRAVITY * 0.5);
CompoundTag customData = new CompoundTag();
customData.putDouble("vz", vz);
customData.putDouble("vy", vy);
TextureProjectile projectile = new TextureProjectile(ModEntities.TEXTURE_PROJECTILE.get(), level);
projectile.setOwner(player);
Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ());
projectile.setPos(pos);
projectile.getEntityData().set(TextureProjectile.BEHAVIOR, ProjectileBehaviors.SEEDLER_NUT);
projectile.getEntityData().set(TextureProjectile.ORIGIN, MathUtil.toVector3f(pos));
projectile.getEntityData().set(TextureProjectile.DIRECTION, dirs[0]);
projectile.getEntityData().set(TextureProjectile.UP, dirs[1]);
projectile.getEntityData().set(TextureProjectile.RIGHT, dirs[2]);
projectile.getEntityData().set(TextureProjectile.ITEM, new ItemStack(ModItems.SEEDLER_NUT.get()));
projectile.getEntityData().set(TextureProjectile.SCALE_X, 0.5f);
projectile.getEntityData().set(TextureProjectile.SCALE_Y, 0.5f);
projectile.getEntityData().set(TextureProjectile.RXPS, 10);
projectile.getEntityData().set(TextureProjectile.LIFETIME, (int) (7 + Math.random() * 36));
projectile.getEntityData().set(TextureProjectile.EXPRESSION_Z, exprZ);
projectile.getEntityData().set(TextureProjectile.EXPRESSION_Y, exprY);
projectile.getEntityData().set(TextureProjectile.CUSTOM_DATA, customData);
projectile.setDeltaMovement(MathUtil.toVec3(dirs[0]));
level.addFreshEntity(projectile);
}
player.getCooldowns().addCooldown(stack.getItem(), 10);
return InteractionResultHolder.sidedSuccess(stack, level.isClientSide());
}
}
@@ -0,0 +1,224 @@
package com.lzxnone.terraria.item.weapon.melee;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.lzxnone.terraria.ModSounds;
import com.lzxnone.terraria.entity.ModEntities;
import com.lzxnone.terraria.entity.projectile.IProjectileBehavior;
import com.lzxnone.terraria.entity.projectile.ProjectileBehaviors;
import com.lzxnone.terraria.entity.projectile.TextureProjectile;
import com.lzxnone.terraria.item.ModItems;
import com.lzxnone.terraria.particle.ModParticles;
import com.lzxnone.terraria.utils.MathUtil;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ProjectileUtil;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.*;
import org.joml.Vector3f;
public class Starfury extends SwordItem {
public Starfury() {
super(Tiers.IRON, new Item.Properties().attributes(ItemAttributeModifiers.builder()
.add(Attributes.ATTACK_DAMAGE,
new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_damage"), 5, AttributeModifier.Operation.ADD_VALUE),
EquipmentSlotGroup.MAINHAND)
.add(Attributes.ATTACK_SPEED,
new AttributeModifier(ResourceLocation.fromNamespaceAndPath(LzxnoneTerraria.MODID, "base_attack_speed"), -2.4, AttributeModifier.Operation.ADD_VALUE),
EquipmentSlotGroup.MAINHAND)
.build()
));
}
public static final IProjectileBehavior PROJECTILE_BEHAVIOR = new IProjectileBehavior() {
@Override
public void onMoving(TextureProjectile projectile) {
projectile.level().addParticle(
ModParticles.STAR_PARTICLE.get(),
projectile.getX(), projectile.getY(), projectile.getZ(),
(Math.random() * 2 - 1) * 0.1, (Math.random() * 2 - 1) * 0.1, (Math.random() * 2 - 1) * 0.1
);
}
@Override
public void onHitEntity(TextureProjectile projectile, EntityHitResult result) {
if(!projectile.level().isClientSide()) {
if(result.getEntity() instanceof LivingEntity target) {
target.hurt(projectile.damageSources().thrown(projectile, projectile.getOwner()), 8f);
}
}
}
@Override
public void onHitBlock(TextureProjectile projectile, BlockHitResult result) {
if(projectile.level().isClientSide()) return;
CompoundTag customData = projectile.getEntityData().get(TextureProjectile.CUSTOM_DATA);
if(!customData.contains("targetLifetime")) return;
int targetLifetime = customData.getInt("targetLifetime");
int age = projectile.getEntityData().get(TextureProjectile.AGE);
if(age < targetLifetime + 1) {
EntityHitResult entityHit = ProjectileUtil.getEntityHitResult(
projectile.level(),
projectile,
projectile.position(),
projectile.position().add(projectile.getDeltaMovement()),
projectile.getBoundingBox()
.expandTowards(projectile.getDeltaMovement())
.inflate(1.0),
entity -> !entity.isSpectator() && entity.isPickable() && entity != projectile.getOwner()
);
if(entityHit != null) {
this.onHitEntity(projectile, entityHit);
}
return;
}
if(!projectile.level().getBlockState(result.getBlockPos()).getCollisionShape(projectile.level(), result.getBlockPos()).isEmpty()) {
((ServerLevel) projectile.level()).sendParticles(
ModParticles.STAR_PARTICLE.get(),
projectile.getX(), projectile.getY(), projectile.getZ(),
25,
0.2, 0.2, 0.2,
0.2
);
projectile.level().playSound(null, projectile, ModSounds.STAR_COLLIDE.get(), SoundSource.PLAYERS, 4.0F, 1.0F);
projectile.discard();
}
}
@Override
public void onDied(TextureProjectile projectile) {
if(!projectile.level().isClientSide()) {
projectile.level().playSound(null, projectile, ModSounds.STAR_COLLIDE.get(), SoundSource.PLAYERS, 4.0F, 1.0F);
projectile.discard();
}
}
};
@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
ItemStack itemstack = player.getItemInHand(hand);
if(!level.isClientSide() && level instanceof ServerLevel serverLevel) {
Vec3 targetPos = getTargetPosition(player, serverLevel, 24.0D);
double spawnHeight = 20.0D;
double slantOffset = 2.0D;
Vec3 spawnPos = new Vec3(
targetPos.x + slantOffset * (Math.random() * 2 - 1),
targetPos.y + spawnHeight,
targetPos.z + slantOffset * (Math.random() * 2 - 1)
);
Vector3f[] dirs = MathUtil.computeProjectileDir(
MathUtil.toVector3f(new Vec3(targetPos.x - spawnPos.x, targetPos.y - spawnPos.y, targetPos.z - spawnPos.z))
);
TextureProjectile projectile = new TextureProjectile(ModEntities.TEXTURE_PROJECTILE.get(), level);
projectile.setOwner(player);
projectile.setPos(spawnPos);
projectile.getEntityData().set(TextureProjectile.BEHAVIOR, ProjectileBehaviors.STARFURY_STAR);
projectile.getEntityData().set(TextureProjectile.ORIGIN, MathUtil.toVector3f(spawnPos));
projectile.getEntityData().set(TextureProjectile.ITEM, new ItemStack(ModItems.STARFURY_STAR.get()));
projectile.getEntityData().set(TextureProjectile.LIFETIME, 300);
projectile.getEntityData().set(TextureProjectile.DIRECTION, dirs[0]);
projectile.getEntityData().set(TextureProjectile.UP, dirs[1]);
projectile.getEntityData().set(TextureProjectile.RIGHT, dirs[2]);
projectile.getEntityData().set(TextureProjectile.SCALE_X, 1f);
projectile.getEntityData().set(TextureProjectile.SCALE_Y, 2f);
projectile.getEntityData().set(TextureProjectile.GLOW, true);
projectile.getEntityData().set(TextureProjectile.RXP, 90);
projectile.getEntityData().set(TextureProjectile.RZP, 90);
projectile.getEntityData().set(TextureProjectile.EXPRESSION_Z, "t*2");
CompoundTag customData = new CompoundTag();
customData.putInt("targetLifetime", (int) Math.floor(targetPos.distanceTo(spawnPos) / 2.0D));
projectile.getEntityData().set(TextureProjectile.CUSTOM_DATA, customData);
projectile.setDeltaMovement(MathUtil.toVec3(dirs[0]));
level.addFreshEntity(projectile);
((ServerLevel) player.level()).sendParticles(
ModParticles.STAR_PARTICLE.get(),
player.getX(), player.getY() + 0.5, player.getZ(),
25,
0.2, 0.2, 0.2,
0.2
);
player.level().playSound(null, player, ModSounds.STAR_FALL.get(), SoundSource.PLAYERS, 4.0F, 1.0F);
}
player.getCooldowns().addCooldown(this, 13);
return InteractionResultHolder.sidedSuccess(itemstack, level.isClientSide());
}
private Vec3 getTargetPosition(Player player, Level level, double maxRange) {
Vec3 eyePos = player.getEyePosition(1.0F);
Vec3 lookVec = player.getLookAngle();
Vec3 maxRangeEnd = eyePos.add(lookVec.scale(maxRange));
BlockHitResult blockHit = level.clip(new ClipContext(
eyePos, maxRangeEnd,
ClipContext.Block.COLLIDER,
ClipContext.Fluid.NONE,
player
));
Vec3 finalTarget = maxRangeEnd;
if(blockHit.getType() != HitResult.Type.MISS) {
finalTarget = blockHit.getLocation();
}
AABB searchBox = player.getBoundingBox().expandTowards(lookVec.scale(maxRange)).inflate(1.0D);
EntityHitResult entityHit = ProjectileUtil.getEntityHitResult(
level, player, eyePos, finalTarget, searchBox,
entity -> !entity.isSpectator() && entity.isPickable() && entity != player
);
if(entityHit != null) {
finalTarget = entityHit.getLocation();
}
return finalTarget;
}
@Override
public void inventoryTick(ItemStack stack, Level level, net.minecraft.world.entity.Entity entity, int slotId, boolean isSelected) {
super.inventoryTick(stack, level, entity, slotId, isSelected);
if(isSelected && entity instanceof Player player) {
boolean currentlyOnCooldown = player.getCooldowns().isOnCooldown(this);
boolean wasOnCooldown = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
.copyTag().getBoolean("WasOnCooldown");
if(wasOnCooldown && !currentlyOnCooldown) {
if(level.isClientSide()) {
player.playSound(ModSounds.MAX_MANA.get(), 4.0F, 1.0F);
}else {
((ServerLevel) player.level()).sendParticles(
ModParticles.MAX_MANA_PARTICLE,
player.getX(), player.getY() + 0.5, player.getZ(),
5,
0.2, 0.2, 0.2,
0.2
);
}
}
CustomData.update(DataComponents.CUSTOM_DATA, stack,
tag -> tag.putBoolean("WasOnCooldown", currentlyOnCooldown));
}
}
}
@@ -0,0 +1,120 @@
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 org.joml.Vector3f;
public class DustParticle extends TextureSheetParticle {
private final SpriteSet sprites;
private final float rotSpeed;
private final float baseSize;
public float initSize;
public float initRotSpeed;
public int initLifetime;
public boolean glow;
public Vector3f[] colors = new Vector3f[]{ new Vector3f(1.0F, 1.0F, 1.0F) };
protected DustParticle(ClientLevel level, double x, double y, double z,
double xSpeed, double ySpeed, double zSpeed,
DustParticleOptions options, SpriteSet spriteSet) {
super(level, x, y, z, xSpeed, ySpeed, zSpeed);
this.sprites = spriteSet;
this.friction = 0.9F;
this.gravity = 0.0F;
this.xd = xSpeed;
this.yd = ySpeed;
this.zd = zSpeed;
this.initSize = options.initSize;
this.initRotSpeed = options.initRotSpeed;
this.initLifetime = options.initLifetime;
this.glow = options.glow;
this.baseSize = initSize + (this.random.nextFloat() * initSize);
this.quadSize = baseSize;
this.roll = this.random.nextFloat() * ((float)Math.PI * 2F);
this.oRoll = this.roll;
this.rotSpeed = (this.random.nextFloat() - 0.5F) * initRotSpeed;
this.lifetime = initLifetime + this.random.nextInt(initLifetime / 2);
Vector3f[] palette = options.colors != null ? options.colors : this.colors;
int randomIndex = this.random.nextInt(palette.length);
this.rCol = palette[randomIndex].x;
this.gCol = palette[randomIndex].y;
this.bCol = palette[randomIndex].z;
this.setSpriteFromAge(spriteSet);
}
@Override
public void tick() {
super.tick();
this.oRoll = this.roll;
this.roll += this.rotSpeed;
float lifeRatio = (float) this.age / (float) this.lifetime;
this.quadSize = this.baseSize * (1.0F - lifeRatio);
this.alpha = 1.0F - lifeRatio;
}
@Override
public void render(VertexConsumer buffer, Camera camera, float partialTick) {
if(this.alpha <= 0.01F) return;
float coloredR = this.rCol;
float coloredG = this.gCol;
float coloredB = this.bCol;
this.setSprite(this.sprites.get(0, 1));
this.rCol = coloredR;
this.gCol = coloredG;
this.bCol = coloredB;
super.render(buffer, camera, partialTick);
this.setSprite(this.sprites.get(1, 1));
this.rCol = 1.0F;
this.gCol = 1.0F;
this.bCol = 1.0F;
super.render(buffer, camera, partialTick);
this.rCol = coloredR;
this.gCol = coloredG;
this.bCol = coloredB;
}
@Override
public int getLightColor(float partialTick) {
return glow ? LightTexture.FULL_BRIGHT : super.getLightColor(partialTick);
}
@Override
public ParticleRenderType getRenderType() {
return ModParticleRenderTypes.TRANSLUCENT_EMISSIVE;
}
public static class Provider implements ParticleProvider<DustParticleOptions> {
private final SpriteSet spriteSet;
public Provider(SpriteSet spriteSet) {
this.spriteSet = spriteSet;
}
@Override
public Particle createParticle(DustParticleOptions type, ClientLevel level,
double x, double y, double z,
double xSpeed, double ySpeed, double zSpeed) {
return new DustParticle(level, x, y, z, xSpeed, ySpeed, zSpeed, type, this.spriteSet);
}
}
}
@@ -0,0 +1,89 @@
package com.lzxnone.terraria.particle;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import org.joml.Vector3f;
import java.util.Arrays;
public class DustParticleOptions implements ParticleOptions {
public final float initSize;
public final float initRotSpeed;
public final int initLifetime;
public final boolean glow;
public final Vector3f[] colors;
public DustParticleOptions(float initSize, float initRotSpeed, int initLifetime,
boolean glow, Vector3f[] colors) {
this.initSize = initSize;
this.initRotSpeed = initRotSpeed;
this.initLifetime = initLifetime;
this.glow = glow;
this.colors = colors;
}
public DustParticleOptions() {
this(0.05f, 0.5f, 40, true, null);
}
@Override
public ParticleType<?> getType() {
return ModParticles.DUST_PARTICLE.get();
}
private static final Codec<Vector3f[]> COLORS_CODEC =
Codec.FLOAT.listOf().listOf().xmap(
lists -> lists.stream().map(l -> new Vector3f(l.get(0), l.get(1), l.get(2))).toArray(Vector3f[]::new),
arr -> Arrays.stream(arr).map(c -> java.util.List.of(c.x, c.y, c.z)).toList()
);
public static final MapCodec<DustParticleOptions> CODEC = RecordCodecBuilder.mapCodec(instance ->
instance.group(
Codec.FLOAT.optionalFieldOf("initSize", 0.05f).forGetter(o -> o.initSize),
Codec.FLOAT.optionalFieldOf("initRotSpeed", 0.5f).forGetter(o -> o.initRotSpeed),
Codec.INT.optionalFieldOf("initLifetime", 40).forGetter(o -> o.initLifetime),
Codec.BOOL.optionalFieldOf("glow", true).forGetter(o -> o.glow),
COLORS_CODEC.optionalFieldOf("colors", null).forGetter(o -> o.colors)
).apply(instance, DustParticleOptions::new)
);
public static final StreamCodec<RegistryFriendlyByteBuf, DustParticleOptions> STREAM_CODEC =
new StreamCodec<>() {
@Override
public DustParticleOptions decode(RegistryFriendlyByteBuf buf) {
float size = buf.readFloat();
float rotSpeed = buf.readFloat();
int lifetime = buf.readInt();
boolean glowFlag = buf.readBoolean();
int colorCount = buf.readVarInt();
Vector3f[] cols = colorCount > 0 ? new Vector3f[colorCount] : null;
for (int i = 0; i < colorCount; i++) {
cols[i] = new Vector3f(buf.readFloat(), buf.readFloat(), buf.readFloat());
}
return new DustParticleOptions(size, rotSpeed, lifetime, glowFlag, cols);
}
@Override
public void encode(RegistryFriendlyByteBuf buf, DustParticleOptions opts) {
buf.writeFloat(opts.initSize);
buf.writeFloat(opts.initRotSpeed);
buf.writeInt(opts.initLifetime);
buf.writeBoolean(opts.glow);
if (opts.colors != null) {
buf.writeVarInt(opts.colors.length);
for (Vector3f c : opts.colors) {
buf.writeFloat(c.x);
buf.writeFloat(c.y);
buf.writeFloat(c.z);
}
} else {
buf.writeVarInt(0);
}
}
};
}
@@ -0,0 +1,66 @@
package com.lzxnone.terraria.particle;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.*;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.core.particles.SimpleParticleType;
public class ExplodeParticle extends TextureSheetParticle {
private final float rotSpeed;
private final float baseSize;
protected ExplodeParticle(ClientLevel level, double x, double y, double z,
double xSpeed, double ySpeed, double zSpeed, SpriteSet spriteSet) {
super(level, x, y, z, xSpeed, ySpeed, zSpeed);
this.friction = 0.9F;
this.gravity = 0.0F;
this.xd = xSpeed;
this.yd = ySpeed;
this.zd = zSpeed;
this.baseSize = 0.5F + (this.random.nextFloat() * 0.1F);
this.quadSize = baseSize;
this.roll = this.random.nextFloat() * ((float)Math.PI * 2F);
this.oRoll = this.roll;
this.rotSpeed = (this.random.nextFloat() - 0.5F) * 0.5F;
this.lifetime = 40 + this.random.nextInt(10);
this.pickSprite(spriteSet);
}
@Override
public void tick() {
super.tick();
this.oRoll = this.roll;
this.roll += this.rotSpeed;
float lifeRatio = (float) this.age / (float) this.lifetime;
this.quadSize = this.baseSize * (1.0F - lifeRatio);
this.alpha = 1.0F - lifeRatio;
}
@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 ExplodeParticle(level, x, y, z, xSpeed, ySpeed, zSpeed, this.spriteSet);
}
}
}
@@ -0,0 +1,30 @@
package com.lzxnone.terraria.particle;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.Tesselator;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.ParticleRenderType;
import net.minecraft.client.renderer.texture.TextureManager;
public final class ModParticleRenderTypes {
public static final ParticleRenderType TRANSLUCENT_EMISSIVE = new ParticleRenderType() {
@Override
public BufferBuilder begin(Tesselator tesselator, TextureManager textureManager) {
Minecraft.getInstance().gameRenderer.lightTexture().turnOnLightLayer();
return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT.begin(tesselator, textureManager);
}
@Override
public String toString() {
return "lzxnoneterraria:translucent_emissive";
}
@Override
public boolean isTranslucent() {
return true;
}
};
private ModParticleRenderTypes() {}
}
@@ -0,0 +1,72 @@
package com.lzxnone.terraria.particle;
import com.lzxnone.terraria.LzxnoneTerraria;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.core.registries.Registries;
import net.neoforged.neoforge.registries.DeferredRegister;
import org.joml.Vector3f;
import java.util.function.Supplier;
public class ModParticles {
public static final DeferredRegister<ParticleType<?>> PARTICLE_TYPES =
DeferredRegister.create(Registries.PARTICLE_TYPE, LzxnoneTerraria.MODID);
public static final DustParticleOptions MAX_MANA_PARTICLE = new DustParticleOptions(
0.25f, 0.5f, 40, true, new Vector3f[]{
new Vector3f(0.5F, 0.35F, 0.9F),
}
);
public static final DustParticleOptions SMOKE_PARTICLE = new DustParticleOptions(
0.025f, 0.5f, 40, true, new Vector3f[]{
new Vector3f(0.7F, 0.7F, 0.7F),
}
);
public static final DustParticleOptions EXPLODE_FLAME_PARTICLE = new DustParticleOptions(
0.05f, 0.5f, 40, true, new Vector3f[]{
new Vector3f(1.0F, 0.8F, 0.5F),
new Vector3f(1.0F, 0.5F, 0.0F),
new Vector3f(1.0F, 0.9F, 0.0F),
}
);
public static final DustParticleOptions COLORFUL_PARTICLE = new DustParticleOptions(
0.025f, 0.5f, 40, true, new Vector3f[]{
new Vector3f(0.0F, 1.0F, 1.0F), // 0: 青色 (Cyan)
new Vector3f(0.1F, 0.4F, 1.0F), // 1: 蓝色 (Blue)
new Vector3f(1.0F, 1.0F, 0.6F), // 2: 淡黄 (Light Yellow)
new Vector3f(1.0F, 0.9F, 0.0F), // 3: 黄色 (Yellow)
new Vector3f(0.5F, 1.0F, 0.5F), // 4: 淡绿 (Light Green)
new Vector3f(0.0F, 1.0F, 0.2F), // 5: 绿色 (Green)
new Vector3f(1.0F, 0.6F, 0.8F), // 6: 粉红 (Pink)
new Vector3f(1.0F, 0.0F, 1.0F), // 7: 品红 (Magenta)
new Vector3f(1.0F, 0.8F, 0.5F), // 8: 淡橙 (Light Orange)
new Vector3f(1.0F, 0.5F, 0.0F), // 9: 橙色 (Orange)
new Vector3f(0.7F, 0.7F, 0.7F) // 10: 淡灰 (Light Gray)
}
);
public static final Supplier<ParticleType<DustParticleOptions>> DUST_PARTICLE =
PARTICLE_TYPES.register("dust_particle", () -> new ParticleType<>(false) {
@Override
public MapCodec<DustParticleOptions> codec() {
return DustParticleOptions.CODEC;
}
@Override
public StreamCodec<? super RegistryFriendlyByteBuf, DustParticleOptions> streamCodec() {
return DustParticleOptions.STREAM_CODEC;
}
});
public static final Supplier<SimpleParticleType> STAR_PARTICLE =
PARTICLE_TYPES.register("star_particle", () -> new SimpleParticleType(true));
public static final Supplier<SimpleParticleType> EXPLODE_PARTICLE =
PARTICLE_TYPES.register("explode_particle", () -> new SimpleParticleType(true));
public static final Supplier<SimpleParticleType> SEEDLER_THORN_PARTICLE =
PARTICLE_TYPES.register("seedler_thorn_particle", () -> new SimpleParticleType(true));
}
@@ -0,0 +1,57 @@
package com.lzxnone.terraria.particle;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.*;
import net.minecraft.core.particles.SimpleParticleType;
public class SeedlerThornParticle extends TextureSheetParticle {
private final float baseSize;
protected SeedlerThornParticle(ClientLevel level, double x, double y, double z,
double xSpeed, double ySpeed, double zSpeed, SpriteSet spriteSet) {
super(level, x, y, z, xSpeed, ySpeed, zSpeed);
this.friction = 0.9F;
this.gravity = 0.0F;
this.xd = xSpeed;
this.yd = ySpeed;
this.zd = zSpeed;
this.baseSize = 0.075F + (this.random.nextFloat() * 0.05F);
this.quadSize = baseSize;
this.lifetime = 25;
this.pickSprite(spriteSet);
}
@Override
public void tick() {
super.tick();
float lifeRatio = (float) this.age / (float) this.lifetime;
this.quadSize = this.baseSize * (1.0F - lifeRatio);
this.alpha = 1.0F - lifeRatio;
}
@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 SeedlerThornParticle(level, x, y, z, xSpeed, ySpeed, zSpeed, this.spriteSet);
}
}
}
@@ -0,0 +1,77 @@
package com.lzxnone.terraria.particle;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.*;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.core.particles.SimpleParticleType;
import org.joml.Vector3f;
public class StarParticle extends TextureSheetParticle {
private final float baseSize;
private static final Vector3f[] COLOR_PALETTE = new Vector3f[]{
new Vector3f(1.0F, 0.9F, 0.0F), // 0: 黄色 (Yellow)
new Vector3f(0.5F, 0.8F, 1.0F), // 1: 淡蓝 (Light Blue)
new Vector3f(1.0F, 0.0F, 1.0F), // 2: 品红 (Magenta)
new Vector3f(0.7F, 0.7F, 0.7F) // 3: 淡灰 (Light Gray)
};
protected StarParticle(ClientLevel level, double x, double y, double z,
double xSpeed, double ySpeed, double zSpeed, SpriteSet spriteSet) {
super(level, x, y, z, xSpeed, ySpeed, zSpeed);
this.friction = 0.9F;
this.gravity = 0.0F;
this.xd = xSpeed;
this.yd = ySpeed;
this.zd = zSpeed;
this.baseSize = 0.025F + (this.random.nextFloat() * 0.1F);
this.quadSize = baseSize;
this.lifetime = 40 + this.random.nextInt(10);
int randomIndex = this.random.nextInt(COLOR_PALETTE.length);
Vector3f chosenColor = COLOR_PALETTE[randomIndex];
this.rCol = chosenColor.x;
this.gCol = chosenColor.y;
this.bCol = chosenColor.z;
this.setSpriteFromAge(spriteSet);
}
@Override
public void tick() {
super.tick();
float lifeRatio = (float) this.age / (float) this.lifetime;
this.quadSize = this.baseSize * (1.0F - lifeRatio);
this.alpha = 1.0F - lifeRatio;
}
@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 StarParticle(level, x, y, z, xSpeed, ySpeed, zSpeed, this.spriteSet);
}
}
}
@@ -0,0 +1,29 @@
package com.lzxnone.terraria.utils;
import net.minecraft.world.phys.Vec3;
import org.joml.Vector3f;
public class MathUtil {
public static Vector3f[] computeProjectileDir(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();
Vector3f up = new Vector3f();
dir.cross(right, up).normalize();
return new Vector3f[]{dir, up, right};
}
public static Vector3f toVector3f(Vec3 vec3) {
return new Vector3f((float) vec3.x, (float) vec3.y, (float) vec3.z);
}
public static Vec3 toVec3(Vector3f vector3f) {
return new Vec3(vector3f.x, vector3f.y, vector3f.z);
}
}
@@ -0,0 +1,20 @@
{
"itemGroup.lzxnoneterraria.weapon": "Terraria Weapon",
"itemGroup.lzxnoneterraria.block": "Terraria Block",
"item.lzxnoneterraria.bee_keeper": "Bee Keeper",
"item.lzxnoneterraria.copper_shortsword": "Copper Shortsword",
"item.lzxnoneterraria.enchanted_sword": "Enchanted Sword",
"item.lzxnoneterraria.influx_waver": "Influx Waver",
"item.lzxnoneterraria.meowmere": "Meowmere",
"item.lzxnoneterraria.seedler": "Seedler",
"item.lzxnoneterraria.star_wrath": "Star Wrath",
"item.lzxnoneterraria.starfury": "Starfury",
"item.lzxnoneterraria.terra_blade": "Terra Blade",
"item.lzxnoneterraria.the_horsemans_blade": "The Horseman's Blade",
"item.lzxnoneterraria.zenith": "Zenith",
"entity.lzxnoneterraria.bee_summon": "Bee",
"effect.lzxnoneterraria.confused": "Confused"
}
@@ -0,0 +1,20 @@
{
"itemGroup.lzxnoneterraria.weapon": "泰拉瑞亚 武器",
"itemGroup.lzxnoneterraria.block": "泰拉瑞亚 方块",
"item.lzxnoneterraria.bee_keeper": "养蜂人",
"item.lzxnoneterraria.copper_shortsword": "铜短剑",
"item.lzxnoneterraria.enchanted_sword": "附魔剑",
"item.lzxnoneterraria.influx_waver": "波涌之刃",
"item.lzxnoneterraria.meowmere": "彩虹喵之刃",
"item.lzxnoneterraria.seedler": "种子弯刀",
"item.lzxnoneterraria.star_wrath": "狂星之怒",
"item.lzxnoneterraria.starfury": "星怒",
"item.lzxnoneterraria.terra_blade": "泰拉刃",
"item.lzxnoneterraria.the_horsemans_blade": "无头骑士剑",
"item.lzxnoneterraria.zenith": "天顶剑",
"entity.lzxnoneterraria.bee_summon": "蜜蜂",
"effect.lzxnoneterraria.confused": "困惑"
}
@@ -0,0 +1,6 @@
{
"parent": "lzxnoneterraria:item/weapon",
"textures": {
"layer0": "lzxnoneterraria:item/bee_keeper"
}
}
@@ -0,0 +1,6 @@
{
"parent": "lzxnoneterraria:item/weapon",
"textures": {
"layer0": "lzxnoneterraria:item/copper_shortsword"
}
}
@@ -0,0 +1,6 @@
{
"parent": "lzxnoneterraria:item/weapon",
"textures": {
"layer0": "lzxnoneterraria:item/enchanted_sword"
}
}
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "lzxnoneterraria:item/enchanted_sword_beam"
}
}
@@ -0,0 +1,6 @@
{
"parent": "lzxnoneterraria:item/weapon",
"textures": {
"layer0": "lzxnoneterraria:item/influx_waver"
}
}
@@ -0,0 +1,6 @@
{
"parent": "lzxnoneterraria:item/weapon",
"textures": {
"layer0": "lzxnoneterraria:item/meowmere"
}
}
@@ -0,0 +1,6 @@
{
"parent": "lzxnoneterraria:item/weapon",
"textures": {
"layer0": "lzxnoneterraria:item/seedler"
}
}
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "lzxnoneterraria:item/seedler_nut"
}
}
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "lzxnoneterraria:item/seedler_thorn"
}
}
@@ -0,0 +1,6 @@
{
"parent": "lzxnoneterraria:item/weapon",
"textures": {
"layer0": "lzxnoneterraria:item/star_wrath"
}
}
@@ -0,0 +1,6 @@
{
"parent": "lzxnoneterraria:item/weapon",
"textures": {
"layer0": "lzxnoneterraria:item/starfury"
}
}
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "lzxnoneterraria:item/starfury_star"
}
}
@@ -0,0 +1,6 @@
{
"parent": "lzxnoneterraria:item/weapon",
"textures": {
"layer0": "lzxnoneterraria:item/terra_blade"
}
}
@@ -0,0 +1,6 @@
{
"parent": "lzxnoneterraria:item/weapon",
"textures": {
"layer0": "lzxnoneterraria:item/the_horsemans_blade"
}
}
@@ -0,0 +1,25 @@
{
"parent": "item/handheld",
"display": {
"thirdperson_righthand": {
"rotation": [0, 90, 55],
"translation": [0, 4.0, 3.0],
"scale": [0.85, 0.85, 0.85]
},
"thirdperson_lefthand": {
"rotation": [0, -90, -55],
"translation": [0, 4.0, 3.0],
"scale": [0.85, 0.85, 0.85]
},
"firstperson_righthand": {
"rotation": [0, 90, 25],
"translation": [1.13, 6.2, 0.0],
"scale": [0.68, 0.68, 0.68]
},
"firstperson_lefthand": {
"rotation": [0, -90, -25],
"translation": [1.13, 3.2, 3.0],
"scale": [0.68, 0.68, 0.68]
}
}
}
@@ -0,0 +1,6 @@
{
"parent": "lzxnoneterraria:item/weapon",
"textures": {
"layer0": "lzxnoneterraria:item/zenith"
}
}
@@ -0,0 +1,6 @@
{
"textures": [
"lzxnoneterraria:dust_particle_arms",
"lzxnoneterraria:dust_particle_center"
]
}
@@ -0,0 +1,6 @@
{
"textures": [
"lzxnoneterraria:enchanted_sword_beam_particle_arms",
"lzxnoneterraria:enchanted_sword_beam_particle_center"
]
}
@@ -0,0 +1,5 @@
{
"textures": [
"lzxnoneterraria:explode_particle"
]
}
@@ -0,0 +1,5 @@
{
"textures": [
"lzxnoneterraria:max_mana_particle"
]
}
@@ -0,0 +1,8 @@
{
"textures": [
"lzxnoneterraria:seedler_thorn_particle0",
"lzxnoneterraria:seedler_thorn_particle1",
"lzxnoneterraria:seedler_thorn_particle2",
"lzxnoneterraria:seedler_thorn_particle3"
]
}
@@ -0,0 +1,5 @@
{
"textures": [
"lzxnoneterraria:star_particle"
]
}
@@ -0,0 +1,20 @@
{
"wave": {
"sounds": ["lzxnoneterraria:wave"]
},
"max_mana": {
"sounds": ["lzxnoneterraria:max_mana"]
},
"beam": {
"sounds": ["lzxnoneterraria:beam"]
},
"star_fall": {
"sounds": ["lzxnoneterraria:star_fall"]
},
"star_collide": {
"sounds": ["lzxnoneterraria:star_collide"]
},
"boom": {
"sounds": ["lzxnoneterraria:boom"]
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 819 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 431 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 343 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 410 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 B

Loaded 100 of 117 files, more files were not shown because too many files have changed in this diff. Show more