v1.6.0
This commit is contained in:
1 parent
4e8170051e
commit
0e66621a04
26 files changed
+963
-7
No files matched your search
@@ -6,6 +6,8 @@ import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent;
|
||||
import net.neoforged.neoforge.client.settings.KeyConflictContext;
|
||||
import net.neoforged.neoforge.client.settings.KeyModifier;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
@EventBusSubscriber(modid = LzxnoneTerraria.MODID, value = Dist.CLIENT)
|
||||
@@ -17,8 +19,28 @@ public class ModKeyBindings {
|
||||
"key.categories.lzxnoneterraria"
|
||||
);
|
||||
|
||||
public static final KeyMapping CLEAR_SUMMON = new KeyMapping(
|
||||
"key.lzxnoneterraria.clear_summon",
|
||||
KeyConflictContext.IN_GAME,
|
||||
KeyModifier.NONE,
|
||||
InputConstants.Type.KEYSYM,
|
||||
GLFW.GLFW_KEY_X,
|
||||
"key.categories.lzxnoneterraria"
|
||||
);
|
||||
|
||||
public static final KeyMapping CLEAR_ALL_SUMMONS = new KeyMapping(
|
||||
"key.lzxnoneterraria.clear_all_summons",
|
||||
KeyConflictContext.IN_GAME,
|
||||
KeyModifier.CONTROL,
|
||||
InputConstants.Type.KEYSYM,
|
||||
GLFW.GLFW_KEY_X,
|
||||
"key.categories.lzxnoneterraria"
|
||||
);
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerKeys(RegisterKeyMappingsEvent event) {
|
||||
event.register(KILL_MODE);
|
||||
event.register(CLEAR_SUMMON);
|
||||
event.register(CLEAR_ALL_SUMMONS);
|
||||
}
|
||||
}
|
||||
@@ -23,4 +23,8 @@ public class ModAttachments {
|
||||
|
||||
public static final Supplier<AttachmentType<Integer>> DEVILS_DEVASTATION_HIT_COUNT =
|
||||
ATTACHMENT_TYPES.register("devils_devastation_hit_count", () -> AttachmentType.builder(() -> 0).serialize(Codec.INT).build());
|
||||
|
||||
public static final Supplier<AttachmentType<List<UUID>>> SUMMON_WEAPON_SUMMONS =
|
||||
ATTACHMENT_TYPES.register("summon_weapon_summons", () -> AttachmentType.<List<UUID>>builder((Supplier<List<UUID>>) ArrayList::new).serialize(Codec.list(Codec.STRING.xmap(UUID::fromString, UUID::toString))).build());
|
||||
|
||||
}
|
||||
@@ -54,4 +54,11 @@ public class ModCreativeModeTabs {
|
||||
.displayItems((parameters, output) -> {
|
||||
output.accept(ModItems.LAST_PRISM.get());
|
||||
}).build());
|
||||
|
||||
public static final DeferredHolder<CreativeModeTab, CreativeModeTab> SUMMON_TAB = CREATIVE_MODE_TABS.register("lzxnoneterraria_summon_0", () -> CreativeModeTab.builder()
|
||||
.title(Component.translatable("itemGroup.lzxnoneterraria.summon"))
|
||||
.icon(() -> ModItems.TERRAPRISMA.get().getDefaultInstance())
|
||||
.displayItems((parameters, output) -> {
|
||||
output.accept(ModItems.TERRAPRISMA.get());
|
||||
}).build());
|
||||
}
|
||||
@@ -20,4 +20,6 @@ public class ModEffects {
|
||||
MOB_EFFECTS.register("kill_mode_cooldown", KillModeCooldownEffect::new);
|
||||
public static final DeferredHolder<MobEffect, DemonicFlamesEffect> DEMONIC_FLAMES =
|
||||
MOB_EFFECTS.register("demonic_flames", DemonicFlamesEffect::new);
|
||||
public static final DeferredHolder<MobEffect, SummonEffect> SUMMON =
|
||||
MOB_EFFECTS.register("summon", SummonEffect::new);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.lzxnone.terraria.effect;
|
||||
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectCategory;
|
||||
|
||||
public class SummonEffect extends MobEffect {
|
||||
public SummonEffect() {
|
||||
super(MobEffectCategory.BENEFICIAL, 0xF2F7FF);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.lzxnone.terraria.entity;
|
||||
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
|
||||
public class PureColorVertexConsumer implements VertexConsumer {
|
||||
private final VertexConsumer vertexConsumer;
|
||||
private final float r;
|
||||
private final float g;
|
||||
private final float b;
|
||||
private final float a;
|
||||
|
||||
public PureColorVertexConsumer(VertexConsumer vertexConsumer, float r, float g, float b, float a) {
|
||||
this.vertexConsumer = vertexConsumer;
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer addVertex(float v, float v1, float v2) {
|
||||
vertexConsumer.addVertex(v, v1, v2);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer setColor(int i, int i1, int i2, int i3) {
|
||||
vertexConsumer.setColor((int) (255 * r), (int) (255 * g), (int) (255 * b), (int) (i3 * a));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer setUv(float v, float v1) {
|
||||
vertexConsumer.setUv(v, v1);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer setUv1(int i, int i1) {
|
||||
vertexConsumer.setUv1(i, i1);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer setUv2(int i, int i1) {
|
||||
vertexConsumer.setUv2(i, i1);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer setNormal(float v, float v1, float v2) {
|
||||
vertexConsumer.setNormal(v, v1, v2);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.MoverType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
@@ -70,6 +69,10 @@ public class StaticSummon extends Entity {
|
||||
SynchedEntityData.defineId(StaticSummon.class, EntityDataSerializers.COMPOUND_TAG);
|
||||
|
||||
public LinkedList<Vec3> trailPositions = new LinkedList<>();
|
||||
public LinkedList<AfterimageFrame> afterimageFrames = new LinkedList<>();
|
||||
|
||||
public record AfterimageFrame(Vec3 position, float xRot, float yRot, float r, float g, float b) {
|
||||
}
|
||||
|
||||
private Entity owner = null;
|
||||
|
||||
@@ -135,7 +138,7 @@ public class StaticSummon extends Entity {
|
||||
super.tick();
|
||||
this.owner = getOwner();
|
||||
StaticSummonBehaviors.getBehavior(this.entityData.get(BEHAVIOR)).tick(this);
|
||||
this.move(MoverType.SELF, this.getDeltaMovement());
|
||||
this.setPos(this.position().add(this.getDeltaMovement()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.lzxnone.terraria.entity.summon;
|
||||
|
||||
import com.lzxnone.terraria.item.weapon.magic.LastPrism;
|
||||
import com.lzxnone.terraria.item.weapon.melee.*;
|
||||
import com.lzxnone.terraria.item.weapon.summon.Terraprisma;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -28,6 +29,7 @@ public class StaticSummonBehaviors {
|
||||
public static final String DEVILS_DEVASTATION_MARK_LIGHTNING = "devils_devastation_mark_lightning";
|
||||
public static final String LAST_PRISM_TRI = "last_prism_tri";
|
||||
public static final String LAST_PRISM_BEAM = "last_prism_beam";
|
||||
public static final String TERRAPRISMA = "terraprisma";
|
||||
|
||||
static {
|
||||
BEHAVIORS.put(DEFAULT, new IStaticSummonBehavior() {});
|
||||
@@ -49,6 +51,7 @@ public class StaticSummonBehaviors {
|
||||
BEHAVIORS.put(DEVILS_DEVASTATION_MARK_LIGHTNING, DevilsDevastation.SUMMON_BEHAVIOR4);
|
||||
BEHAVIORS.put(LAST_PRISM_TRI, LastPrism.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(LAST_PRISM_BEAM, LastPrism.SUMMON_BEHAVIOR2);
|
||||
BEHAVIORS.put(TERRAPRISMA, Terraprisma.SUMMON_BEHAVIOR);
|
||||
}
|
||||
|
||||
public static IStaticSummonBehavior getBehavior(String id) {
|
||||
|
||||
@@ -4,10 +4,12 @@ import com.lzxnone.terraria.LzxnoneTerraria;
|
||||
import com.lzxnone.terraria.ModKeyBindings;
|
||||
import com.lzxnone.terraria.effect.ModEffects;
|
||||
import com.lzxnone.terraria.item.ModItems;
|
||||
import com.lzxnone.terraria.item.weapon.SummonWeapon;
|
||||
import com.lzxnone.terraria.item.weapon.melee.DevilsDevastation;
|
||||
import com.lzxnone.terraria.item.weapon.melee.FirstFractal;
|
||||
import com.lzxnone.terraria.item.weapon.melee.TrueCopperShortsword;
|
||||
import com.lzxnone.terraria.item.weapon.melee.Zenith;
|
||||
import com.lzxnone.terraria.network.payload.ClearSummonPayload;
|
||||
import com.lzxnone.terraria.network.payload.DevilsDevastationKillModePayload;
|
||||
import com.lzxnone.terraria.network.payload.FirstFractalScrollPayload;
|
||||
import com.lzxnone.terraria.network.payload.ZenithScrollPayload;
|
||||
@@ -110,5 +112,18 @@ public class InputHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
while(ModKeyBindings.CLEAR_SUMMON.consumeClick()) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if(mc.player != null) {
|
||||
Player player = mc.player;
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if(stack.getItem() instanceof SummonWeapon weapon) {
|
||||
PacketDistributor.sendToServer(new ClearSummonPayload(weapon.getSummonId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
while(ModKeyBindings.CLEAR_ALL_SUMMONS.consumeClick()) {
|
||||
PacketDistributor.sendToServer(new ClearSummonPayload(""));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.lzxnone.terraria.item;
|
||||
|
||||
import com.lzxnone.terraria.LzxnoneTerraria;
|
||||
import com.lzxnone.terraria.item.weapon.melee.*;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
@@ -13,18 +14,36 @@ 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);
|
||||
if(id.getNamespace().equals("lzxnoneterraria")) 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);
|
||||
if(id.getNamespace().equals("lzxnoneterraria")) 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);
|
||||
if(id.getNamespace().equals("lzxnoneterraria")) getBehavior(id.getPath()).onAttackEntity(event);
|
||||
}
|
||||
|
||||
private static IItemWaveBehavior getBehavior(String id) {
|
||||
return switch(id) {
|
||||
case "bee_keeper" -> BeeKeeper.ITEM_WAVE_BEHAVIOR;
|
||||
case "the_horsemans_blade" -> TheHorsemansBlade.ITEM_WAVE_BEHAVIOR;
|
||||
case "terra_blade" -> TerraBlade.ITEM_WAVE_BEHAVIOR;
|
||||
case "true_excalibur" -> TrueExcalibur.ITEM_WAVE_BEHAVIOR;
|
||||
case "true_nights_edge" -> TrueNightsEdge.ITEM_WAVE_BEHAVIOR;
|
||||
case "excalibur" -> Excalibur.ITEM_WAVE_BEHAVIOR;
|
||||
case "nights_edge" -> NightsEdge.ITEM_WAVE_BEHAVIOR;
|
||||
case "lights_bane" -> LightsBane.ITEM_WAVE_BEHAVIOR;
|
||||
case "blood_butcherer" -> BloodButcherer.ITEM_WAVE_BEHAVIOR;
|
||||
case "muramasa" -> Muramasa.ITEM_WAVE_BEHAVIOR;
|
||||
case "volcano" -> Volcano.ITEM_WAVE_BEHAVIOR;
|
||||
case "devils_devastation" -> DevilsDevastation.ITEM_WAVE_BEHAVIOR;
|
||||
default -> new IItemWaveBehavior() {};
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.lzxnone.terraria.item.projectile.*;
|
||||
import com.lzxnone.terraria.item.projectile.first_fractal.*;
|
||||
import com.lzxnone.terraria.item.weapon.magic.*;
|
||||
import com.lzxnone.terraria.item.weapon.melee.*;
|
||||
import com.lzxnone.terraria.item.weapon.summon.*;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.neoforged.neoforge.registries.DeferredItem;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
@@ -41,6 +42,9 @@ public class ModItems {
|
||||
//魔法武器
|
||||
public static final DeferredItem<Item> LAST_PRISM = ITEMS.register("last_prism", LastPrism::new);
|
||||
|
||||
//召唤武器
|
||||
public static final DeferredItem<Item> TERRAPRISMA = ITEMS.register("terraprisma", Terraprisma::new);
|
||||
|
||||
//弹射物
|
||||
public static final DeferredItem<Item> ENCHANTED_SWORD_BEAM = ITEMS.register("enchanted_sword_beam", EnchantedSwordBeam::new);
|
||||
public static final DeferredItem<Item> STARFURY_STAR = ITEMS.register("starfury_star", StarfuryStar::new);
|
||||
@@ -66,4 +70,5 @@ public class ModItems {
|
||||
public static final DeferredItem<Item> FIRST_FRACTAL_PROJECTILE13 = ITEMS.register("first_fractal_projectile13", FirstFractalProjectile13::new);
|
||||
public static final DeferredItem<Item> FIRST_FRACTAL_PROJECTILE14 = ITEMS.register("first_fractal_projectile14", FirstFractalProjectile14::new);
|
||||
public static final DeferredItem<Item> MACE_PROJECTILE = ITEMS.register("mace_projectile", MaceProjectile::new);
|
||||
public static final DeferredItem<Item> TERRAPRISMA_SUMMON = ITEMS.register("terraprisma_summon", TerraprismaSummon::new);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.lzxnone.terraria.item.projectile;
|
||||
|
||||
import net.minecraft.world.item.Item;
|
||||
|
||||
public class TerraprismaSummon extends Item {
|
||||
public TerraprismaSummon() {
|
||||
super(new Item.Properties());
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,92 @@
|
||||
package com.lzxnone.terraria.item.weapon;
|
||||
|
||||
public class SummonWeapon {
|
||||
import com.lzxnone.terraria.attachment.ModAttachments;
|
||||
import com.lzxnone.terraria.effect.ModEffects;
|
||||
import com.lzxnone.terraria.entity.summon.StaticSummon;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Tier;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SummonWeapon extends Item {
|
||||
private final int enchantmentValue;
|
||||
|
||||
public SummonWeapon(Tier tier, Properties properties) {
|
||||
super(properties.durability(tier.getUses()));
|
||||
this.enchantmentValue = tier.getEnchantmentValue();
|
||||
}
|
||||
|
||||
public SummonWeapon(Properties properties) {
|
||||
super(properties);
|
||||
this.enchantmentValue = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnchantable(ItemStack stack) {
|
||||
return stack.getMaxStackSize() == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnchantmentValue(ItemStack stack) {
|
||||
return enchantmentValue;
|
||||
}
|
||||
|
||||
public static int getMaxSummonCount(Player player) {
|
||||
MobEffectInstance instance = player.getEffect(ModEffects.SUMMON);
|
||||
return 1 + (instance == null ? 0 : instance.getAmplifier() + 1);
|
||||
}
|
||||
|
||||
public static List<UUID> getSummons(Player player) {
|
||||
return new ArrayList<>(player.getData(ModAttachments.SUMMON_WEAPON_SUMMONS));
|
||||
}
|
||||
|
||||
public static void registerSummon(Player player, Entity summon) {
|
||||
if(!(player.level() instanceof ServerLevel serverLevel)) return;
|
||||
|
||||
List<UUID> summons = getSummons(player);
|
||||
summons.removeIf(uuid -> {
|
||||
Entity entity = serverLevel.getEntity(uuid);
|
||||
if(entity instanceof StaticSummon summon1) {
|
||||
Entity owner = summon1.getOwner();
|
||||
if(owner != null) {
|
||||
double dist = owner.position().subtract(summon.position()).length();
|
||||
if(dist > 256) return true;
|
||||
}else return true;
|
||||
}
|
||||
return entity == null || !entity.isAlive();
|
||||
});
|
||||
|
||||
int maxSummonCount = Math.max(1, getMaxSummonCount(player));
|
||||
while(summons.size() >= maxSummonCount) {
|
||||
UUID uuid = summons.remove(0);
|
||||
Entity entity = serverLevel.getEntity(uuid);
|
||||
if(entity != null) entity.discard();
|
||||
}
|
||||
|
||||
summons.add(summon.getUUID());
|
||||
player.setData(ModAttachments.SUMMON_WEAPON_SUMMONS, summons);
|
||||
}
|
||||
|
||||
public static void addFreshSummon(Player player, Entity summon) {
|
||||
registerSummon(player, summon);
|
||||
player.level().addFreshEntity(summon);
|
||||
}
|
||||
|
||||
public static void removeSummon(Player player, Entity summon) {
|
||||
List<UUID> summons = getSummons(player);
|
||||
if(summons.remove(summon.getUUID())) {
|
||||
player.setData(ModAttachments.SUMMON_WEAPON_SUMMONS, summons);
|
||||
}
|
||||
}
|
||||
|
||||
public String getSummonId() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,615 @@
|
||||
package com.lzxnone.terraria.item.weapon.summon;
|
||||
|
||||
import com.lzxnone.terraria.attachment.ModAttachments;
|
||||
import com.lzxnone.terraria.entity.ModEntities;
|
||||
import com.lzxnone.terraria.entity.ModRenderTypes;
|
||||
import com.lzxnone.terraria.entity.PureColorVertexConsumer;
|
||||
import com.lzxnone.terraria.entity.TintedVertexConsumer;
|
||||
import com.lzxnone.terraria.entity.summon.IStaticSummonBehavior;
|
||||
import com.lzxnone.terraria.entity.summon.StaticSummon;
|
||||
import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors;
|
||||
import com.lzxnone.terraria.item.ModItems;
|
||||
import com.lzxnone.terraria.item.weapon.SummonWeapon;
|
||||
import com.lzxnone.terraria.utils.DamageUtil;
|
||||
import com.lzxnone.terraria.utils.FilterUtil;
|
||||
import com.lzxnone.terraria.utils.MathUtil;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Axis;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.monster.Monster;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.checkerframework.checker.units.qual.C;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Terraprisma extends SummonWeapon {
|
||||
private static final double TARGET_RANGE = 32.0D;
|
||||
|
||||
private static final double FOLLOW_SPEED = 4.0D;
|
||||
|
||||
public static final double DASH_PRE_SPEED = -0.75;
|
||||
public static final double DASH_PRE_FRICTION = 0.78;
|
||||
|
||||
public static final double DASH_SPEED = 1.6;
|
||||
public static final int DASH_MORE_TIME = 1;
|
||||
public static final double DASH_FRICTION = 0.72;
|
||||
|
||||
public static final float ROTATION_LERP = 0.25f;
|
||||
public static final float ROTATION_LERP2 = 0.5f;
|
||||
|
||||
public static final double ROTATE_SPEED = 1.0;
|
||||
|
||||
public static final float DAMAGE = 20;
|
||||
public static final float TRAIL_ALPHA = 1.0f;
|
||||
public static final int TRAIL_MAX_LENGTH = 20;
|
||||
public static final float AFTERIMAGE_ALPHA = 0.5f;
|
||||
public static final int AFTERIMAGE_MAX_LENGTH = 3;
|
||||
public static final float AFTERIMAGE_SCALE = 0.92f;
|
||||
|
||||
public enum State {
|
||||
IDLE,
|
||||
FIGHT,
|
||||
DASH_PRE,
|
||||
DASH,
|
||||
ROTATE
|
||||
};
|
||||
|
||||
public Terraprisma() {
|
||||
super(Tiers.NETHERITE, new Item.Properties().stacksTo(1).fireResistant().rarity(Rarity.EPIC));
|
||||
}
|
||||
|
||||
public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() {
|
||||
public static final ResourceLocation RES = ResourceLocation.parse("lzxnoneterraria:textures/vfx/sword_trail.png");
|
||||
@Override
|
||||
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
|
||||
if(!(entity instanceof StaticSummon summon) || summon.getOwner() == null) return;
|
||||
ItemStack stack = summon.getEntityData().get(StaticSummon.ITEM);
|
||||
if(stack.isEmpty()) return;
|
||||
|
||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
|
||||
int idx = customData.contains("idx") ? customData.getInt("idx") : 0;
|
||||
int state = customData.contains("state") ? customData.getInt("state") : 0;
|
||||
float[] color = computeCrystalColor(summon.tickCount + partialTick, idx);
|
||||
Vec3 currentPos = summon.position();
|
||||
|
||||
if(state == State.DASH_PRE.ordinal() || state == State.DASH.ordinal()) {
|
||||
for(int i = summon.afterimageFrames.size() - 1; i >= 0; i--) {
|
||||
StaticSummon.AfterimageFrame frame = summon.afterimageFrames.get(i);
|
||||
float alpha = AFTERIMAGE_ALPHA * (1.0f - (float)i / AFTERIMAGE_MAX_LENGTH);
|
||||
Vec3 offset = frame.position().subtract(currentPos);
|
||||
|
||||
poseStack.pushPose();
|
||||
poseStack.translate(offset.x, offset.y, offset.z);
|
||||
|
||||
poseStack.mulPose(Axis.YP.rotationDegrees(-frame.yRot()));
|
||||
poseStack.mulPose(Axis.XP.rotationDegrees(frame.xRot()));
|
||||
|
||||
poseStack.mulPose(Axis.ZP.rotationDegrees(90));
|
||||
poseStack.mulPose(Axis.YP.rotationDegrees(90));
|
||||
|
||||
poseStack.scale(
|
||||
summon.getEntityData().get(StaticSummon.SCALE_X) * AFTERIMAGE_SCALE,
|
||||
summon.getEntityData().get(StaticSummon.SCALE_Y) * AFTERIMAGE_SCALE,
|
||||
summon.getEntityData().get(StaticSummon.SCALE_Z) * AFTERIMAGE_SCALE
|
||||
);
|
||||
|
||||
Minecraft.getInstance().getItemRenderer().renderStatic(
|
||||
stack,
|
||||
ItemDisplayContext.NONE,
|
||||
LightTexture.FULL_BRIGHT,
|
||||
OverlayTexture.NO_OVERLAY,
|
||||
poseStack,
|
||||
renderType -> {
|
||||
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(InventoryMenu.BLOCK_ATLAS));
|
||||
return new PureColorVertexConsumer(vertexConsumer,
|
||||
frame.r(),
|
||||
frame.g(),
|
||||
frame.b(),
|
||||
alpha);
|
||||
},
|
||||
entity.level(),
|
||||
0
|
||||
);
|
||||
poseStack.popPose();
|
||||
}
|
||||
}
|
||||
|
||||
poseStack.pushPose();
|
||||
|
||||
poseStack.mulPose(Axis.YP.rotationDegrees(-Mth.lerp(partialTick, summon.yRotO, summon.getYRot())));
|
||||
poseStack.mulPose(Axis.XP.rotationDegrees(Mth.lerp(partialTick, summon.xRotO, summon.getXRot())));
|
||||
|
||||
poseStack.mulPose(Axis.ZP.rotationDegrees(90));
|
||||
poseStack.mulPose(Axis.YP.rotationDegrees(90));
|
||||
|
||||
poseStack.scale(
|
||||
summon.getEntityData().get(StaticSummon.SCALE_X),
|
||||
summon.getEntityData().get(StaticSummon.SCALE_Y),
|
||||
summon.getEntityData().get(StaticSummon.SCALE_Z)
|
||||
);
|
||||
|
||||
for(int i = 0;i < 3;i++) {
|
||||
Minecraft.getInstance().getItemRenderer().renderStatic(
|
||||
stack,
|
||||
ItemDisplayContext.NONE,
|
||||
LightTexture.FULL_BRIGHT,
|
||||
OverlayTexture.NO_OVERLAY,
|
||||
poseStack,
|
||||
renderType -> {
|
||||
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(InventoryMenu.BLOCK_ATLAS));
|
||||
return new TintedVertexConsumer(vertexConsumer,
|
||||
color[0],
|
||||
color[1],
|
||||
color[2],
|
||||
summon.getEntityData().get(StaticSummon.COLOR_A));
|
||||
},
|
||||
entity.level(),
|
||||
0
|
||||
);
|
||||
}
|
||||
poseStack.popPose();
|
||||
|
||||
if(state == State.ROTATE.ordinal()) {
|
||||
VertexConsumer vertexConsumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(RES));
|
||||
float mainAlpha = TRAIL_ALPHA;
|
||||
int quadCount = summon.trailPositions.size() / 2 - 1;
|
||||
for(int j = 0; j < 3; j++) {
|
||||
for(int i = 0; i < quadCount; i++) {
|
||||
Vec3 currentPoint1 = summon.trailPositions.get(i * 2);
|
||||
Vec3 currentPoint2 = summon.trailPositions.get(i * 2 + 1);
|
||||
Vec3 nextPoint1 = summon.trailPositions.get(i * 2 + 3);
|
||||
Vec3 nextPoint2 = summon.trailPositions.get(i * 2 + 2);
|
||||
|
||||
double x1 = currentPoint1.x - currentPos.x;
|
||||
double y1 = currentPoint1.y - currentPos.y;
|
||||
double z1 = currentPoint1.z - currentPos.z;
|
||||
|
||||
double x2 = currentPoint2.x - currentPos.x;
|
||||
double y2 = currentPoint2.y - currentPos.y;
|
||||
double z2 = currentPoint2.z - currentPos.z;
|
||||
|
||||
double x3 = nextPoint1.x - currentPos.x;
|
||||
double y3 = nextPoint1.y - currentPos.y;
|
||||
double z3 = nextPoint1.z - currentPos.z;
|
||||
|
||||
double x4 = nextPoint2.x - currentPos.x;
|
||||
double y4 = nextPoint2.y - currentPos.y;
|
||||
double z4 = nextPoint2.z - currentPos.z;
|
||||
|
||||
float radio1 = (float) i / quadCount;
|
||||
float radio2 = (float) (i + 1) / quadCount;
|
||||
|
||||
vertexConsumer.addVertex(poseStack.last().pose(), (float)x1, (float)y1, (float)z1)
|
||||
.setColor(color[0], color[1], color[2], mainAlpha).setUv(radio1, 0.0f)
|
||||
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
|
||||
vertexConsumer.addVertex(poseStack.last().pose(), (float)x2, (float)y2, (float)z2)
|
||||
.setColor(color[0], color[1], color[2], 0).setUv(radio1, 1.0f)
|
||||
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
|
||||
vertexConsumer.addVertex(poseStack.last().pose(), (float)x3, (float)y3, (float)z3)
|
||||
.setColor(color[0], color[1], color[2], 0).setUv(radio2, 1.0f)
|
||||
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
|
||||
vertexConsumer.addVertex(poseStack.last().pose(), (float)x4, (float)y4, (float)z4)
|
||||
.setColor(color[0], color[1], color[2], mainAlpha).setUv(radio2, 0.0f)
|
||||
.setOverlay(OverlayTexture.NO_OVERLAY).setLight(LightTexture.FULL_BRIGHT).setNormal(0, 1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(StaticSummon summon) {
|
||||
this.checkBeforeTick(summon);
|
||||
if(summon.getOwner() instanceof Player player && !summon.level().isClientSide()) {
|
||||
onState(summon, player);
|
||||
}
|
||||
if(summon.level().isClientSide()) {
|
||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
|
||||
int state = customData.contains("state") ? customData.getInt("state") : 0;
|
||||
if(state == State.DASH_PRE.ordinal() || state == State.DASH.ordinal()) {
|
||||
int idx = customData.contains("idx") ? customData.getInt("idx") : 0;
|
||||
float[] color = computeCrystalColor(summon.tickCount, idx);
|
||||
summon.afterimageFrames.addFirst(new StaticSummon.AfterimageFrame(
|
||||
summon.position(),
|
||||
summon.getXRot(),
|
||||
summon.getYRot(),
|
||||
color[0],
|
||||
color[1],
|
||||
color[2]
|
||||
));
|
||||
while(summon.afterimageFrames.size() > AFTERIMAGE_MAX_LENGTH) summon.afterimageFrames.removeLast();
|
||||
}else {
|
||||
summon.afterimageFrames.clear();
|
||||
}
|
||||
|
||||
if(state == State.ROTATE.ordinal()) {
|
||||
Vector3f[] dirs = MathUtil.computeCoordinateSystem(summon);
|
||||
Vec3 dir = MathUtil.toVec3(dirs[0]);
|
||||
summon.trailPositions.addFirst(summon.position().add(dir.scale(-1)));
|
||||
summon.trailPositions.addFirst(summon.position().add(dir.scale(1)));
|
||||
while(summon.trailPositions.size() > TRAIL_MAX_LENGTH) summon.trailPositions.removeLast();
|
||||
}else {
|
||||
summon.trailPositions.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static void onState(StaticSummon summon, Player player) {
|
||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
|
||||
int state = customData.contains("state") ? customData.getInt("state") : 0;
|
||||
|
||||
if(state == State.IDLE.ordinal()) {
|
||||
updateTargetData(summon, player);
|
||||
tickFollowOwner(summon);
|
||||
}else if(state == State.FIGHT.ordinal()) {
|
||||
updateTargetData(summon, player);
|
||||
}else if(state == State.DASH_PRE.ordinal()) {
|
||||
Entity target = getTarget(summon);
|
||||
if(target != null) {
|
||||
Vec3 distV = target.getBoundingBox().getCenter().subtract(summon.position());
|
||||
Vec3 targetDir = distV.normalize();
|
||||
float[] targetXYRot = MathUtil.computeXYRot(targetDir.toVector3f());
|
||||
summon.setXRot(Mth.rotLerp(ROTATION_LERP, summon.getXRot(), targetXYRot[0]));
|
||||
summon.setYRot(Mth.rotLerp(ROTATION_LERP, summon.getYRot(), targetXYRot[1]));
|
||||
}
|
||||
summon.setDeltaMovement(summon.getDeltaMovement().scale(DASH_PRE_FRICTION));
|
||||
}else if(state == State.DASH.ordinal()) {
|
||||
int dashTime = customData.contains("dashTime") ? customData.getInt("dashTime") : 0;
|
||||
customData.putInt("dashTime", dashTime - 1);
|
||||
if(dashTime > 0) {
|
||||
summon.setDeltaMovement(summon.getLookAngle().normalize().scale(DASH_SPEED));
|
||||
}else {
|
||||
summon.setDeltaMovement(summon.getDeltaMovement().scale(DASH_FRICTION));
|
||||
}
|
||||
List<Entity> targets = summon.level().getEntitiesOfClass(
|
||||
Entity.class,
|
||||
summon.getBoundingBox(),
|
||||
FilterUtil.createTargetFilter(summon, player)
|
||||
);
|
||||
for(Entity target : targets) {
|
||||
if(DamageUtil.normalAttack(summon, target, DAMAGE, 1.0f)) target.invulnerableTime = 15;
|
||||
}
|
||||
}else if(state == State.ROTATE.ordinal()) {
|
||||
int time = customData.contains("rotateTime") ? customData.getInt("rotateTime") : 0;
|
||||
|
||||
Vec3 center = new Vec3(
|
||||
customData.getFloat("centerX"),
|
||||
customData.getFloat("centerY"),
|
||||
customData.getFloat("centerZ")
|
||||
);
|
||||
|
||||
Vec3 axisX = new Vec3(
|
||||
customData.getFloat("axisX_X"),
|
||||
customData.getFloat("axisX_Y"),
|
||||
customData.getFloat("axisX_Z")
|
||||
).normalize();
|
||||
|
||||
Vec3 axisY = new Vec3(
|
||||
customData.getFloat("axisY_X"),
|
||||
customData.getFloat("axisY_Y"),
|
||||
customData.getFloat("axisY_Z")
|
||||
).normalize();
|
||||
|
||||
double a = customData.getDouble("a");
|
||||
double b = customData.getDouble("b");
|
||||
double w = customData.getDouble("w");
|
||||
|
||||
double theta = Math.PI - w * time;
|
||||
|
||||
Vec3 nextPos = center
|
||||
.add(axisX.scale(Math.cos(theta) * a))
|
||||
.add(axisY.scale(Math.sin(theta) * b));
|
||||
|
||||
summon.setDeltaMovement(nextPos.subtract(summon.position()));
|
||||
|
||||
Vec3 swordDir = nextPos.subtract(center);
|
||||
if(swordDir.lengthSqr() > 0.0001) {
|
||||
float[] xyRot = MathUtil.computeXYRot(swordDir.toVector3f());
|
||||
summon.setXRot(Mth.rotLerp(ROTATION_LERP2, summon.getXRot(), xyRot[0]));
|
||||
summon.setYRot(Mth.rotLerp(ROTATION_LERP2, summon.getYRot(), xyRot[1]));
|
||||
}
|
||||
|
||||
AABB hitBox = new AABB(summon.position(), nextPos).inflate(0.8);
|
||||
List<Entity> targets = summon.level().getEntitiesOfClass(
|
||||
Entity.class,
|
||||
hitBox,
|
||||
FilterUtil.createTargetFilter(summon, player)
|
||||
);
|
||||
|
||||
for(Entity target : targets) {
|
||||
if(DamageUtil.normalAttack(summon, target, DAMAGE, 1.0f)) target.invulnerableTime = 15;
|
||||
}
|
||||
|
||||
customData.putInt("rotateTime", time + 1);
|
||||
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
|
||||
}
|
||||
|
||||
int nextState = getNextState(summon, state);
|
||||
if(nextState != state) changeState(summon, state, nextState);
|
||||
}
|
||||
|
||||
public static int getNextState(StaticSummon summon, int state) {
|
||||
if(state == State.IDLE.ordinal()) {
|
||||
Entity target = getTarget(summon);
|
||||
if(target != null) return State.FIGHT.ordinal();
|
||||
return State.IDLE.ordinal();
|
||||
}else if(state == State.FIGHT.ordinal()) {
|
||||
Entity target = getTarget(summon);
|
||||
if(target != null) {
|
||||
Vec3 distV = target.getBoundingBox().getCenter().subtract(summon.position());
|
||||
double dist = distV.length();
|
||||
if (dist < 8) {
|
||||
if (summon.getRandom().nextInt(2) == 0) return State.DASH_PRE.ordinal();
|
||||
else return State.ROTATE.ordinal();
|
||||
} else {
|
||||
return State.DASH_PRE.ordinal();
|
||||
}
|
||||
}
|
||||
return State.IDLE.ordinal();
|
||||
}else if(state == State.DASH_PRE.ordinal()) {
|
||||
Entity target = getTarget(summon);
|
||||
if(target != null) {
|
||||
Vec3 targetDir = target.getBoundingBox().getCenter().subtract(summon.position()).normalize();
|
||||
double speed = summon.getDeltaMovement().length();
|
||||
if(speed < 0.05 && Math.abs(summon.getLookAngle().dot(targetDir) - 1) < 0.001) {
|
||||
return State.DASH.ordinal();
|
||||
}
|
||||
return State.DASH_PRE.ordinal();
|
||||
}
|
||||
return State.FIGHT.ordinal();
|
||||
}else if(state == State.DASH.ordinal()) {
|
||||
double speed = summon.getDeltaMovement().length();
|
||||
if(speed < 0.05) {
|
||||
return State.FIGHT.ordinal();
|
||||
}
|
||||
return State.DASH.ordinal();
|
||||
}else if(state == State.ROTATE.ordinal()) {
|
||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
|
||||
int time = customData.contains("rotateTime") ? customData.getInt("rotateTime") : 0;
|
||||
int duration = customData.getInt("duration");
|
||||
if(time >= duration) {
|
||||
return State.FIGHT.ordinal();
|
||||
}
|
||||
return State.ROTATE.ordinal();
|
||||
}
|
||||
return State.IDLE.ordinal();
|
||||
}
|
||||
|
||||
public static void changeState(StaticSummon summon, int from, int to) {
|
||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA).copy();
|
||||
customData.putInt("state", to);
|
||||
if(to == State.DASH_PRE.ordinal()) {
|
||||
Entity target = getTarget(summon);
|
||||
if(target != null) {
|
||||
summon.setDeltaMovement(target.getBoundingBox().getCenter().subtract(summon.position()).normalize().scale(DASH_PRE_SPEED));
|
||||
}
|
||||
}else if(to == State.DASH.ordinal()) {
|
||||
Entity target = getTarget(summon);
|
||||
if(target != null) {
|
||||
summon.setDeltaMovement(Vec3.ZERO);
|
||||
Vec3 distV = target.getBoundingBox().getCenter().subtract(summon.position());
|
||||
double dist = distV.length();
|
||||
int dashTime = (int) (dist / DASH_SPEED) + DASH_MORE_TIME;
|
||||
customData.putInt("dashTime", dashTime);
|
||||
}
|
||||
}else if(to == State.ROTATE.ordinal()) {
|
||||
Entity target = getTarget(summon);
|
||||
if(target != null) {
|
||||
Vec3 start = summon.position();
|
||||
Vec3 end = target.getBoundingBox().getCenter();
|
||||
Vector3f center = start.add(end).scale(0.5).toVector3f();
|
||||
Vec3 rotateDir = end.subtract(start);
|
||||
if(rotateDir.lengthSqr() < 1.0E-4D) {
|
||||
rotateDir = summon.getLookAngle();
|
||||
}
|
||||
if(rotateDir.lengthSqr() < 1.0E-4D && summon.getOwner() != null) {
|
||||
rotateDir = summon.getOwner().getLookAngle();
|
||||
}
|
||||
if(rotateDir.lengthSqr() < 1.0E-4D) {
|
||||
rotateDir = new Vec3(0.0D, 0.0D, 1.0D);
|
||||
}
|
||||
Vector3f[] dirs = MathUtil.computeCoordinateSystem(rotateDir.toVector3f(), summon.getYRot());
|
||||
int rotationAngle = (int) ((Math.random() * 2 - 1) * 60);
|
||||
dirs = MathUtil.rotateCoordinateSystem(dirs[0], dirs[2], rotationAngle);
|
||||
double a = end.subtract(start).length() / 2;
|
||||
double b = Math.min(Math.random() * 4, a) + 1;
|
||||
|
||||
double h = Math.pow(a - b, 2) / Math.pow(a + b, 2);
|
||||
double circumference = Math.PI * (a + b) * (1 + (3 * h) / (10 + Math.sqrt(4 - 3 * h)));
|
||||
double range = 0.5 + Math.random() * 0.5;
|
||||
double arcLength = circumference * range;
|
||||
int duration = (int)Math.ceil(arcLength / ROTATE_SPEED);
|
||||
duration = Mth.clamp(duration, 8, 18);
|
||||
double w = Math.PI * 2 * range / duration;
|
||||
if(summon.getRandom().nextInt(2) == 0) w = -w;
|
||||
|
||||
customData.putFloat("axisX_X", dirs[0].x);
|
||||
customData.putFloat("axisX_Y", dirs[0].y);
|
||||
customData.putFloat("axisX_Z", dirs[0].z);
|
||||
customData.putFloat("axisY_X", dirs[2].x);
|
||||
customData.putFloat("axisY_Y", dirs[2].y);
|
||||
customData.putFloat("axisY_Z", dirs[2].z);
|
||||
customData.putFloat("centerX", center.x);
|
||||
customData.putFloat("centerY", center.y);
|
||||
customData.putFloat("centerZ", center.z);
|
||||
customData.putDouble("a", a);
|
||||
customData.putDouble("b", b);
|
||||
customData.putInt("duration", duration);
|
||||
customData.putDouble("w", w);
|
||||
customData.putInt("rotateTime", 0);
|
||||
}
|
||||
}
|
||||
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
|
||||
}
|
||||
|
||||
private static void tickFollowOwner(StaticSummon summon) {
|
||||
if(summon.getOwner() == null) return;
|
||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
|
||||
int idx = customData.contains("idx") ? customData.getInt("idx") : 0;
|
||||
|
||||
Vector3f[] dirs = MathUtil.computeCoordinateSystem(summon.getOwner());
|
||||
|
||||
Vec3 hDir = new Vec3(dirs[0].x, 0, dirs[0].z).normalize();
|
||||
if(dirs[0].y > 0.999) {
|
||||
hDir = new Vec3(-dirs[1].x, 0, -dirs[1].z);
|
||||
}else if(dirs[0].y < -0.999) {
|
||||
hDir = new Vec3(dirs[1].x, 0, dirs[1].z);
|
||||
}
|
||||
|
||||
//剑的朝向,向下
|
||||
Vector3f tipDir = new Vector3f(0, -1, 0);
|
||||
Vector3f upDir = hDir.toVector3f();
|
||||
Quaternionf rotation = new Quaternionf().fromAxisAngleDeg(dirs[2], (idx + 1) * 10);
|
||||
tipDir.rotate(rotation);
|
||||
upDir.rotate(rotation);
|
||||
float[] targetXYRot = MathUtil.computeXYRot(tipDir, upDir);
|
||||
summon.setXRot(Mth.rotLerp(ROTATION_LERP, summon.getXRot(), targetXYRot[0]));
|
||||
summon.setYRot(Mth.rotLerp(ROTATION_LERP, summon.getYRot(), targetXYRot[1]));
|
||||
|
||||
//剑的位置,基于水平方向
|
||||
Vec3 basePos = summon.getOwner().getBoundingBox().getCenter();
|
||||
Vec3 pos = basePos.add(hDir.scale(-(idx + 1) * 0.25 - 1));
|
||||
Vec3 dist = pos.subtract(summon.position());
|
||||
if(dist.length() > 4.0) {
|
||||
summon.setDeltaMovement(dist.normalize().scale(Math.min(FOLLOW_SPEED, dist.length())));
|
||||
}else {
|
||||
summon.setDeltaMovement(Vec3.ZERO);
|
||||
summon.setPos(pos);
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateTargetData(StaticSummon summon, Player player) {
|
||||
LivingEntity target = findTarget(summon, player);
|
||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA).copy();
|
||||
if(target == null) {
|
||||
customData.remove("target");
|
||||
}else {
|
||||
customData.putUUID("target", target.getUUID());
|
||||
}
|
||||
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
|
||||
}
|
||||
|
||||
private static LivingEntity findTarget(StaticSummon summon, Player player) {
|
||||
LivingEntity playerAttackTarget = player.getLastHurtMob();
|
||||
if(isValidTarget(summon, player, playerAttackTarget)) {
|
||||
return playerAttackTarget;
|
||||
}
|
||||
|
||||
LivingEntity playerAttacker = player.getLastHurtByMob();
|
||||
if(isValidTarget(summon, player, playerAttacker)) {
|
||||
return playerAttacker;
|
||||
}
|
||||
|
||||
List<Monster> monsters = summon.level().getEntitiesOfClass(
|
||||
Monster.class,
|
||||
AABB.ofSize(summon.position(), TARGET_RANGE * 2.0D, TARGET_RANGE * 2.0D, TARGET_RANGE * 2.0D),
|
||||
FilterUtil.createMonsterFilter(player)
|
||||
);
|
||||
monsters.sort(Comparator.comparingDouble(monster -> monster.distanceToSqr(summon.position())));
|
||||
if(!monsters.isEmpty()) {
|
||||
return monsters.getFirst();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isValidTarget(StaticSummon summon, Player player, LivingEntity target) {
|
||||
return target != null
|
||||
&& target.level() == summon.level()
|
||||
&& target.distanceToSqr(summon) <= TARGET_RANGE * TARGET_RANGE
|
||||
&& FilterUtil.createLivingTargetFilter(summon, player).test(target);
|
||||
}
|
||||
|
||||
private static Entity getTarget(StaticSummon summon) {
|
||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
|
||||
if(customData.contains("target") && summon.level() instanceof ServerLevel serverLevel) {
|
||||
Entity target = serverLevel.getEntity(customData.getUUID("target"));
|
||||
if(target != null && target.isAlive()) {
|
||||
return target;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static float[] computeCrystalColor(float time, int idx) {
|
||||
float hue = (time * 0.015F + idx * 0.12F) % 1.0F;
|
||||
int rgb = Mth.hsvToRgb(hue, 0.85F, 1.0F);
|
||||
float rainbowR = ((rgb >> 16) & 255) / 255.0F;
|
||||
float rainbowG = ((rgb >> 8) & 255) / 255.0F;
|
||||
float rainbowB = (rgb & 255) / 255.0F;
|
||||
float tint = 0.35F;
|
||||
float pulse = 0.92F + 0.08F * Mth.sin(time * 0.12F + idx * 0.7F);
|
||||
|
||||
return new float[]{
|
||||
(1.0F * (1.0F - tint) + rainbowR * tint) * pulse,
|
||||
(1.0F * (1.0F - tint) + rainbowG * tint) * pulse,
|
||||
(1.0F * (1.0F - tint) + rainbowB * tint) * pulse
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
if(stack.is(ModItems.TERRAPRISMA.get()) && level instanceof ServerLevel serverLevel) {
|
||||
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level);
|
||||
summon.setOwner(player);
|
||||
summon.setPos(player.position());
|
||||
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.TERRAPRISMA);
|
||||
summon.getEntityData().set(StaticSummon.RENDER_MODE, "custom");
|
||||
summon.getEntityData().set(StaticSummon.ITEM, new ItemStack(ModItems.TERRAPRISMA_SUMMON.get()));
|
||||
summon.getEntityData().set(StaticSummon.SCALE_X, 2.0f);
|
||||
summon.getEntityData().set(StaticSummon.SCALE_Y, 1.0f);
|
||||
summon.getEntityData().set(StaticSummon.SCALE_Z, 1.0f);
|
||||
summon.getEntityData().set(StaticSummon.LIFETIME, 72000);
|
||||
summon.getEntityData().set(StaticSummon.GLOW, true);
|
||||
|
||||
summon.setNoGravity(true);
|
||||
summon.noPhysics = true;
|
||||
|
||||
SummonWeapon.addFreshSummon(player, summon);
|
||||
|
||||
List<UUID> summons = player.getData(ModAttachments.SUMMON_WEAPON_SUMMONS);
|
||||
int idx = 0;
|
||||
for(UUID uuid : summons) {
|
||||
Entity entity = serverLevel.getEntity(uuid);
|
||||
if(entity instanceof StaticSummon terraSummon && terraSummon.getEntityData().get(StaticSummon.BEHAVIOR).equals(StaticSummonBehaviors.TERRAPRISMA)) {
|
||||
if(terraSummon.isAlive()) {
|
||||
CompoundTag customData = terraSummon.getEntityData().get(StaticSummon.CUSTOM_DATA).copy();
|
||||
customData.putInt("idx", idx);
|
||||
terraSummon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return InteractionResultHolder.consume(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummonId() {
|
||||
return StaticSummonBehaviors.TERRAPRISMA;
|
||||
}
|
||||
}
|
||||
@@ -38,5 +38,10 @@ public class ModNetwork {
|
||||
DevilsDevastationLeftClickPayload.CODEC,
|
||||
DevilsDevastationLeftClickHandler::handle
|
||||
);
|
||||
registrar.playToServer(
|
||||
ClearSummonPayload.TYPE,
|
||||
ClearSummonPayload.CODEC,
|
||||
ClearSummonHandler::handle
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.lzxnone.terraria.network.handler;
|
||||
|
||||
import com.lzxnone.terraria.attachment.ModAttachments;
|
||||
import com.lzxnone.terraria.entity.summon.StaticSummon;
|
||||
import com.lzxnone.terraria.item.weapon.SummonWeapon;
|
||||
import com.lzxnone.terraria.network.payload.ClearSummonPayload;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ClearSummonHandler {
|
||||
public static void handle(final ClearSummonPayload payload, final IPayloadContext context) {
|
||||
context.enqueueWork(() -> {
|
||||
Level level = context.player().level();
|
||||
if(level.isClientSide() || !(level instanceof ServerLevel serverLevel)) return;
|
||||
Player player = context.player();
|
||||
String id = payload.id();
|
||||
boolean clearAll = id.isEmpty();
|
||||
List<UUID> summons = SummonWeapon.getSummons(player);
|
||||
List<UUID> remainingSummons = new ArrayList<>();
|
||||
|
||||
for(UUID uuid : summons) {
|
||||
Entity entity = serverLevel.getEntity(uuid);
|
||||
if(entity == null || !entity.isAlive()) continue;
|
||||
|
||||
if(clearAll || (entity instanceof StaticSummon summon && summon.getEntityData().get(StaticSummon.BEHAVIOR).equals(id))) {
|
||||
entity.discard();
|
||||
}else {
|
||||
remainingSummons.add(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
player.setData(ModAttachments.SUMMON_WEAPON_SUMMONS, remainingSummons);
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.lzxnone.terraria.network.payload;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public record ClearSummonPayload(String id) implements CustomPacketPayload {
|
||||
public static final CustomPacketPayload.Type<ClearSummonPayload> TYPE = new CustomPacketPayload.Type<>(
|
||||
ResourceLocation.fromNamespaceAndPath("lzxnoneterraria", "clear_summon_payload")
|
||||
);
|
||||
|
||||
public static final StreamCodec<FriendlyByteBuf, ClearSummonPayload> CODEC = StreamCodec.composite(
|
||||
ByteBufCodecs.STRING_UTF8, ClearSummonPayload::id,
|
||||
ClearSummonPayload::new
|
||||
);
|
||||
|
||||
@Override
|
||||
public CustomPacketPayload.Type<? extends CustomPacketPayload> type() {
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user