v1.8.1
This commit is contained in:
1 parent
67bdb76fe4
commit
94e10c465f
7 files changed
+514
-366
No files matched your search
+2
-3
@@ -5,11 +5,10 @@ import com.lzxnone.terraria.client.item.magic.ClientStellarTune;
|
||||
import com.lzxnone.terraria.client.item.magic.ClientNebulaArcanum;
|
||||
import com.lzxnone.terraria.client.item.melee.ClientBladeOfGrass;
|
||||
import com.lzxnone.terraria.client.item.melee.ClientDevilsDevastation;
|
||||
import com.lzxnone.terraria.client.item.melee.ClientMace;
|
||||
import com.lzxnone.terraria.client.item.melee.ClientFlail;
|
||||
import com.lzxnone.terraria.client.item.melee.ClientMuramasa;
|
||||
import com.lzxnone.terraria.client.item.melee.ClientStarfallProjectile;
|
||||
import com.lzxnone.terraria.client.item.melee.ClientZenith;
|
||||
import com.lzxnone.terraria.client.item.ranged.ClientFlamethrower;
|
||||
import com.lzxnone.terraria.client.item.ranged.ClientSuperStarShooter;
|
||||
import com.lzxnone.terraria.client.item.summon.ClientPossession;
|
||||
import com.lzxnone.terraria.client.item.summon.ClientStardustCellStaff;
|
||||
@@ -31,7 +30,7 @@ public class ClientStaticProjectileRenderBehaviors {
|
||||
BEHAVIORS.put(StaticProjectileBehaviors.ZENITH_PROJECTILE, ClientZenith.PROJECTILE_BEHAVIOR);
|
||||
BEHAVIORS.put(StaticProjectileBehaviors.MURAMASA_PROJECTILE, ClientMuramasa.PROJECTILE_BEHAVIOR);
|
||||
BEHAVIORS.put(StaticProjectileBehaviors.LEAF_PROJECTILE, ClientBladeOfGrass.PROJECTILE_BEHAVIOR);
|
||||
BEHAVIORS.put(StaticProjectileBehaviors.MACE_PROJECTILE, ClientMace.PROJECTILE_BEHAVIOR);
|
||||
BEHAVIORS.put(StaticProjectileBehaviors.FLAIL_PROJECTILE, ClientFlail.PROJECTILE_BEHAVIOR);
|
||||
BEHAVIORS.put(StaticProjectileBehaviors.DEVILS_DEVASTATION_PROJECTILE, ClientDevilsDevastation.PROJECTILE_BEHAVIOR);
|
||||
BEHAVIORS.put(StaticProjectileBehaviors.DEVILS_DEVASTATION_PROJECTILE2, ClientDevilsDevastation.PROJECTILE_BEHAVIOR2);
|
||||
BEHAVIORS.put(StaticProjectileBehaviors.DEVILS_DEVASTATION_PROJECTILE3, ClientDevilsDevastation.PROJECTILE_BEHAVIOR3);
|
||||
|
||||
+2
-2
@@ -12,7 +12,7 @@ import com.lzxnone.terraria.client.item.magic.ClientNebulaBlaze;
|
||||
import com.lzxnone.terraria.client.item.melee.ClientDevilsDevastation;
|
||||
import com.lzxnone.terraria.client.item.melee.ClientFirstFractal;
|
||||
import com.lzxnone.terraria.client.item.melee.ClientLightsBane;
|
||||
import com.lzxnone.terraria.client.item.melee.ClientMace;
|
||||
import com.lzxnone.terraria.client.item.melee.ClientFlail;
|
||||
import com.lzxnone.terraria.client.item.melee.ClientMeowmere;
|
||||
import com.lzxnone.terraria.client.item.melee.ClientNightsEdge;
|
||||
import com.lzxnone.terraria.client.item.melee.ClientTerraBlade;
|
||||
@@ -52,7 +52,7 @@ public class ClientStaticSummonRenderBehaviors {
|
||||
BEHAVIORS.put(StaticSummonBehaviors.VOLCANO_LIGHT, DEFAULT_BEHAVIOR);
|
||||
BEHAVIORS.put(StaticSummonBehaviors.TERRAGRIM_BEAM, ClientTerragrim.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(StaticSummonBehaviors.FIRST_FRACTAL_PROJECTILE, ClientFirstFractal.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(StaticSummonBehaviors.MACE_PROJECTILE, ClientMace.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(StaticSummonBehaviors.FLAIL_PROJECTILE, ClientFlail.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(StaticSummonBehaviors.DEVILS_DEVASTATION_STUCK_PROJECTILE, DEFAULT_BEHAVIOR);
|
||||
BEHAVIORS.put(StaticSummonBehaviors.DEVILS_DEVASTATION_LIGHTNING, ClientDevilsDevastation.SUMMON_BEHAVIOR2);
|
||||
BEHAVIORS.put(StaticSummonBehaviors.DEVILS_DEVASTATION_MARK, ClientDevilsDevastation.SUMMON_BEHAVIOR3);
|
||||
|
||||
+28
-10
@@ -2,6 +2,7 @@ package com.lzxnone.terraria.client.item.melee;
|
||||
|
||||
import com.lzxnone.terraria.entity.projectile.StaticProjectile;
|
||||
import com.lzxnone.terraria.entity.summon.StaticSummon;
|
||||
import com.lzxnone.terraria.item.weapon.melee.flail.Flail;
|
||||
import com.lzxnone.terraria.utils.*;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
@@ -10,16 +11,27 @@ 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.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.HumanoidArm;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.phys.*;
|
||||
import org.joml.Vector3f;
|
||||
import com.lzxnone.terraria.client.entity.projectile.IStaticProjectileRenderBehavior;
|
||||
import com.lzxnone.terraria.client.entity.summon.IStaticSummonRenderBehavior;
|
||||
import static com.lzxnone.terraria.item.weapon.melee.Mace.*;
|
||||
|
||||
public class ClientMace {
|
||||
public class ClientFlail {
|
||||
private static double getRightSign(boolean mainHand, Entity owner) {
|
||||
if(!(owner instanceof Player player)) return 1.0;
|
||||
boolean isRightHand = mainHand == (player.getMainArm() == HumanoidArm.RIGHT);
|
||||
return isRightHand ? 1.0 : -1.0;
|
||||
}
|
||||
|
||||
public static final float CHAIN_LENGTH = 0.25f;
|
||||
|
||||
public static final IStaticProjectileRenderBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileRenderBehavior() {
|
||||
@Override
|
||||
public void render(Entity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) {
|
||||
@@ -27,6 +39,8 @@ public class ClientMace {
|
||||
if(projectile.getOwner() == null) return;
|
||||
ItemStack itemStack = projectile.getEntityData().get(StaticProjectile.ITEM);
|
||||
if(itemStack == ItemStack.EMPTY) return;
|
||||
CompoundTag customData = projectile.getEntityData().get(StaticProjectile.CUSTOM_DATA);
|
||||
ResourceLocation chainRes = ResourceLocation.parse(customData.contains("chainRes") ? customData.getString("chainRes") : "");
|
||||
|
||||
Vector3f[] dirs = MathUtil.computeCoordinateSystem(projectile.getOwner());
|
||||
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
|
||||
@@ -69,10 +83,11 @@ public class ClientMace {
|
||||
|
||||
if(projectile.getOwner() == null) return;
|
||||
Vec3 eyePos = projectile.getOwner().getEyePosition();
|
||||
boolean projectileMainHand = customData.getBoolean("mainHand");
|
||||
Vec3 start = eyePos.add(new Vec3(
|
||||
dirs[0].x * DIRECTION_OFFSET + dirs[1].x * UP_OFFSET + dirs[2].x * RIGHT_OFFSET,
|
||||
dirs[0].y * DIRECTION_OFFSET + dirs[1].y * UP_OFFSET + dirs[2].y * RIGHT_OFFSET,
|
||||
dirs[0].z * DIRECTION_OFFSET + dirs[1].z * UP_OFFSET + dirs[2].z * RIGHT_OFFSET
|
||||
dirs[0].x * Flail.DIRECTION_OFFSET + dirs[1].x * Flail.UP_OFFSET + dirs[2].x * Flail.RIGHT_OFFSET * getRightSign(projectileMainHand, projectile.getOwner()),
|
||||
dirs[0].y * Flail.DIRECTION_OFFSET + dirs[1].y * Flail.UP_OFFSET + dirs[2].y * Flail.RIGHT_OFFSET * getRightSign(projectileMainHand, projectile.getOwner()),
|
||||
dirs[0].z * Flail.DIRECTION_OFFSET + dirs[1].z * Flail.UP_OFFSET + dirs[2].z * Flail.RIGHT_OFFSET * getRightSign(projectileMainHand, projectile.getOwner())
|
||||
));
|
||||
Vec3 end = projectile.getPosition(partialTick);
|
||||
double dist = end.subtract(start).length();
|
||||
@@ -81,7 +96,7 @@ public class ClientMace {
|
||||
Vec3 right = MathUtil.toVec3(dirs2[2]);
|
||||
Vec3 up = MathUtil.toVec3(dirs2[1]);
|
||||
|
||||
VertexConsumer vertexConsumer = bufferSource.getBuffer(RenderType.entityCutoutNoCull(RES));
|
||||
VertexConsumer vertexConsumer = bufferSource.getBuffer(RenderType.entityCutoutNoCull(chainRes));
|
||||
|
||||
int count = (int) (dist / CHAIN_LENGTH);
|
||||
for(int j = 0;j < 2;j++) {
|
||||
@@ -134,6 +149,8 @@ public class ClientMace {
|
||||
if(!(entity instanceof StaticSummon summon)) return;
|
||||
ItemStack itemStack = summon.getEntityData().get(StaticSummon.ITEM);
|
||||
if(itemStack == ItemStack.EMPTY) return;
|
||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
|
||||
ResourceLocation chainRes = ResourceLocation.parse(customData.contains("chainRes") ? customData.getString("chainRes") : "");
|
||||
|
||||
poseStack.pushPose();
|
||||
|
||||
@@ -174,10 +191,11 @@ public class ClientMace {
|
||||
if(summon.getOwner() == null) return;
|
||||
Vector3f[] dirs = MathUtil.computeCoordinateSystem(summon.getOwner());
|
||||
Vec3 eyePos = summon.getOwner().getEyePosition();
|
||||
boolean summonMainHand = summon.getEntityData().get(StaticSummon.CUSTOM_DATA).getBoolean("mainHand");
|
||||
Vec3 start = eyePos.add(new Vec3(
|
||||
dirs[0].x * DIRECTION_OFFSET + dirs[1].x * UP_OFFSET + dirs[2].x * RIGHT_OFFSET,
|
||||
dirs[0].y * DIRECTION_OFFSET + dirs[1].y * UP_OFFSET + dirs[2].y * RIGHT_OFFSET,
|
||||
dirs[0].z * DIRECTION_OFFSET + dirs[1].z * UP_OFFSET + dirs[2].z * RIGHT_OFFSET
|
||||
dirs[0].x * Flail.DIRECTION_OFFSET + dirs[1].x * Flail.UP_OFFSET + dirs[2].x * Flail.RIGHT_OFFSET * getRightSign(summonMainHand, summon.getOwner()),
|
||||
dirs[0].y * Flail.DIRECTION_OFFSET + dirs[1].y * Flail.UP_OFFSET + dirs[2].y * Flail.RIGHT_OFFSET * getRightSign(summonMainHand, summon.getOwner()),
|
||||
dirs[0].z * Flail.DIRECTION_OFFSET + dirs[1].z * Flail.UP_OFFSET + dirs[2].z * Flail.RIGHT_OFFSET * getRightSign(summonMainHand, summon.getOwner())
|
||||
));
|
||||
Vec3 end = summon.getPosition(partialTick);
|
||||
double dist = end.subtract(start).length();
|
||||
@@ -186,7 +204,7 @@ public class ClientMace {
|
||||
Vec3 right = MathUtil.toVec3(dirs2[2]);
|
||||
Vec3 up = MathUtil.toVec3(dirs2[1]);
|
||||
|
||||
VertexConsumer vertexConsumer = bufferSource.getBuffer(RenderType.entityCutoutNoCull(RES));
|
||||
VertexConsumer vertexConsumer = bufferSource.getBuffer(RenderType.entityCutoutNoCull(chainRes));
|
||||
|
||||
int count = (int) (dist / CHAIN_LENGTH);
|
||||
for(int j = 0;j < 2;j++) {
|
||||
@@ -5,6 +5,7 @@ import com.lzxnone.terraria.item.effect.FallenStarSummoner;
|
||||
import com.lzxnone.terraria.item.weapon.magic.NebulaArcanum;
|
||||
import com.lzxnone.terraria.item.weapon.magic.StellarTune;
|
||||
import com.lzxnone.terraria.item.weapon.melee.*;
|
||||
import com.lzxnone.terraria.item.weapon.melee.flail.Flail;
|
||||
import com.lzxnone.terraria.item.weapon.ranged.Flamethrower;
|
||||
import com.lzxnone.terraria.item.weapon.ranged.SuperStarShooter;
|
||||
import com.lzxnone.terraria.item.weapon.summon.whip.Possession;
|
||||
@@ -26,7 +27,7 @@ public class StaticProjectileBehaviors {
|
||||
public static final String ZENITH_PROJECTILE = "zenith_projectile";
|
||||
public static final String MURAMASA_PROJECTILE = "muramasa_projectile";
|
||||
public static final String LEAF_PROJECTILE = "leaf_projectile";
|
||||
public static final String MACE_PROJECTILE = "mace_projectile";
|
||||
public static final String FLAIL_PROJECTILE = "flail_projectile";
|
||||
public static final String DEVILS_DEVASTATION_PROJECTILE = "devils_devastation_projectile";
|
||||
public static final String DEVILS_DEVASTATION_PROJECTILE2 = "devils_devastation_projectile2";
|
||||
public static final String DEVILS_DEVASTATION_PROJECTILE3 = "devils_devastation_projectile3";
|
||||
@@ -60,7 +61,7 @@ public class StaticProjectileBehaviors {
|
||||
BEHAVIORS.put(ZENITH_PROJECTILE, Zenith.PROJECTILE_BEHAVIOR);
|
||||
BEHAVIORS.put(MURAMASA_PROJECTILE, Muramasa.PROJECTILE_BEHAVIOR);
|
||||
BEHAVIORS.put(LEAF_PROJECTILE, BladeOfGrass.PROJECTILE_BEHAVIOR);
|
||||
BEHAVIORS.put(MACE_PROJECTILE, Mace.PROJECTILE_BEHAVIOR);
|
||||
BEHAVIORS.put(FLAIL_PROJECTILE, Flail.PROJECTILE_BEHAVIOR);
|
||||
BEHAVIORS.put(DEVILS_DEVASTATION_PROJECTILE, DevilsDevastation.PROJECTILE_BEHAVIOR);
|
||||
BEHAVIORS.put(DEVILS_DEVASTATION_PROJECTILE2, DevilsDevastation.PROJECTILE_BEHAVIOR2);
|
||||
BEHAVIORS.put(DEVILS_DEVASTATION_PROJECTILE3, DevilsDevastation.PROJECTILE_BEHAVIOR3);
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.lzxnone.terraria.item.weapon.magic.BubbleGun;
|
||||
import com.lzxnone.terraria.item.weapon.magic.LunarFlare;
|
||||
import com.lzxnone.terraria.item.weapon.magic.NebulaBlaze;
|
||||
import com.lzxnone.terraria.item.weapon.magic.NebulaArcanum;
|
||||
import com.lzxnone.terraria.item.weapon.melee.flail.Flail;
|
||||
import com.lzxnone.terraria.item.weapon.ranged.ElfMelter;
|
||||
import com.lzxnone.terraria.item.weapon.magic.LastPrism;
|
||||
import com.lzxnone.terraria.item.weapon.melee.*;
|
||||
@@ -45,7 +46,7 @@ public class StaticSummonBehaviors {
|
||||
public static final String VOLCANO_LIGHT = "volcano_light";
|
||||
public static final String TERRAGRIM_BEAM = "terragrim_beam";
|
||||
public static final String FIRST_FRACTAL_PROJECTILE = "first_fractal_projectile";
|
||||
public static final String MACE_PROJECTILE = "mace_projectile";
|
||||
public static final String FLAIL_PROJECTILE = "flail_projectile";
|
||||
public static final String DEVILS_DEVASTATION_STUCK_PROJECTILE = "devils_devastation_stuck_projectile";
|
||||
public static final String DEVILS_DEVASTATION_LIGHTNING = "devils_devastation_lightning";
|
||||
public static final String DEVILS_DEVASTATION_MARK = "devils_devastation_mark";
|
||||
@@ -108,7 +109,7 @@ public class StaticSummonBehaviors {
|
||||
BEHAVIORS.put(VOLCANO_LIGHT, Volcano.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(TERRAGRIM_BEAM, Terragrim.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(FIRST_FRACTAL_PROJECTILE, FirstFractal.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(MACE_PROJECTILE, Mace.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(FLAIL_PROJECTILE, Flail.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(DEVILS_DEVASTATION_STUCK_PROJECTILE, DevilsDevastation.SUMMON_BEHAVIOR);
|
||||
BEHAVIORS.put(DEVILS_DEVASTATION_LIGHTNING, DevilsDevastation.SUMMON_BEHAVIOR2);
|
||||
BEHAVIORS.put(DEVILS_DEVASTATION_MARK, DevilsDevastation.SUMMON_BEHAVIOR3);
|
||||
|
||||
@@ -10,6 +10,7 @@ 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.melee.flail.Flail;
|
||||
import com.lzxnone.terraria.utils.*;
|
||||
import com.mojang.math.Axis;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
@@ -41,7 +42,7 @@ import com.lzxnone.terraria.ui.config.struct.ConfigStruct;
|
||||
import java.util.List;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
|
||||
public class Mace extends MeleeWeapon {
|
||||
public class Mace extends Flail {
|
||||
public static final String ID = "mace";
|
||||
public static final ConfigFloat BASE_MELEE_DAMAGE = createBaseMeleeDamageConfig(ID, 3F);
|
||||
public static final ConfigFloat BASE_MELEE_ATTACK_SPEED = createBaseMeleeAttackSpeedConfig(ID, -2.4F);
|
||||
@@ -101,20 +102,6 @@ public class Mace extends MeleeWeapon {
|
||||
super(Tiers.IRON, new Item.Properties());
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTooltipDamage(ItemStack weaponStack, LivingEntity entity) {
|
||||
float damage = DAMAGE.get();
|
||||
//锋利附魔
|
||||
int sharpnessLevel = getEnchantmentLevel(entity, weaponStack, Enchantments.SHARPNESS);
|
||||
if(sharpnessLevel > 0) {
|
||||
damage += 1.0F + Math.max(0, sharpnessLevel - 1) * 0.5F;
|
||||
}
|
||||
//药水
|
||||
if(entity instanceof Player player) damage = DamageUtil.applyPlayerDamageEffects(player, damage);
|
||||
//近战加成
|
||||
return MeleeWeapon.applyMeleeDamageBonus(weaponStack, entity, damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getBaseMeleeDamage(ItemStack stack) {
|
||||
return BASE_MELEE_DAMAGE.get();
|
||||
@@ -125,348 +112,41 @@ public class Mace extends MeleeWeapon {
|
||||
return BASE_MELEE_ATTACK_SPEED.get();
|
||||
}
|
||||
|
||||
public enum State {
|
||||
IDLE,
|
||||
USING,
|
||||
THROWING,
|
||||
THROWING_BACK,
|
||||
DROPPING
|
||||
public ItemStack getItemStack() {
|
||||
return ModItems.MACE.get().getDefaultInstance();
|
||||
}
|
||||
|
||||
public static final ResourceLocation RES = ResourceLocation.parse("lzxnoneterraria:textures/vfx/mace_chain.png");
|
||||
public static final float CHAIN_LENGTH = 0.25f;
|
||||
|
||||
public static final double DIRECTION_OFFSET = 0.6;
|
||||
public static final double UP_OFFSET = -0.3;
|
||||
public static final double RIGHT_OFFSET = -0.3;
|
||||
|
||||
public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileBehavior() {
|
||||
|
||||
@Override
|
||||
public void onMoving(StaticProjectile projectile) {
|
||||
Entity entity = projectile.getOwner();
|
||||
if(!(entity instanceof Player player)) return;
|
||||
ItemStack stack = player.getItemInHand(InteractionHand.MAIN_HAND);
|
||||
if(!stack.is(ModItems.MACE.get())) {
|
||||
onDied(projectile);
|
||||
return;
|
||||
}
|
||||
|
||||
projectile.setBoundingBox(new AABB(
|
||||
projectile.getX() - 0.5f, projectile.getY() - 0.5f, projectile.getZ() - 0.5f,
|
||||
projectile.getX() + 0.5f, projectile.getY() + 0.5f, projectile.getZ() + 0.5f
|
||||
));
|
||||
|
||||
int state = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
|
||||
.copyTag().getInt("state");
|
||||
if(state == State.USING.ordinal()) {
|
||||
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
|
||||
Vec3 eyePos = player.getEyePosition();
|
||||
Vec3 pos = eyePos.add(new Vec3(
|
||||
dirs[0].x * DIRECTION_OFFSET + dirs[1].x * UP_OFFSET + dirs[2].x * RIGHT_OFFSET,
|
||||
dirs[0].y * DIRECTION_OFFSET + dirs[1].y * UP_OFFSET + dirs[2].y * RIGHT_OFFSET,
|
||||
dirs[0].z * DIRECTION_OFFSET + dirs[1].z * UP_OFFSET + dirs[2].z * RIGHT_OFFSET
|
||||
));
|
||||
projectile.getEntityData().set(StaticProjectile.ORIGIN, pos.toVector3f());
|
||||
projectile.getEntityData().set(StaticProjectile.DIRECTION, dirs[0]);
|
||||
projectile.getEntityData().set(StaticProjectile.UP, dirs[1]);
|
||||
projectile.getEntityData().set(StaticProjectile.RIGHT, dirs[2]);
|
||||
|
||||
if(!projectile.level().isClientSide()) {
|
||||
List<Entity> targets = projectile.level().getEntitiesOfClass(
|
||||
Entity.class,
|
||||
projectile.getBoundingBox(),
|
||||
FilterUtil.createTargetFilter(projectile, player)
|
||||
);
|
||||
for(Entity target : targets) {
|
||||
if(DamageUtil.meleeAttack(projectile, target, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE), (float) DAMAGE.get(), 1.0f, 10)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}else {
|
||||
onDied(projectile);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDied(StaticProjectile projectile) {
|
||||
Entity entity = projectile.getOwner();
|
||||
if(!(entity instanceof Player player)) {
|
||||
if(!projectile.level().isClientSide()) projectile.discard();
|
||||
return;
|
||||
}
|
||||
if(!projectile.level().isClientSide()) projectile.discard();
|
||||
}
|
||||
};
|
||||
|
||||
public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() {
|
||||
|
||||
@Override
|
||||
public AABB getBoundingBoxForCulling(StaticSummon summon) {
|
||||
Entity owner = summon.getOwner();
|
||||
if(owner != null) {
|
||||
AABB hammerBox = summon.getBoundingBox();
|
||||
AABB ownerBox = owner.getBoundingBoxForCulling();
|
||||
return hammerBox.minmax(ownerBox).inflate(1.0D);
|
||||
}
|
||||
return summon.getBoundingBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(StaticSummon summon) {
|
||||
this.checkBeforeTick(summon);
|
||||
Entity entity = summon.getOwner();
|
||||
if(!(entity instanceof Player player)) {
|
||||
onDied(summon);
|
||||
return;
|
||||
}
|
||||
ItemStack stack = player.getItemInHand(InteractionHand.MAIN_HAND);
|
||||
if(!stack.is(ModItems.MACE.get())) {
|
||||
onDied(summon);
|
||||
return;
|
||||
}
|
||||
summon.setBoundingBox(new AABB(
|
||||
summon.getX() - 0.25f, summon.getY() - 0.25f, summon.getZ() - 0.25f,
|
||||
summon.getX() + 0.25f, summon.getY() + 0.25f, summon.getZ() + 0.25f
|
||||
));
|
||||
int state = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
|
||||
.copyTag().getInt("state");
|
||||
if(state == State.THROWING.ordinal()) {
|
||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
|
||||
int flyTime = customData.contains("flyTime") ? customData.getInt("flyTime") : 0;
|
||||
int age = summon.getEntityData().get(StaticSummon.AGE);
|
||||
if(age < flyTime) {
|
||||
summon.setDeltaMovement(summon.getLookAngle().normalize().scale(PROJECTILE_SPEED.get()));
|
||||
BlockHitResult blockHitResult = CollisionUtil.checkBlockHit(summon, summon.position().add(summon.getDeltaMovement()));
|
||||
if(blockHitResult.getType() != HitResult.Type.MISS) {
|
||||
summon.getEntityData().set(StaticSummon.AGE, flyTime);
|
||||
if(summon.level() instanceof ServerLevel serverLevel) {
|
||||
BlockState hitState = serverLevel.getBlockState(blockHitResult.getBlockPos());
|
||||
ParticleUtil.addParticles(
|
||||
serverLevel, new BlockParticleOption(ParticleTypes.BLOCK, hitState),
|
||||
blockHitResult.getLocation(), new Vec3(0, 0, 0),
|
||||
0.2, 25
|
||||
);
|
||||
SoundUtil.playServerSound(serverLevel, ModSounds.DIG.get(), blockHitResult.getLocation());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
Vec3 moveDir = player.getEyePosition().subtract(summon.position());
|
||||
double dist = moveDir.length();
|
||||
summon.setDeltaMovement(moveDir.normalize().scale(PROJECTILE_SPEED.get()));
|
||||
if(dist < 2.0f) {
|
||||
onDied(summon);
|
||||
return;
|
||||
}
|
||||
BlockHitResult blockHitResult = CollisionUtil.checkBlockHit(summon, summon.position().add(summon.getDeltaMovement()));
|
||||
if(blockHitResult.getType() != HitResult.Type.MISS) {
|
||||
int hitBlockCount = customData.contains("hitBlockCount") ? customData.getInt("hitBlockCount") : 0;
|
||||
if(hitBlockCount > 10) {
|
||||
summon.noPhysics = true;
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", State.THROWING_BACK.ordinal()));
|
||||
}else {
|
||||
customData.putInt("hitBlockCount", hitBlockCount + 1);
|
||||
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
|
||||
}
|
||||
if(summon.level() instanceof ServerLevel serverLevel) {
|
||||
BlockState hitState = serverLevel.getBlockState(blockHitResult.getBlockPos());
|
||||
ParticleUtil.addParticles(
|
||||
serverLevel, new BlockParticleOption(ParticleTypes.BLOCK, hitState),
|
||||
blockHitResult.getLocation(), new Vec3(0, 0, 0),
|
||||
0.2, 25
|
||||
);
|
||||
SoundUtil.playServerSound(serverLevel, ModSounds.DIG.get(), blockHitResult.getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
double dist = summon.position().subtract(player.position()).length();
|
||||
if(dist > MAX_RANGE.get()) {
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", State.THROWING_BACK.ordinal()));
|
||||
}
|
||||
if(!summon.level().isClientSide()) {
|
||||
EntityHitResult entityHitResult = CollisionUtil.checkEntityHit(summon, summon.position().add(summon.getDeltaMovement()), 1.0);
|
||||
if(entityHitResult != null) {
|
||||
Entity target = entityHitResult.getEntity();
|
||||
if(DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float) DAMAGE.get(), 1.0f, 10)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(state == State.DROPPING.ordinal()) {
|
||||
Vec3 g = new Vec3(0, -1, 0);
|
||||
summon.setDeltaMovement(g.scale(GRAVITY.get()));
|
||||
double dist = summon.position().subtract(player.position()).length();
|
||||
if(dist > MAX_RANGE.get()) {
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", State.THROWING_BACK.ordinal()));
|
||||
}
|
||||
List<Entity> targets = summon.level().getEntitiesOfClass(
|
||||
Entity.class,
|
||||
summon.getBoundingBox(),
|
||||
FilterUtil.createTargetFilter(summon, summon.getOwner())
|
||||
);
|
||||
for(Entity target : targets) {
|
||||
DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float) DAMAGE.get(), 1.0f, 10);
|
||||
}
|
||||
}else if(state == State.THROWING_BACK.ordinal()){
|
||||
Vec3 moveDir = player.getEyePosition().subtract(summon.position());
|
||||
double dist = moveDir.length();
|
||||
summon.setDeltaMovement(moveDir.normalize().scale(PROJECTILE_SPEED.get()));
|
||||
if(!summon.noPhysics) {
|
||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
|
||||
BlockHitResult blockHitResult = CollisionUtil.checkBlockHit(summon, summon.position().add(summon.getDeltaMovement()));
|
||||
if(blockHitResult.getType() != HitResult.Type.MISS) {
|
||||
int hitBlockCount = customData.contains("hitBlockCount") ? customData.getInt("hitBlockCount") : 0;
|
||||
if(hitBlockCount > 10) {
|
||||
summon.noPhysics = true;
|
||||
}else {
|
||||
customData.putInt("hitBlockCount", hitBlockCount + 1);
|
||||
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
|
||||
}
|
||||
if(summon.level() instanceof ServerLevel serverLevel) {
|
||||
BlockState hitState = serverLevel.getBlockState(blockHitResult.getBlockPos());
|
||||
ParticleUtil.addParticles(
|
||||
serverLevel, new BlockParticleOption(ParticleTypes.BLOCK, hitState),
|
||||
blockHitResult.getLocation(), new Vec3(0, 0, 0),
|
||||
0.2, 25
|
||||
);
|
||||
SoundUtil.playServerSound(serverLevel, ModSounds.DIG.get(), blockHitResult.getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
EntityHitResult entityHitResult = CollisionUtil.checkEntityHit(summon, summon.position().add(summon.getDeltaMovement()), 1.0);
|
||||
if(entityHitResult != null) {
|
||||
Entity target = entityHitResult.getEntity();
|
||||
if(DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), (float) DAMAGE.get(), 1.0f, 10)) {
|
||||
}
|
||||
}
|
||||
if(dist < 2.0f) {
|
||||
onDied(summon);
|
||||
return;
|
||||
}
|
||||
}else {
|
||||
onDied(summon);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDied(StaticSummon summon) {
|
||||
Entity entity = summon.getOwner();
|
||||
if(!(entity instanceof Player player)) {
|
||||
if(!summon.level().isClientSide()) summon.discard();
|
||||
return;
|
||||
}
|
||||
ItemStack stack = player.getItemInHand(InteractionHand.MAIN_HAND);
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", State.IDLE.ordinal()));
|
||||
if(!summon.level().isClientSide()) summon.discard();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
int state = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
|
||||
.copyTag().getInt("state");
|
||||
if(state == State.IDLE.ordinal()) {
|
||||
StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level);
|
||||
projectile.setOwner(player);
|
||||
projectile.getEntityData().set(StaticProjectile.STACK_SOURCE, player.getWeaponItem().copy());
|
||||
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
|
||||
|
||||
Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ());
|
||||
projectile.setPos(pos);
|
||||
projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.MACE_PROJECTILE);
|
||||
projectile.getEntityData().set(StaticProjectile.RENDER_MODE, "custom");
|
||||
projectile.getEntityData().set(StaticProjectile.ITEM, new ItemStack(ModItems.MACE_PROJECTILE.get()));
|
||||
projectile.getEntityData().set(StaticProjectile.ORIGIN, pos.toVector3f());
|
||||
projectile.getEntityData().set(StaticProjectile.DIRECTION, dirs[0]);
|
||||
projectile.getEntityData().set(StaticProjectile.UP, dirs[1]);
|
||||
projectile.getEntityData().set(StaticProjectile.RIGHT, dirs[2]);
|
||||
projectile.getEntityData().set(StaticProjectile.EXPRESSION_Z, String.format("%.3f*cos(%.3f*t)", 1.0, 1.0));
|
||||
projectile.getEntityData().set(StaticProjectile.EXPRESSION_Y, String.format("%.3f*sin(%.3f*t)", 1.0, 1.0));
|
||||
|
||||
projectile.getEntityData().set(StaticProjectile.LIFETIME, 12000);
|
||||
level.addFreshEntity(projectile);
|
||||
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", State.USING.ordinal()));
|
||||
player.startUsingItem(hand);
|
||||
return InteractionResultHolder.consume(stack);
|
||||
}else if(state == State.THROWING.ordinal()) {
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", State.DROPPING.ordinal()));
|
||||
player.startUsingItem(hand);
|
||||
return InteractionResultHolder.consume(stack);
|
||||
}else {
|
||||
return InteractionResultHolder.pass(stack);
|
||||
}
|
||||
public ItemStack getProjectileItemStack() {
|
||||
return ModItems.MACE_PROJECTILE.get().getDefaultInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseUsing(ItemStack stack, Level level, LivingEntity entity, int timeLeft) {
|
||||
if(!(entity instanceof Player player)) return;
|
||||
int state = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
|
||||
.copyTag().getInt("state");
|
||||
if(state == State.USING.ordinal()) {
|
||||
if(!level.isClientSide()) {
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", State.THROWING.ordinal()));
|
||||
|
||||
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
|
||||
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
|
||||
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level);
|
||||
summon.setOwner(player);
|
||||
summon.getEntityData().set(StaticSummon.STACK_SOURCE, player.getWeaponItem().copy());
|
||||
Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ());
|
||||
summon.setPos(pos);
|
||||
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.MACE_PROJECTILE);
|
||||
summon.getEntityData().set(StaticSummon.RENDER_MODE, "custom");
|
||||
summon.getEntityData().set(StaticSummon.ITEM, new ItemStack(ModItems.MACE_PROJECTILE.get()));
|
||||
summon.getEntityData().set(StaticSummon.LIFETIME, 12000);
|
||||
|
||||
summon.setXRot(xyRot[0]);
|
||||
summon.xRotO = xyRot[0];
|
||||
summon.setYRot(xyRot[1]);
|
||||
summon.yRotO = xyRot[1];
|
||||
|
||||
CompoundTag customData = new CompoundTag();
|
||||
customData.putInt("flyTime", FLY_TIME.get());
|
||||
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
|
||||
|
||||
summon.setNoGravity(true);
|
||||
|
||||
level.addFreshEntity(summon);
|
||||
}
|
||||
}else if(state == State.DROPPING.ordinal()) {
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", State.THROWING_BACK.ordinal()));
|
||||
|
||||
}
|
||||
public String getChainRes() {
|
||||
return "lzxnoneterraria:textures/vfx/mace_chain.png";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull UseAnim getUseAnimation(ItemStack stack) {
|
||||
return UseAnim.BLOCK;
|
||||
public boolean canDrop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUseDuration(ItemStack stack, LivingEntity entity) {
|
||||
return 72000;
|
||||
public float getDamage() {
|
||||
return DAMAGE.get();
|
||||
}
|
||||
|
||||
@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(entity instanceof Player player) {
|
||||
if(!isSelected) {
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", State.IDLE.ordinal()));
|
||||
}
|
||||
}
|
||||
public int getFlyTime() {
|
||||
return FLY_TIME.get();
|
||||
}
|
||||
|
||||
public double getProjectileSpeed() {
|
||||
return PROJECTILE_SPEED.get();
|
||||
}
|
||||
|
||||
public double getGravity() {
|
||||
return GRAVITY.get();
|
||||
}
|
||||
|
||||
public double getMaxRange() {
|
||||
return MAX_RANGE.get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,449 @@
|
||||
package com.lzxnone.terraria.item.weapon.melee.flail;
|
||||
|
||||
import com.lzxnone.terraria.LzxnoneTerraria;
|
||||
import com.lzxnone.terraria.ModSounds;
|
||||
import com.lzxnone.terraria.entity.ModEntities;
|
||||
import com.lzxnone.terraria.entity.projectile.IStaticProjectileBehavior;
|
||||
import com.lzxnone.terraria.entity.projectile.StaticProjectile;
|
||||
import com.lzxnone.terraria.entity.projectile.StaticProjectileBehaviors;
|
||||
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.MeleeWeapon;
|
||||
import com.lzxnone.terraria.utils.*;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.particles.BlockParticleOption;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.HumanoidArm;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Tier;
|
||||
import net.minecraft.world.item.UseAnim;
|
||||
import net.minecraft.world.item.component.CustomData;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.*;
|
||||
import org.joml.Vector3f;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Flail extends MeleeWeapon {
|
||||
public static final double DIRECTION_OFFSET = 0.6;
|
||||
public static final double UP_OFFSET = -0.3;
|
||||
public static final double RIGHT_OFFSET = -0.5;
|
||||
|
||||
public static final double DROPPING_HITBOX_SIZE = 0.5;
|
||||
public static final double USING_HITBOX_SIZE = 0.5;
|
||||
public static final double THROWING_INFLATE = 2.0;
|
||||
|
||||
protected Flail(Tier tier, Properties properties) {
|
||||
super(tier, properties);
|
||||
}
|
||||
|
||||
public enum State {
|
||||
IDLE,
|
||||
USING,
|
||||
THROWING,
|
||||
THROWING_BACK,
|
||||
DROPPING
|
||||
}
|
||||
|
||||
public abstract ItemStack getItemStack();
|
||||
|
||||
public abstract ItemStack getProjectileItemStack();
|
||||
|
||||
public abstract String getChainRes();
|
||||
|
||||
public abstract boolean canDrop();
|
||||
|
||||
public abstract float getDamage();
|
||||
|
||||
public abstract int getFlyTime();
|
||||
|
||||
public abstract double getProjectileSpeed();
|
||||
|
||||
public abstract double getGravity();
|
||||
|
||||
public abstract double getMaxRange();
|
||||
|
||||
@Override
|
||||
public float getTooltipDamage(ItemStack weaponStack, LivingEntity entity) {
|
||||
float damage = getDamage();
|
||||
//锋利附魔
|
||||
int sharpnessLevel = getEnchantmentLevel(entity, weaponStack, Enchantments.SHARPNESS);
|
||||
if(sharpnessLevel > 0) {
|
||||
damage += 1.0F + Math.max(0, sharpnessLevel - 1) * 0.5F;
|
||||
}
|
||||
//药水
|
||||
if(entity instanceof Player player) damage = DamageUtil.applyPlayerDamageEffects(player, damage);
|
||||
//近战加成
|
||||
return MeleeWeapon.applyMeleeDamageBonus(weaponStack, entity, damage);
|
||||
}
|
||||
|
||||
//来回甩
|
||||
public static final IStaticProjectileBehavior PROJECTILE_BEHAVIOR = new IStaticProjectileBehavior() {
|
||||
@Override
|
||||
public void onMoving(StaticProjectile projectile) {
|
||||
Entity entity = projectile.getOwner();
|
||||
if(!(entity instanceof Player player)) return;
|
||||
if(!player.isUsingItem()) {
|
||||
onDied(projectile);
|
||||
return;
|
||||
}
|
||||
ItemStack stack = player.getUseItem();
|
||||
if(!(stack.getItem() instanceof Flail flail)) {
|
||||
onDied(projectile);
|
||||
return;
|
||||
}
|
||||
if(!stack.is(flail.getItemStack().getItem())) {
|
||||
onDied(projectile);
|
||||
return;
|
||||
}
|
||||
|
||||
int state = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
|
||||
.copyTag().getInt("state");
|
||||
if(state == Flail.State.USING.ordinal()) {
|
||||
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
|
||||
Vec3 eyePos = player.getEyePosition();
|
||||
boolean mainHand = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
|
||||
.copyTag().getBoolean("mainHand");
|
||||
boolean isRightHand = mainHand == (player.getMainArm() == HumanoidArm.RIGHT);
|
||||
double rightSign = isRightHand ? 1.0 : -1.0;
|
||||
Vec3 pos = eyePos.add(new Vec3(
|
||||
dirs[0].x * DIRECTION_OFFSET + dirs[1].x * UP_OFFSET + dirs[2].x * RIGHT_OFFSET * rightSign,
|
||||
dirs[0].y * DIRECTION_OFFSET + dirs[1].y * UP_OFFSET + dirs[2].y * RIGHT_OFFSET * rightSign,
|
||||
dirs[0].z * DIRECTION_OFFSET + dirs[1].z * UP_OFFSET + dirs[2].z * RIGHT_OFFSET * rightSign
|
||||
));
|
||||
projectile.getEntityData().set(StaticProjectile.ORIGIN, pos.toVector3f());
|
||||
projectile.getEntityData().set(StaticProjectile.DIRECTION, dirs[0]);
|
||||
projectile.getEntityData().set(StaticProjectile.UP, dirs[1]);
|
||||
projectile.getEntityData().set(StaticProjectile.RIGHT, dirs[2]);
|
||||
|
||||
if(!projectile.level().isClientSide()) {
|
||||
List<Entity> targets = projectile.level().getEntitiesOfClass(
|
||||
Entity.class,
|
||||
new AABB(
|
||||
projectile.getX() - USING_HITBOX_SIZE, projectile.getY() - USING_HITBOX_SIZE, projectile.getZ() - USING_HITBOX_SIZE,
|
||||
projectile.getX() + USING_HITBOX_SIZE, projectile.getY() + USING_HITBOX_SIZE, projectile.getZ() + USING_HITBOX_SIZE
|
||||
),
|
||||
FilterUtil.createTargetFilter(projectile, player)
|
||||
);
|
||||
for(Entity target : targets) {
|
||||
if(DamageUtil.meleeAttack(projectile, target, projectile.getEntityData().get(StaticProjectile.STACK_SOURCE), flail.getDamage(), 1.0f, 10)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}else {
|
||||
onDied(projectile);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static final IStaticSummonBehavior SUMMON_BEHAVIOR = new IStaticSummonBehavior() {
|
||||
@Override
|
||||
public AABB getBoundingBoxForCulling(StaticSummon summon) {
|
||||
Entity owner = summon.getOwner();
|
||||
if(owner != null) {
|
||||
AABB hammerBox = summon.getBoundingBox();
|
||||
AABB ownerBox = owner.getBoundingBoxForCulling();
|
||||
return hammerBox.minmax(ownerBox).inflate(1.0D);
|
||||
}
|
||||
return summon.getBoundingBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(StaticSummon summon) {
|
||||
this.checkBeforeTick(summon);
|
||||
Entity entity = summon.getOwner();
|
||||
if(!(entity instanceof Player player)) return;
|
||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
|
||||
boolean mainHand = !customData.contains("mainHand") || customData.getBoolean("mainHand");
|
||||
ItemStack stack = player.getItemInHand(mainHand ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND);
|
||||
if(!(stack.getItem() instanceof Flail flail)) {
|
||||
onDied(summon);
|
||||
return;
|
||||
}
|
||||
if(!stack.is(flail.getItemStack().getItem())) {
|
||||
onDied(summon);
|
||||
return;
|
||||
}
|
||||
|
||||
AABB hitBox = new AABB(
|
||||
summon.getX() - DROPPING_HITBOX_SIZE, summon.getY() - DROPPING_HITBOX_SIZE, summon.getZ() - DROPPING_HITBOX_SIZE,
|
||||
summon.getX() + DROPPING_HITBOX_SIZE, summon.getY() + DROPPING_HITBOX_SIZE, summon.getZ() + DROPPING_HITBOX_SIZE
|
||||
);
|
||||
int state = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
|
||||
.copyTag().getInt("state");
|
||||
if(state == Flail.State.THROWING.ordinal()) {
|
||||
int flyTime = customData.contains("flyTime") ? customData.getInt("flyTime") : 0;
|
||||
int age = summon.getEntityData().get(StaticSummon.AGE);
|
||||
if(age < flyTime) {
|
||||
summon.setDeltaMovement(summon.getLookAngle().normalize().scale(flail.getProjectileSpeed()));
|
||||
BlockHitResult blockHitResult = CollisionUtil.checkBlockHit(summon, summon.position().add(summon.getDeltaMovement()));
|
||||
if(blockHitResult.getType() != HitResult.Type.MISS) {
|
||||
summon.getEntityData().set(StaticSummon.AGE, flyTime);
|
||||
if(summon.level() instanceof ServerLevel serverLevel) {
|
||||
BlockState hitState = serverLevel.getBlockState(blockHitResult.getBlockPos());
|
||||
ParticleUtil.addParticles(
|
||||
serverLevel, new BlockParticleOption(ParticleTypes.BLOCK, hitState),
|
||||
blockHitResult.getLocation(), new Vec3(0, 0, 0),
|
||||
0.2, 25
|
||||
);
|
||||
SoundUtil.playServerSound(serverLevel, ModSounds.DIG.get(), blockHitResult.getLocation());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
Vec3 moveDir = player.getEyePosition().subtract(summon.position());
|
||||
double dist = moveDir.length();
|
||||
summon.setDeltaMovement(moveDir.normalize().scale(flail.getProjectileSpeed()));
|
||||
if(dist < 2.0f) {
|
||||
onDied(summon);
|
||||
return;
|
||||
}
|
||||
BlockHitResult blockHitResult = CollisionUtil.checkBlockHit(summon, summon.position().add(summon.getDeltaMovement()));
|
||||
if(blockHitResult.getType() != HitResult.Type.MISS) {
|
||||
int hitBlockCount = customData.contains("hitBlockCount") ? customData.getInt("hitBlockCount") : 0;
|
||||
if(hitBlockCount > 10) {
|
||||
summon.noPhysics = true;
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", Flail.State.THROWING_BACK.ordinal()));
|
||||
}else {
|
||||
customData.putInt("hitBlockCount", hitBlockCount + 1);
|
||||
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
|
||||
}
|
||||
if(summon.level() instanceof ServerLevel serverLevel) {
|
||||
BlockState hitState = serverLevel.getBlockState(blockHitResult.getBlockPos());
|
||||
ParticleUtil.addParticles(
|
||||
serverLevel, new BlockParticleOption(ParticleTypes.BLOCK, hitState),
|
||||
blockHitResult.getLocation(), new Vec3(0, 0, 0),
|
||||
0.2, 25
|
||||
);
|
||||
SoundUtil.playServerSound(serverLevel, ModSounds.DIG.get(), blockHitResult.getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
double dist = summon.position().subtract(player.position()).length();
|
||||
if(dist > flail.getMaxRange()) {
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", Flail.State.THROWING_BACK.ordinal()));
|
||||
}
|
||||
if(!summon.level().isClientSide()) {
|
||||
EntityHitResult entityHitResult = CollisionUtil.checkEntityHit(summon, summon.position().add(summon.getDeltaMovement()), THROWING_INFLATE);
|
||||
if(entityHitResult != null) {
|
||||
Entity target = entityHitResult.getEntity();
|
||||
if(DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), flail.getDamage(), 1.0f, 10)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(state == Flail.State.DROPPING.ordinal()) {
|
||||
Vec3 g = new Vec3(0, -1, 0);
|
||||
summon.setDeltaMovement(g.scale(flail.getGravity()));
|
||||
double dist = summon.position().subtract(player.position()).length();
|
||||
if(dist > flail.getMaxRange()) {
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", Flail.State.THROWING_BACK.ordinal()));
|
||||
}
|
||||
List<Entity> targets = summon.level().getEntitiesOfClass(
|
||||
Entity.class,
|
||||
hitBox,
|
||||
FilterUtil.createTargetFilter(summon, summon.getOwner())
|
||||
);
|
||||
for(Entity target : targets) {
|
||||
DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), flail.getDamage(), 1.0f, 10);
|
||||
}
|
||||
}else if(state == Flail.State.THROWING_BACK.ordinal()){
|
||||
Vec3 moveDir = player.getEyePosition().subtract(summon.position());
|
||||
double dist = moveDir.length();
|
||||
summon.setDeltaMovement(moveDir.normalize().scale(flail.getProjectileSpeed()));
|
||||
if(!summon.noPhysics) {
|
||||
BlockHitResult blockHitResult = CollisionUtil.checkBlockHit(summon, summon.position().add(summon.getDeltaMovement()));
|
||||
if(blockHitResult.getType() != HitResult.Type.MISS) {
|
||||
int hitBlockCount = customData.contains("hitBlockCount") ? customData.getInt("hitBlockCount") : 0;
|
||||
if(hitBlockCount > 10) {
|
||||
summon.noPhysics = true;
|
||||
}else {
|
||||
customData.putInt("hitBlockCount", hitBlockCount + 1);
|
||||
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
|
||||
}
|
||||
if(summon.level() instanceof ServerLevel serverLevel) {
|
||||
BlockState hitState = serverLevel.getBlockState(blockHitResult.getBlockPos());
|
||||
ParticleUtil.addParticles(
|
||||
serverLevel, new BlockParticleOption(ParticleTypes.BLOCK, hitState),
|
||||
blockHitResult.getLocation(), new Vec3(0, 0, 0),
|
||||
0.2, 25
|
||||
);
|
||||
SoundUtil.playServerSound(serverLevel, ModSounds.DIG.get(), blockHitResult.getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
EntityHitResult entityHitResult = CollisionUtil.checkEntityHit(summon, summon.position().add(summon.getDeltaMovement()), THROWING_INFLATE);
|
||||
if(entityHitResult != null) {
|
||||
Entity target = entityHitResult.getEntity();
|
||||
if(DamageUtil.meleeAttack(summon, target, summon.getEntityData().get(StaticSummon.STACK_SOURCE), flail.getDamage(), 1.0f, 10)) {
|
||||
}
|
||||
}
|
||||
if(dist < 2.0f) {
|
||||
onDied(summon);
|
||||
return;
|
||||
}
|
||||
}else {
|
||||
onDied(summon);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDied(StaticSummon summon) {
|
||||
if(summon.level().isClientSide()) return;
|
||||
Entity entity = summon.getOwner();
|
||||
if(!(entity instanceof Player player)) {
|
||||
summon.discard();
|
||||
return;
|
||||
}
|
||||
CompoundTag customData = summon.getEntityData().get(StaticSummon.CUSTOM_DATA);
|
||||
boolean mainHand = !customData.contains("mainHand") || customData.getBoolean("mainHand");
|
||||
ItemStack stack = player.getItemInHand(mainHand ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND);
|
||||
if(!(stack.getItem() instanceof Flail flail)) {
|
||||
summon.discard();
|
||||
return;
|
||||
}
|
||||
if(!stack.is(flail.getItemStack().getItem())) {
|
||||
summon.discard();
|
||||
return;
|
||||
}
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", Flail.State.IDLE.ordinal()));
|
||||
summon.discard();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
if(!(stack.getItem() instanceof Flail flail)) return InteractionResultHolder.fail(stack);;
|
||||
|
||||
int state = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
|
||||
.copyTag().getInt("state");
|
||||
if(state == Flail.State.IDLE.ordinal()) {
|
||||
StaticProjectile projectile = new StaticProjectile(ModEntities.STATIC_PROJECTILE.get(), level);
|
||||
projectile.setOwner(player);
|
||||
projectile.getEntityData().set(StaticProjectile.STACK_SOURCE, player.getItemInHand(hand).copy());
|
||||
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
|
||||
|
||||
Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ());
|
||||
projectile.setPos(pos);
|
||||
projectile.getEntityData().set(StaticProjectile.BEHAVIOR, StaticProjectileBehaviors.FLAIL_PROJECTILE);
|
||||
projectile.getEntityData().set(StaticProjectile.RENDER_MODE, "custom");
|
||||
projectile.getEntityData().set(StaticProjectile.ITEM, flail.getProjectileItemStack());
|
||||
projectile.getEntityData().set(StaticProjectile.ORIGIN, pos.toVector3f());
|
||||
projectile.getEntityData().set(StaticProjectile.DIRECTION, dirs[0]);
|
||||
projectile.getEntityData().set(StaticProjectile.UP, dirs[1]);
|
||||
projectile.getEntityData().set(StaticProjectile.RIGHT, dirs[2]);
|
||||
projectile.getEntityData().set(StaticProjectile.EXPRESSION_Z, String.format("%.3f*cos(%.3f*t)", 1.0, 1.0));
|
||||
projectile.getEntityData().set(StaticProjectile.EXPRESSION_Y, String.format("%.3f*sin(%.3f*t)", 1.0, 1.0));
|
||||
|
||||
projectile.getEntityData().set(StaticProjectile.LIFETIME, StaticSummon.INFINITE_LIFETIME);
|
||||
|
||||
CompoundTag customData = new CompoundTag();
|
||||
customData.putString("chainRes", flail.getChainRes());
|
||||
customData.putBoolean("mainHand", hand == InteractionHand.MAIN_HAND);
|
||||
projectile.getEntityData().set(StaticProjectile.CUSTOM_DATA, customData);
|
||||
|
||||
level.addFreshEntity(projectile);
|
||||
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", Flail.State.USING.ordinal()));
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putBoolean("mainHand", hand == InteractionHand.MAIN_HAND));
|
||||
player.startUsingItem(hand);
|
||||
return InteractionResultHolder.consume(stack);
|
||||
}else if(state == Flail.State.THROWING.ordinal()) {
|
||||
if(!canDrop()) return InteractionResultHolder.fail(stack);
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", Flail.State.DROPPING.ordinal()));
|
||||
player.startUsingItem(hand);
|
||||
return InteractionResultHolder.consume(stack);
|
||||
}else {
|
||||
return InteractionResultHolder.fail(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseUsing(ItemStack stack, Level level, LivingEntity entity, int timeLeft) {
|
||||
if(!(entity instanceof Player player)) return;
|
||||
if(!(stack.getItem() instanceof Flail flail)) return;
|
||||
|
||||
int state = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
|
||||
.copyTag().getInt("state");
|
||||
boolean mainHand = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
|
||||
.copyTag().getBoolean("mainHand");
|
||||
if(state == Flail.State.USING.ordinal()) {
|
||||
if(!level.isClientSide()) {
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", Flail.State.THROWING.ordinal()));
|
||||
|
||||
Vector3f[] dirs = MathUtil.computeCoordinateSystem(player);
|
||||
float[] xyRot = MathUtil.computeXYRot(dirs[0], dirs[1]);
|
||||
StaticSummon summon = new StaticSummon(ModEntities.STATIC_SUMMON.get(), level);
|
||||
summon.setOwner(player);
|
||||
summon.getEntityData().set(StaticSummon.STACK_SOURCE, stack.copy());
|
||||
Vec3 pos = new Vec3(player.getX(), player.getEyeY() - 0.1, player.getZ());
|
||||
summon.setPos(pos);
|
||||
summon.getEntityData().set(StaticSummon.BEHAVIOR, StaticSummonBehaviors.FLAIL_PROJECTILE);
|
||||
summon.getEntityData().set(StaticSummon.RENDER_MODE, "custom");
|
||||
summon.getEntityData().set(StaticSummon.ITEM, flail.getProjectileItemStack());
|
||||
summon.getEntityData().set(StaticSummon.LIFETIME, StaticSummon.INFINITE_LIFETIME);
|
||||
|
||||
summon.setXRot(xyRot[0]);
|
||||
summon.xRotO = xyRot[0];
|
||||
summon.setYRot(xyRot[1]);
|
||||
summon.yRotO = xyRot[1];
|
||||
|
||||
CompoundTag customData = new CompoundTag();
|
||||
customData.putInt("flyTime", flail.getFlyTime());
|
||||
customData.putString("chainRes", flail.getChainRes());
|
||||
customData.putBoolean("mainHand", mainHand);
|
||||
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
|
||||
|
||||
summon.setNoGravity(true);
|
||||
|
||||
level.addFreshEntity(summon);
|
||||
}
|
||||
}else if(state == Flail.State.DROPPING.ordinal()) {
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", Flail.State.THROWING_BACK.ordinal()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull UseAnim getUseAnimation(ItemStack stack) {
|
||||
return UseAnim.BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUseDuration(ItemStack stack, LivingEntity entity) {
|
||||
return 72000;
|
||||
}
|
||||
|
||||
@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(entity instanceof Player player) {
|
||||
if(!isSelected
|
||||
&& !player.getMainHandItem().is(stack.getItem())
|
||||
&& !player.getOffhandItem().is(stack.getItem())) {
|
||||
CustomData.update(DataComponents.CUSTOM_DATA, stack,
|
||||
tag -> tag.putInt("state", Flail.State.IDLE.ordinal()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user