improvements in basePrimedTNT
This commit is contained in:
parent
1226338d10
commit
183d0fe38a
@ -10,12 +10,8 @@ import javax.annotation.Nullable;
|
||||
public class ClusterPrimedTNT extends basePrimedTNT {
|
||||
|
||||
public ClusterPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse, Vec3 move) {
|
||||
super(entities.TNT_CLUSTER.get(), pLevel, pOwner);
|
||||
this.setPos(pX, pY, pZ);
|
||||
this.setFuse(fuse);
|
||||
this.setPower(power);
|
||||
super(entities.TNT_CLUSTER.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power, "cluster");
|
||||
this.addDeltaMovement(move);
|
||||
this.setRenderID("cluster");
|
||||
}
|
||||
|
||||
public ClusterPrimedTNT(EntityType<ClusterPrimedTNT> entityType, Level level) {
|
||||
|
@ -3,15 +3,13 @@ package com.jenny.compressedtnt.entities;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class StrongerPrimedTNT extends basePrimedTNT {
|
||||
public StrongerPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse) {
|
||||
super(entities.TNT_STRONGER.get(), pLevel, pOwner);
|
||||
this.setPos(pX, pY, pZ);
|
||||
this.setFuse(fuse);
|
||||
this.setPower(power);
|
||||
super(entities.TNT_STRONGER.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power, "default");
|
||||
this.setRenderID(evalRenderID());
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.jenny.compressedtnt.entities;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
@ -7,6 +8,8 @@ import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.world.entity.*;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@ -22,12 +25,25 @@ public abstract class basePrimedTNT extends Entity implements TraceableEntity {
|
||||
|
||||
public basePrimedTNT(EntityType<? extends basePrimedTNT> pEntityType, Level pLevel, @Nullable LivingEntity owner) {
|
||||
super(pEntityType, pLevel);
|
||||
commonInit(pLevel, owner);
|
||||
}
|
||||
|
||||
private void commonInit(Level pLevel, @Nullable LivingEntity owner) {
|
||||
double d0 = pLevel.random.nextDouble() * (double)((float)Math.PI * 2F);
|
||||
this.setDeltaMovement(-Math.sin(d0) * 0.02D, (double)0.2F, -Math.cos(d0) * 0.02D);
|
||||
this.blocksBuilding = true;
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public basePrimedTNT(EntityType<? extends basePrimedTNT> pEntityType, Level pLevel, @Nullable LivingEntity owner, Vec3 pos, int fuse, float power, String renderID) {
|
||||
super(pEntityType, pLevel);
|
||||
commonInit(pLevel, owner);
|
||||
setPos(pos);
|
||||
setFuse(fuse);
|
||||
setPower(power);
|
||||
setRenderID(renderID);
|
||||
}
|
||||
|
||||
protected void explode() {
|
||||
this.level().explode(this, this.getX(), this.getY(0.0625D), this.getZ(), this.getPower(), Level.ExplosionInteraction.TNT);
|
||||
}
|
||||
@ -116,4 +132,8 @@ public abstract class basePrimedTNT extends Entity implements TraceableEntity {
|
||||
public String getRenderID() {
|
||||
return this.entityData.get(DATA_RENDER_ID);
|
||||
}
|
||||
|
||||
protected float getEyeHeight(@NotNull Pose pPose, @NotNull EntityDimensions pSize) {
|
||||
return 0.15F;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import net.minecraft.world.entity.*;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
@ -17,18 +16,14 @@ public class blackHolePrimedTNT extends basePrimedTNT {
|
||||
private static final EntityDataAccessor<Float> DATA_SPEED_ID = SynchedEntityData.defineId(blackHolePrimedTNT.class, EntityDataSerializers.FLOAT);
|
||||
|
||||
public blackHolePrimedTNT(Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse, float speed) {
|
||||
super(entities.TNT_BLACK_HOLE.get(), pLevel, pOwner);
|
||||
this.setRenderID("black_hole");
|
||||
this.setPos(pX, pY, pZ);
|
||||
this.setOwner(pOwner);
|
||||
super(entities.TNT_BLACK_HOLE.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power, "black_hole");
|
||||
this.setSpeed(speed);
|
||||
this.setPower(power);
|
||||
this.setFuse(fuse);
|
||||
}
|
||||
|
||||
public blackHolePrimedTNT(EntityType<blackHolePrimedTNT> entityType, Level level) {
|
||||
super(entityType, level, null);
|
||||
this.setRenderID("black_hole");
|
||||
this.setSpeed(this.getSpeed());
|
||||
}
|
||||
|
||||
private Vec3 targetVector(Entity target) {
|
||||
@ -90,8 +85,4 @@ public class blackHolePrimedTNT extends basePrimedTNT {
|
||||
this.entityData.define(DATA_SPEED_ID, 4.0f);
|
||||
super.defineSynchedData();
|
||||
}
|
||||
|
||||
protected float getEyeHeight(@NotNull Pose pPose, @NotNull EntityDimensions pSize) {
|
||||
return 0.15F;
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,25 @@
|
||||
package com.jenny.compressedtnt.entities;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.world.entity.*;
|
||||
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class homingPrimedTNT extends basePrimedTNT {
|
||||
float speed = 0;
|
||||
private static final EntityDataAccessor<Float> DATA_SPEED_ID = SynchedEntityData.defineId(homingPrimedTNT.class, EntityDataSerializers.FLOAT);
|
||||
Entity target;
|
||||
|
||||
public homingPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse, float speed) {
|
||||
super(entities.TNT_HOMING.get(), pLevel, pOwner);
|
||||
this.setPos(pX, pY, pZ);
|
||||
this.setOwner(pOwner);
|
||||
this.speed = speed;
|
||||
super(entities.TNT_HOMING.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power, "homing");
|
||||
this.target = null;
|
||||
this.setPower(power);
|
||||
this.setFuse(fuse);
|
||||
this.setRenderID("homing");
|
||||
this.setSpeed(speed);
|
||||
}
|
||||
|
||||
public homingPrimedTNT(EntityType<homingPrimedTNT> entityType, Level level) {
|
||||
@ -32,6 +30,7 @@ public class homingPrimedTNT extends basePrimedTNT {
|
||||
double targetDist = getTargetDist();
|
||||
Vec3 targetVec = new Vec3(0, 0, 0);
|
||||
if (targetDist > 3) {
|
||||
float speed = getSpeed();
|
||||
targetVec = new Vec3(target.getX() - this.getX(), target.getY() - this.getY(), target.getZ() - this.getZ()).normalize().multiply(speed, speed, speed);
|
||||
if (targetDist < 10) {
|
||||
targetVec.multiply(targetDist / 10, targetDist / 10, targetDist / 10);
|
||||
@ -49,7 +48,6 @@ public class homingPrimedTNT extends basePrimedTNT {
|
||||
Vec3 corner2 = this.position().add(15, 15, 15);
|
||||
AABB boundingBox = new AABB(corner1, corner2);
|
||||
target = this.level().getNearestEntity(LivingEntity.class, TargetingConditions.forNonCombat(), null, this.getX(), this.getY(), this.getZ(), boundingBox);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,7 +62,29 @@ public class homingPrimedTNT extends basePrimedTNT {
|
||||
super.tick();
|
||||
}
|
||||
|
||||
protected float getEyeHeight(@NotNull Pose pPose, @NotNull EntityDimensions pSize) {
|
||||
return 0.15F;
|
||||
@Override
|
||||
protected void addAdditionalSaveData(CompoundTag pCompound) {
|
||||
pCompound.putFloat("Speed", this.getSpeed());
|
||||
super.addAdditionalSaveData(pCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readAdditionalSaveData(CompoundTag pCompound) {
|
||||
this.setSpeed(pCompound.getFloat("Speed"));
|
||||
super.readAdditionalSaveData(pCompound);
|
||||
}
|
||||
|
||||
public void setSpeed(float speed) {
|
||||
this.entityData.set(DATA_SPEED_ID, speed);
|
||||
}
|
||||
|
||||
public float getSpeed() {
|
||||
return this.entityData.get(DATA_SPEED_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void defineSynchedData() {
|
||||
this.entityData.define(DATA_SPEED_ID, 4.0f);
|
||||
super.defineSynchedData();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user