Skip to content

Commit

Permalink
✨ artemis tracking and particle tweaking
Browse files Browse the repository at this point in the history
  • Loading branch information
LocusAzzurro committed Apr 2, 2024
1 parent 604a2f6 commit b90c7c9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public PlasmaTrailParticle(ClientLevel world, double x, double y, double z, doub
this.xd = xSpeed + (Math.random() * 2.0d - 1.0d) * 0.005d;
this.yd = ySpeed + (Math.random() * 2.0d - 1.0d) * 0.005d;
this.zd = zSpeed + (Math.random() * 2.0d - 1.0d) * 0.005d;
this.lifetime = (int)(10 / Math.random() * 1.5f);
this.lifetime = (int)Math.min(50f, (10 / Math.random() * 1.5f));
this.hasPhysics = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ArtemisMissileEntity extends AbstractHurtingProjectile {
private static final int DEFAULT_FUEL = 1200; // Default: 1200 (60s)
private int fuel;
private double homingSpeed = 1.1;
private double cruisingSpeed = 0.8;
private static final ParticleOptions PARTICLE = ParticleRegistry.PLASMA_TRAIL.get();

// 空白粒子
Expand Down Expand Up @@ -140,6 +141,10 @@ public void tick() {
.normalize().scale(homingSpeed);
this.setDeltaMovement(v3d);
}
else {
this.setDeltaMovement(this.getDeltaMovement().normalize().scale(cruisingSpeed));
}

if (this.fuel <= 0) {
this.onEmptyFuel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public InteractionResultHolder<ItemStack> use(Level worldIn, Player playerIn, In
return InteractionResultHolder.pass(item);
}

LivingEntity entity = ProjectileUtils.rayTraceTarget(playerIn, 0.1f, 300, 1);
LivingEntity entity = ProjectileUtils.rayTraceTarget(playerIn, ProjectileUtils.IS_HOSTILE, 0.5f, 500, 2);
ArtemisMissileEntity missile;
if (entity != null) {
missile = new ArtemisMissileEntity(worldIn, playerIn, entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public InteractionResultHolder<ItemStack> use(Level worldIn, Player playerIn, In
LivingEntity target = null;
boolean homing = (type == CardType.ARTEMIS_HOMING);
if (homing) {
target = ProjectileUtils.rayTraceTarget(playerIn, 0.1d, 300, 0.2);
target = ProjectileUtils.rayTraceTarget(playerIn, ProjectileUtils.IS_HOSTILE, 0.5f, 500, 2);
if (target == null) {
if (!worldIn.isClientSide()) {
playerIn.sendSystemMessage(Component.translatable("item.locusazzurro_icaruswings.transport_card_artemis.error1"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package org.mineplugin.locusazzurro.icaruswings.util;

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;

import javax.annotation.Nullable;
import java.util.List;
import java.util.function.Predicate;

public class ProjectileUtils {

public static final Predicate<LivingEntity> IS_HOSTILE = e -> e.getType().getCategory().equals(MobCategory.MONSTER);

@Nullable
public static LivingEntity rayTraceTarget(LivingEntity targeter, double step, int depth, double size){
public static LivingEntity rayTraceTarget(LivingEntity targeter, Predicate<LivingEntity> criteria, double step, int depth, double size){
Vec3 eyePos = targeter.getEyePosition(1f);
Vec3 lookVec = targeter.getViewVector(1f);
Vec3 checkPos = eyePos;
Expand All @@ -19,16 +23,16 @@ public static LivingEntity rayTraceTarget(LivingEntity targeter, double step, in
AABB aabb = new AABB(hS,hS,hS,-hS,-hS,-hS).move(checkPos);
List<LivingEntity> entities = targeter.level().getEntitiesOfClass(LivingEntity.class, aabb);
for (LivingEntity entity : entities){
if (entity != targeter && targeter.hasLineOfSight(entity)) return entity;
if (entity != targeter && criteria.test(entity) && targeter.hasLineOfSight(entity)) return entity;
}
checkPos = checkPos.add(lookVec.scale(step));
}
return null;
}

@Nullable
public static LivingEntity rayTraceTargetFixedDistance(LivingEntity targeter, double step, int distance, double size){
return rayTraceTarget(targeter, step, (int)Math.ceil(distance/step), size);
public static LivingEntity rayTraceTargetFixedDistance(LivingEntity targeter, Predicate<LivingEntity> criteria, double step, int distance, double size){
return rayTraceTarget(targeter, criteria, step, (int)Math.ceil(distance/step), size);
}

}

0 comments on commit b90c7c9

Please sign in to comment.