v1.6.1
This commit is contained in:
1 parent
fa21552d8d
commit
724455c26f
21 files changed
+600
-1
No files matched your search
@@ -59,6 +59,16 @@ public class PlayerMana {
|
||||
this.mana = Math.min(mana, this.maxMana);
|
||||
}
|
||||
|
||||
public int increaseMaxMana(int amount, int maxLimit) {
|
||||
if(amount <= 0 || maxMana >= maxLimit) return 0;
|
||||
|
||||
int oldMaxMana = maxMana;
|
||||
setMaxMana(Math.min(maxMana + amount, maxLimit));
|
||||
int increase = maxMana - oldMaxMana;
|
||||
setMana(mana + increase);
|
||||
return increase;
|
||||
}
|
||||
|
||||
public double getConsumeProgress() {
|
||||
return consumeProgress;
|
||||
}
|
||||
|
||||
+2
@@ -15,6 +15,7 @@ import com.lzxnone.terraria.client.item.ranged.ClientFlamethrower;
|
||||
import com.lzxnone.terraria.client.item.ranged.ClientStarCannon;
|
||||
import com.lzxnone.terraria.client.item.ranged.ClientSuperStarShooter;
|
||||
import com.lzxnone.terraria.client.item.summon.ClientTerraprisma;
|
||||
import com.lzxnone.terraria.client.item.summon.ClientWhip;
|
||||
import com.lzxnone.terraria.entity.summon.StaticSummonBehaviors;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -46,6 +47,7 @@ public class ClientStaticSummonRenderBehaviors {
|
||||
BEHAVIORS.put(StaticSummonBehaviors.LAST_PRISM_TRI, ClientLastPrism.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(StaticSummonBehaviors.LAST_PRISM_BEAM, ClientLastPrism.SUMMON_BEHAVIOR2);
|
||||
BEHAVIORS.put(StaticSummonBehaviors.TERRAPRISMA, ClientTerraprisma.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(StaticSummonBehaviors.POSSESSION, ClientWhip.SUMMON_BEHAVIOR);
|
||||
|
||||
BEHAVIORS.put(StaticSummonBehaviors.MUSKET_BALL, ClientBulletAmmo.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(StaticSummonBehaviors.METEOR_SHOT, ClientBulletAmmo.SUMMON_BEHAVIOR);
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.lzxnone.terraria.client.item.summon;
|
||||
|
||||
import com.lzxnone.terraria.client.entity.summon.IStaticSummonRenderBehavior;
|
||||
import com.lzxnone.terraria.entity.ModRenderTypes;
|
||||
import com.lzxnone.terraria.entity.summon.StaticSummon;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ClientWhip {
|
||||
private static final int SEGMENTS = 24;
|
||||
private static final float WIDTH = 1.0F;
|
||||
|
||||
public static final IStaticSummonRenderBehavior SUMMON_BEHAVIOR = new IStaticSummonRenderBehavior() {
|
||||
@Override
|
||||
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
|
||||
if(!(entity instanceof StaticSummon summon) || summon.getOwner() == null) return;
|
||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
|
||||
int lifetime = Math.max(1, summon.getEntityData().get(StaticSummon.LIFETIME));
|
||||
float progress = Mth.clamp((summon.getEntityData().get(StaticSummon.AGE) + partialTick) / lifetime, 0.0F, 1.0F);
|
||||
|
||||
Vec3 origin = entity.getPosition(partialTick);
|
||||
Vec3 hand = origin;
|
||||
Vec3 dir = readVec3(customData, "dir", new Vec3(0.0D, 0.0D, 1.0D)).normalize();
|
||||
Vec3 up = readVec3(customData, "up", new Vec3(0.0D, 1.0D, 0.0D)).normalize();
|
||||
Vec3 right = readVec3(customData, "right", new Vec3(1.0D, 0.0D, 0.0D)).normalize();
|
||||
if(dir.lengthSqr() < 1.0E-6D) dir = new Vec3(0.0D, 0.0D, 1.0D);
|
||||
if(up.lengthSqr() < 1.0E-6D) up = new Vec3(0.0D, 1.0D, 0.0D);
|
||||
if(right.lengthSqr() < 1.0E-6D) right = new Vec3(1.0D, 0.0D, 0.0D);
|
||||
|
||||
double range = customData.contains("range") ? customData.getDouble("range") : 8.0D;
|
||||
double height = customData.contains("height") ? customData.getDouble("height") : range * 0.25D;
|
||||
double bend = customData.contains("bend") ? customData.getDouble("bend") : range * 0.25D;
|
||||
boolean reverse = customData.contains("reverse") && customData.getBoolean("reverse");
|
||||
|
||||
if(!customData.contains("res") || customData.getString("res").isEmpty()) return;
|
||||
ResourceLocation res = ResourceLocation.parse(customData.getString("res"));
|
||||
List<Vec3> points = computePoints(hand, dir, up, progress, range, height, bend, reverse, SEGMENTS);
|
||||
renderRibbon(points, origin, right, res, poseStack, bufferSource);
|
||||
renderRibbon(points, origin, up, res, poseStack, bufferSource);//
|
||||
}
|
||||
|
||||
private static List<Vec3> computePoints(Vec3 hand, Vec3 dir, Vec3 up, float progress, double range, double height, double bend, boolean reverse, int segments) {
|
||||
float phase = 1.0F - Math.abs(progress * 2.0F - 1.0F);
|
||||
float s = easeInOut(phase);
|
||||
float tipArc = 4.0F * s * (1.0F - s);
|
||||
Vec3 tip = hand
|
||||
.add(dir.scale(range * s))
|
||||
.add(up.scale(height * tipArc));
|
||||
Vec3 chord = tip.subtract(hand);
|
||||
double bendAmount = bend * (1.0F - s);
|
||||
Vec3 dynamicBendDir = dir.scale(1.0F - s).add(up.scale(-s)).normalize();
|
||||
if(dynamicBendDir.lengthSqr() < 1.0E-6D) dynamicBendDir = dir;
|
||||
List<Vec3> points = new ArrayList<>(segments + 1);
|
||||
|
||||
for(int i = 0; i <= segments; i++) {
|
||||
float t = i / (float)segments;
|
||||
float shape = 4.0F * t * (1.0F - t);
|
||||
Vec3 base = hand.add(chord.scale(t));
|
||||
Vec3 point = base.add(dynamicBendDir.scale(shape * bendAmount));
|
||||
boolean reflect = reverse ? progress <= 0.5F : progress > 0.5F;
|
||||
points.add(reflect ? reflectAcrossDir(hand, dir, point) : point);
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
private static Vec3 reflectAcrossDir(Vec3 hand, Vec3 dir, Vec3 point) {
|
||||
Vec3 relative = point.subtract(hand);
|
||||
Vec3 parallel = dir.scale(relative.dot(dir));
|
||||
Vec3 perpendicular = relative.subtract(parallel);
|
||||
return hand.add(parallel.subtract(perpendicular));
|
||||
}
|
||||
|
||||
private static void renderRibbon(List<Vec3> points, Vec3 origin, Vec3 widthDir, ResourceLocation res, PoseStack poseStack, MultiBufferSource bufferSource) {
|
||||
if(points.size() < 2) return;
|
||||
VertexConsumer consumer = bufferSource.getBuffer(ModRenderTypes.entityTranslucentEmissive(res));
|
||||
Vec3 halfWidth = widthDir.normalize().scale(WIDTH * 0.5F);
|
||||
double totalLength = 0.0D;
|
||||
double[] distances = new double[points.size()];
|
||||
|
||||
for(int i = 1; i < points.size(); i++) {
|
||||
totalLength += points.get(i).distanceTo(points.get(i - 1));
|
||||
distances[i] = totalLength;
|
||||
}
|
||||
if(totalLength < 1.0E-5D) return;
|
||||
|
||||
for(int i = 0; i < points.size() - 1; i++) {
|
||||
Vec3 p0 = points.get(i);
|
||||
Vec3 p1 = points.get(i + 1);
|
||||
Vec3 tangent = p1.subtract(p0);
|
||||
if(tangent.lengthSqr() < 1.0E-6D) continue;
|
||||
|
||||
Vec3 a = p0.add(halfWidth).subtract(origin);
|
||||
Vec3 b = p0.subtract(halfWidth).subtract(origin);
|
||||
Vec3 c = p1.subtract(halfWidth).subtract(origin);
|
||||
Vec3 d = p1.add(halfWidth).subtract(origin);
|
||||
float u0 = (float)(distances[i] / totalLength);
|
||||
float u1 = (float)(distances[i + 1] / totalLength);
|
||||
|
||||
addVertex(consumer, poseStack, a, u0, 0.0F);
|
||||
addVertex(consumer, poseStack, b, u0, 1.0F);
|
||||
addVertex(consumer, poseStack, c, u1, 1.0F);
|
||||
addVertex(consumer, poseStack, d, u1, 0.0F);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addVertex(VertexConsumer consumer, PoseStack poseStack, Vec3 pos, float u, float v) {
|
||||
consumer.addVertex(poseStack.last().pose(), (float)pos.x, (float)pos.y, (float)pos.z)
|
||||
.setColor(1.0F, 1.0F, 1.0F, 1.0F)
|
||||
.setUv(u, v)
|
||||
.setOverlay(OverlayTexture.NO_OVERLAY)
|
||||
.setLight(LightTexture.FULL_BRIGHT)
|
||||
.setNormal(0.0F, 1.0F, 0.0F);
|
||||
}
|
||||
|
||||
private static Vec3 readVec3(CompoundTag tag, String prefix, Vec3 fallback) {
|
||||
String x = prefix + "X";
|
||||
String y = prefix + "Y";
|
||||
String z = prefix + "Z";
|
||||
if(!tag.contains(x) || !tag.contains(y) || !tag.contains(z)) return fallback;
|
||||
return new Vec3(tag.getDouble(x), tag.getDouble(y), tag.getDouble(z));
|
||||
}
|
||||
|
||||
private static float easeInOut(float value) {
|
||||
return value < 0.5F ? 2.0F * value * value : 1.0F - (float)Math.pow(-2.0F * value + 2.0F, 2.0D) / 2.0F;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -53,6 +53,7 @@ public class ModCreativeModeTabs {
|
||||
.icon(() -> ModItems.LAST_PRISM.get().getDefaultInstance())
|
||||
.displayItems((parameters, output) -> {
|
||||
output.accept(ModItems.LAST_PRISM.get());
|
||||
output.accept(ModItems.MANA_CRYSTAL.get());
|
||||
}).build());
|
||||
|
||||
public static final DeferredHolder<CreativeModeTab, CreativeModeTab> ACCESSORY_TAB = CREATIVE_MODE_TABS.register("lzxnoneterraria_accessory_0", () -> CreativeModeTab.builder()
|
||||
@@ -116,5 +117,6 @@ public class ModCreativeModeTabs {
|
||||
.icon(() -> ModItems.TERRAPRISMA.get().getDefaultInstance())
|
||||
.displayItems((parameters, output) -> {
|
||||
output.accept(ModItems.TERRAPRISMA.get());
|
||||
output.accept(ModItems.POSSESSION.get());
|
||||
}).build());
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import com.lzxnone.terraria.item.weapon.ranged.SnowballCannon;
|
||||
import com.lzxnone.terraria.item.weapon.ranged.StarCannon;
|
||||
import com.lzxnone.terraria.item.weapon.ranged.SuperStarShooter;
|
||||
import com.lzxnone.terraria.item.weapon.summon.Terraprisma;
|
||||
import com.lzxnone.terraria.item.weapon.summon.whip.Whip;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -38,6 +39,7 @@ public class StaticSummonBehaviors {
|
||||
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";
|
||||
public static final String POSSESSION = "possession";
|
||||
|
||||
//通用子弹实体
|
||||
public static final String MUSKET_BALL = "musket_ball";
|
||||
@@ -85,6 +87,7 @@ public class StaticSummonBehaviors {
|
||||
BEHAVIORS.put(LAST_PRISM_TRI, LastPrism.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(LAST_PRISM_BEAM, LastPrism.SUMMON_BEHAVIOR2);
|
||||
BEHAVIORS.put(TERRAPRISMA, Terraprisma.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(POSSESSION, Whip.SUMMON_BEHAVIOR);
|
||||
|
||||
BEHAVIORS.put(MUSKET_BALL, MusketBall.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(METEOR_SHOT, MeteorShot.SUMMON_BEHAVIOR);
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.lzxnone.terraria.LzxnoneTerraria;
|
||||
import com.lzxnone.terraria.item.ammo.*;
|
||||
import com.lzxnone.terraria.item.accessory.ManaFlower;
|
||||
import com.lzxnone.terraria.item.accessory.NaturesGift;
|
||||
import com.lzxnone.terraria.item.food.ManaCrystal;
|
||||
import com.lzxnone.terraria.item.weapon.ranged.ElfMelter;
|
||||
import com.lzxnone.terraria.item.weapon.magic.*;
|
||||
import com.lzxnone.terraria.item.weapon.melee.*;
|
||||
@@ -13,6 +14,7 @@ import com.lzxnone.terraria.item.weapon.ranged.StarCannon;
|
||||
import com.lzxnone.terraria.item.weapon.ranged.SuperStarShooter;
|
||||
import com.lzxnone.terraria.item.weapon.ranged.gun.*;
|
||||
import com.lzxnone.terraria.item.weapon.summon.*;
|
||||
import com.lzxnone.terraria.item.weapon.summon.whip.Possession;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.neoforged.neoforge.registries.DeferredItem;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
@@ -78,6 +80,7 @@ public class ModItems {
|
||||
|
||||
//召唤武器
|
||||
public static final DeferredItem<Item> TERRAPRISMA = ITEMS.register("terraprisma", Terraprisma::new);
|
||||
public static final DeferredItem<Item> POSSESSION = ITEMS.register("possession", Possession::new);
|
||||
|
||||
//近战武器 灾厄
|
||||
public static final DeferredItem<Item> DEVILS_DEVASTATION = ITEMS.register("devils_devastation", DevilsDevastation::new);
|
||||
@@ -105,6 +108,9 @@ public class ModItems {
|
||||
public static final DeferredItem<Item> NATURES_GIFT = ITEMS.register("natures_gift", NaturesGift::new);
|
||||
public static final DeferredItem<Item> MANA_FLOWER = ITEMS.register("mana_flower", ManaFlower::new);
|
||||
|
||||
//食物
|
||||
public static final DeferredItem<Item> MANA_CRYSTAL = ITEMS.register("mana_crystal", ManaCrystal::new);
|
||||
|
||||
//弹射物
|
||||
public static final DeferredItem<Item> BULLET_PROJECTILE = ITEMS.register("bullet_projectile", () -> new Item(new Item.Properties()));
|
||||
public static final DeferredItem<Item> METEOR_SHOT_PROJECTILE = ITEMS.register("meteor_shot_projectile", () -> new Item(new Item.Properties()));
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.lzxnone.terraria.item.food;
|
||||
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.UseAnim;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class Food extends Item {
|
||||
private static final int DEFAULT_USE_DURATION = 32;
|
||||
|
||||
private final int useDuration;
|
||||
|
||||
public Food(Properties properties) {
|
||||
this(properties, DEFAULT_USE_DURATION);
|
||||
}
|
||||
|
||||
public Food(Properties properties, int useDuration) {
|
||||
super(properties);
|
||||
this.useDuration = useDuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
if(!canEat(level, player, stack)) return InteractionResultHolder.fail(stack);
|
||||
|
||||
player.startUsingItem(hand);
|
||||
return InteractionResultHolder.consume(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity livingEntity) {
|
||||
if(livingEntity instanceof Player player && canEat(level, player, stack)) {
|
||||
if(!level.isClientSide() && onEat(level, player, stack) && !player.hasInfiniteMaterials()) {
|
||||
stack.shrink(1);
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUseDuration(ItemStack stack, LivingEntity entity) {
|
||||
return useDuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull UseAnim getUseAnimation(ItemStack stack) {
|
||||
return UseAnim.EAT;
|
||||
}
|
||||
|
||||
protected boolean canEat(Level level, Player player, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract boolean onEat(Level level, Player player, ItemStack stack);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.lzxnone.terraria.item.food;
|
||||
|
||||
import com.lzxnone.terraria.attachment.ModAttachments;
|
||||
import com.lzxnone.terraria.attachment.PlayerMana;
|
||||
import com.lzxnone.terraria.event.PlayerManaSyncEventHandler;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ManaCrystal extends Food {
|
||||
public static final int MANA_INCREASE = 20;
|
||||
public static final int MAX_MANA = 200;
|
||||
|
||||
public ManaCrystal() {
|
||||
super(new Item.Properties().rarity(Rarity.UNCOMMON));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canEat(Level level, Player player, ItemStack stack) {
|
||||
return player.getData(ModAttachments.PLAYER_MANA).getMaxMana() < MAX_MANA;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onEat(Level level, Player player, ItemStack stack) {
|
||||
PlayerMana mana = player.getData(ModAttachments.PLAYER_MANA);
|
||||
if(mana.increaseMaxMana(MANA_INCREASE, MAX_MANA) <= 0) return false;
|
||||
|
||||
player.setData(ModAttachments.PLAYER_MANA, mana);
|
||||
if(player instanceof ServerPlayer serverPlayer) {
|
||||
PlayerManaSyncEventHandler.sync(serverPlayer);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, Item.TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
|
||||
tooltipComponents.add(Component.translatable("tooltip.lzxnoneterraria.mana_crystal.0").withStyle(ChatFormatting.GRAY));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.lzxnone.terraria.item.weapon.summon.whip;
|
||||
|
||||
import com.lzxnone.terraria.entity.summon.StaticSummon;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.item.Tiers;
|
||||
|
||||
public class Possession extends Whip {
|
||||
private static final double RANGE = 32.0D;
|
||||
private static final float DAMAGE = 5.0F;
|
||||
private static final int ROTATE = 60;
|
||||
|
||||
public Possession() {
|
||||
super(Tiers.NETHERITE, new Item.Properties().stacksTo(1).fireResistant().rarity(Rarity.RARE));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double getRange() {
|
||||
return RANGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRes(StaticSummon summon) {
|
||||
return "lzxnoneterraria:textures/vfx/possession_projectile" + summon.getRandom().nextInt(3) + ".png";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getDamage() {
|
||||
return DAMAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLifetime() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRotateAngle() {
|
||||
return ROTATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getCooldown() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getInvulnerableTime() {
|
||||
return 12;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
package com.lzxnone.terraria.item.weapon.summon.whip;
|
||||
|
||||
import com.lzxnone.terraria.entity.ModEntities;
|
||||
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.weapon.SummonWeapon;
|
||||
import com.lzxnone.terraria.utils.CollisionUtil;
|
||||
import com.lzxnone.terraria.utils.DamageUtil;
|
||||
import com.lzxnone.terraria.utils.MathUtil;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
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.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Tier;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Whip extends SummonWeapon {
|
||||
private static final int SEGMENTS = 24;
|
||||
private static final double HITBOX_INFLATE = 1.0D;
|
||||
private static final double SUMMON_OFFSET_X = -1.0D;
|
||||
private static final double SUMMON_OFFSET_Y = 1.0D;
|
||||
private static final double SUMMON_OFFSET_Z = 0.0D;
|
||||
|
||||
protected Whip(Tier tier, Item.Properties properties) {
|
||||
super(tier, properties);
|
||||
}
|
||||
|
||||
protected abstract double getRange();
|
||||
|
||||
protected abstract String getRes(StaticSummon summon);
|
||||
|
||||
protected abstract float getDamage();
|
||||
|
||||
protected abstract int getLifetime();
|
||||
|
||||
protected double getHeight() {
|
||||
return getRange() * 0.5D;
|
||||
}
|
||||
|
||||
protected double getBend() {
|
||||
return getRange() * 0.25D;
|
||||
}
|
||||
|
||||
protected int getCooldown() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
protected float getKnockbackScale() {
|
||||
return 1.0F;
|
||||
}
|
||||
|
||||
protected int getInvulnerableTime() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
protected int getRotateAngle() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() {
|
||||
@Override
|
||||
public void tick(StaticSummon summon) {
|
||||
this.checkBeforeTick(summon);
|
||||
if(summon.isRemoved()) return;
|
||||
|
||||
Entity owner = summon.getOwner();
|
||||
if(owner == null) return;
|
||||
|
||||
Vector3f[] dirs = MathUtil.computeCoordinateSystem(owner);
|
||||
summon.setPos(new Vec3(
|
||||
owner.getX() + dirs[0].x * SUMMON_OFFSET_Z + dirs[1].x * SUMMON_OFFSET_Y + dirs[2].x * SUMMON_OFFSET_X,
|
||||
owner.getY() + dirs[0].y * SUMMON_OFFSET_Z + dirs[1].y * SUMMON_OFFSET_Y + dirs[2].y * SUMMON_OFFSET_X,
|
||||
owner.getZ() + dirs[0].z * SUMMON_OFFSET_Z + dirs[1].z * SUMMON_OFFSET_Y + dirs[2].z * SUMMON_OFFSET_X
|
||||
));
|
||||
hurtTargets(summon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBoxForCulling(StaticSummon summon) {
|
||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
|
||||
double range = customData.contains("range") ? customData.getDouble("range") : 8.0D;
|
||||
double height = customData.contains("height") ? customData.getDouble("height") : range * 0.5D;
|
||||
double bend = customData.contains("bend") ? customData.getDouble("bend") : range * 0.25D;
|
||||
double radius = range + height + bend + HITBOX_INFLATE;
|
||||
return AABB.ofSize(summon.position(), radius * 2.0D, radius * 2.0D, radius * 2.0D);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
|
||||
if(!level.isClientSide()) {
|
||||
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
|
||||
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level);
|
||||
summon.setOwner(player);
|
||||
summon.getEntityData().set(StaticSummon.STACK_SOURCE, stack.copy());
|
||||
summon.setPos(new Vec3(
|
||||
player.getX() + dirs[0].x * SUMMON_OFFSET_Z + dirs[1].x * SUMMON_OFFSET_Y + dirs[2].x * SUMMON_OFFSET_X,
|
||||
player.getY() + dirs[0].y * SUMMON_OFFSET_Z + dirs[1].y * SUMMON_OFFSET_Y + dirs[2].y * SUMMON_OFFSET_X,
|
||||
player.getZ() + dirs[0].z * SUMMON_OFFSET_Z + dirs[1].z * SUMMON_OFFSET_Y + dirs[2].z * SUMMON_OFFSET_X
|
||||
));
|
||||
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.POSSESSION);
|
||||
summon.getEntityData().set(StaticSummon.RENDER_MODE, "custom");
|
||||
summon.getEntityData().set(StaticSummon.LIFETIME, getLifetime());
|
||||
|
||||
int rotateAngle = (int)((player.getRandom().nextFloat() * 2.0F - 1.0F) * getRotateAngle());
|
||||
dirs = MathUtil.rotateCoordinateSystem(dirs[0], dirs[2], rotateAngle);
|
||||
CompoundTag customData = new CompoundTag();
|
||||
customData.putFloat("dirX", dirs[0].x);
|
||||
customData.putFloat("dirY", dirs[0].y);
|
||||
customData.putFloat("dirZ", dirs[0].z);
|
||||
customData.putFloat("upX", dirs[1].x);
|
||||
customData.putFloat("upY", dirs[1].y);
|
||||
customData.putFloat("upZ", dirs[1].z);
|
||||
customData.putFloat("rightX", dirs[2].x);
|
||||
customData.putFloat("rightY", dirs[2].y);
|
||||
customData.putFloat("rightZ", dirs[2].z);
|
||||
customData.putDouble("range", getRange());
|
||||
customData.putDouble("height", getHeight());
|
||||
customData.putDouble("bend", getBend());
|
||||
customData.putBoolean("reverse", summon.getRandom().nextInt(2) == 0);
|
||||
customData.putString("res", getRes(summon));
|
||||
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
|
||||
|
||||
summon.setNoGravity(true);
|
||||
summon.noPhysics = true;
|
||||
|
||||
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
|
||||
summon.setXRot(xyRot[0]);
|
||||
summon.setYRot(xyRot[1]);
|
||||
summon.setDeltaMovement(Vec3.ZERO);
|
||||
level.addFreshEntity(summon);
|
||||
}
|
||||
|
||||
player.getCooldowns().addCooldown(stack.getItem(), getCooldown());
|
||||
return InteractionResultHolder.sidedSuccess(stack, level.isClientSide());
|
||||
}
|
||||
|
||||
private static void hurtTargets(StaticSummon summon) {
|
||||
if(summon.level().isClientSide()) return;
|
||||
|
||||
ItemStack sourceStack = summon.getEntityData().get(StaticSummon.STACK_SOURCE);
|
||||
if(!(sourceStack.getItem() instanceof Whip whip)) return;
|
||||
|
||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
|
||||
int lifetime = Math.max(1, summon.getEntityData().get(StaticSummon.LIFETIME));
|
||||
float progress = Mth.clamp(summon.getEntityData().get(StaticSummon.AGE) / (float)lifetime, 0.0F, 1.0F);
|
||||
|
||||
Vec3 hand = summon.position();
|
||||
Vec3 dir = readVec3(customData, "dir", new Vec3(0.0D, 0.0D, 1.0D)).normalize();
|
||||
Vec3 up = readVec3(customData, "up", new Vec3(0.0D, 1.0D, 0.0D)).normalize();
|
||||
if(dir.lengthSqr() < 1.0E-6D) dir = new Vec3(0.0D, 0.0D, 1.0D);
|
||||
if(up.lengthSqr() < 1.0E-6D) up = new Vec3(0.0D, 1.0D, 0.0D);
|
||||
|
||||
double range = customData.contains("range") ? customData.getDouble("range") : whip.getRange();
|
||||
double height = customData.contains("height") ? customData.getDouble("height") : whip.getHeight();
|
||||
double bend = customData.contains("bend") ? customData.getDouble("bend") : whip.getBend();
|
||||
boolean reverse = customData.contains("reverse") && customData.getBoolean("reverse");
|
||||
List<Vec3> points = computePoints(hand, dir, up, progress, range, height, bend, reverse, SEGMENTS);
|
||||
|
||||
double radius = range + height + bend + HITBOX_INFLATE;
|
||||
AABB searchBox = AABB.ofSize(hand, radius * 2.0D, radius * 2.0D, radius * 2.0D);
|
||||
|
||||
for(Entity target : CollisionUtil.searchEntities(summon.level(), searchBox, summon, summon.getOwner())) {
|
||||
if(!intersectsWhip(points, target)) continue;
|
||||
if(DamageUtil.summonAttack(summon, target, sourceStack, whip.getDamage(), whip.getKnockbackScale())) {
|
||||
target.invulnerableTime = whip.getInvulnerableTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean intersectsWhip(List<Vec3> points, Entity target) {
|
||||
AABB targetBox = target.getBoundingBox().inflate(HITBOX_INFLATE);
|
||||
for(int i = 0; i < points.size() - 1; i++) {
|
||||
if(targetBox.clip(points.get(i), points.get(i + 1)).isPresent()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<Vec3> computePoints(Vec3 hand, Vec3 dir, Vec3 up, float progress, double range, double height, double bend, boolean reverse, int segments) {
|
||||
float phase = 1.0F - Math.abs(progress * 2.0F - 1.0F);
|
||||
float s = easeInOut(phase);
|
||||
float tipArc = 4.0F * s * (1.0F - s);
|
||||
Vec3 tip = hand
|
||||
.add(dir.scale(range * s))
|
||||
.add(up.scale(height * tipArc));
|
||||
Vec3 chord = tip.subtract(hand);
|
||||
double bendAmount = bend * (1.0F - s);
|
||||
Vec3 dynamicBendDir = dir.scale(1.0F - s).add(up.scale(-s)).normalize();
|
||||
if(dynamicBendDir.lengthSqr() < 1.0E-6D) dynamicBendDir = dir;
|
||||
|
||||
List<Vec3> points = new ArrayList<>(segments + 1);
|
||||
for(int i = 0; i <= segments; i++) {
|
||||
float t = i / (float)segments;
|
||||
float shape = 4.0F * t * (1.0F - t);
|
||||
Vec3 base = hand.add(chord.scale(t));
|
||||
Vec3 point = base.add(dynamicBendDir.scale(shape * bendAmount));
|
||||
boolean reflect = reverse ? progress <= 0.5F : progress > 0.5F;
|
||||
points.add(reflect ? reflectAcrossDir(hand, dir, point) : point);
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
private static Vec3 reflectAcrossDir(Vec3 hand, Vec3 dir, Vec3 point) {
|
||||
Vec3 relative = point.subtract(hand);
|
||||
Vec3 parallel = dir.scale(relative.dot(dir));
|
||||
Vec3 perpendicular = relative.subtract(parallel);
|
||||
return hand.add(parallel.subtract(perpendicular));
|
||||
}
|
||||
|
||||
private static Vec3 readVec3(CompoundTag tag, String prefix, Vec3 fallback) {
|
||||
String x = prefix + "X";
|
||||
String y = prefix + "Y";
|
||||
String z = prefix + "Z";
|
||||
if(!tag.contains(x) || !tag.contains(y) || !tag.contains(z)) return fallback;
|
||||
return new Vec3(tag.getDouble(x), tag.getDouble(y), tag.getDouble(z));
|
||||
}
|
||||
|
||||
private static float easeInOut(float value) {
|
||||
return value < 0.5F ? 2.0F * value * value : 1.0F - (float)Math.pow(-2.0F * value + 2.0F, 2.0D) / 2.0F;
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@
|
||||
"item.lzxnoneterraria.devils_devastation": "Devil's Devastation",
|
||||
"item.lzxnoneterraria.last_prism": "Last Prism",
|
||||
"item.lzxnoneterraria.terraprisma": "Terraprisma",
|
||||
"item.lzxnoneterraria.possession": "Possession",
|
||||
"item.lzxnoneterraria.musket": "Musket",
|
||||
"item.lzxnoneterraria.minishark": "Minishark",
|
||||
"item.lzxnoneterraria.flintlock_pistol": "Flintlock Pistol",
|
||||
@@ -78,6 +79,7 @@
|
||||
"item.lzxnoneterraria.fallen_star": "Fallen Star",
|
||||
"item.lzxnoneterraria.natures_gift": "Nature's Gift",
|
||||
"item.lzxnoneterraria.mana_flower": "Mana Flower",
|
||||
"item.lzxnoneterraria.mana_crystal": "Mana Crystal",
|
||||
|
||||
"enchantment.lzxnoneterraria.mana_leak": "Mana Leak",
|
||||
"enchantment.lzxnoneterraria.mana_efficiency": "Mana Efficiency",
|
||||
@@ -105,6 +107,7 @@
|
||||
"tooltip.lzxnoneterraria.natures_gift.0": "6% reduced mana cost",
|
||||
"tooltip.lzxnoneterraria.mana_flower.0": "8% reduced mana cost",
|
||||
"tooltip.lzxnoneterraria.mana_flower.1": "Automatically uses mana potions when mana runs out",
|
||||
"tooltip.lzxnoneterraria.mana_crystal.0": "Permanently increases maximum mana by 20, up to 200",
|
||||
|
||||
"entity.lzxnoneterraria.static_projectile": "Projectile",
|
||||
"entity.lzxnoneterraria.static_summon": "Summon",
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"item.lzxnoneterraria.devils_devastation": "破灭魔王剑",
|
||||
"item.lzxnoneterraria.last_prism": "终极棱镜",
|
||||
"item.lzxnoneterraria.terraprisma": "泰拉棱镜",
|
||||
"item.lzxnoneterraria.possession": "支配之鞭",
|
||||
"item.lzxnoneterraria.musket": "火枪",
|
||||
"item.lzxnoneterraria.minishark": "迷你鲨",
|
||||
"item.lzxnoneterraria.flintlock_pistol": "燧发枪",
|
||||
@@ -78,6 +79,7 @@
|
||||
"item.lzxnoneterraria.fallen_star": "坠落之星",
|
||||
"item.lzxnoneterraria.natures_gift": "大自然的恩赐",
|
||||
"item.lzxnoneterraria.mana_flower": "魔力花",
|
||||
"item.lzxnoneterraria.mana_crystal": "魔力水晶",
|
||||
|
||||
"enchantment.lzxnoneterraria.mana_leak": "魔力泄漏",
|
||||
"enchantment.lzxnoneterraria.mana_efficiency": "魔力效率",
|
||||
@@ -105,6 +107,7 @@
|
||||
"tooltip.lzxnoneterraria.natures_gift.0": "魔力花费降低 6%",
|
||||
"tooltip.lzxnoneterraria.mana_flower.0": "魔力花费降低 8%",
|
||||
"tooltip.lzxnoneterraria.mana_flower.1": "魔力枯竭时自动使用魔力药水",
|
||||
"tooltip.lzxnoneterraria.mana_crystal.0": "永久提升 20 点最大魔力,最高提升到 200",
|
||||
|
||||
"entity.lzxnoneterraria.static_projectile": "弹射物",
|
||||
"entity.lzxnoneterraria.static_summon": "召唤物",
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "lzxnoneterraria:item/item",
|
||||
"textures": {
|
||||
"layer0": "lzxnoneterraria:item/mana_crystal"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "lzxnoneterraria:item/whip",
|
||||
"textures": {
|
||||
"layer0": "lzxnoneterraria:item/possession"
|
||||
}
|
||||
}
|
||||
@@ -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, 6.2, 0.0],
|
||||
"scale": [0.68, 0.68, 0.68]
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 209 B |
Binary file not shown.
|
After Width: | Height: | Size: 300 B |
Binary file not shown.
|
After Width: | Height: | Size: 674 B |
Binary file not shown.
|
After Width: | Height: | Size: 655 B |
Binary file not shown.
|
After Width: | Height: | Size: 657 B |
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"lzxnoneterraria:terraprisma"
|
||||
"lzxnoneterraria:terraprisma",
|
||||
"lzxnoneterraria:possession"
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user