This commit is contained in:
parent
befb1eae2f
commit
a6dc65027d
@ -15,10 +15,12 @@ import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.RayTraceContext;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.explosion.Explosion;
|
||||
|
||||
import java.util.Comparator;
|
||||
@ -32,8 +34,12 @@ public class DefensiveLaserBlockEntity extends EnergyReceiverBlockEntity {
|
||||
|
||||
public final Rotation rotation = new Rotation(0, 0, "Rotation");
|
||||
|
||||
private static Vec3d getPosVec(BlockPos pos) {
|
||||
return new Vec3d(pos.getX() + 0.5d, pos.getY() + 0.5d, pos.getZ() + 0.5d);
|
||||
}
|
||||
|
||||
private Vec3d getPosVec() {
|
||||
return new Vec3d(getPos().getX() + 0.5d, getPos().getY() + 0.5d, getPos().getZ() + 0.5d);
|
||||
return getPosVec(getPos());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -176,23 +182,12 @@ public class DefensiveLaserBlockEntity extends EnergyReceiverBlockEntity {
|
||||
return new ItemEntity(getWorld(), posVec.getX(), posVec.getY(), posVec.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tickEnergy() {
|
||||
assert getWorld() != null;
|
||||
addAction(Action.createBlockStatePropertyAction(Config.DEFENSIVE_LASER_IDLE_ENERGY_REQUIRED, DefensiveLaserBlock.POWERED, true, false));
|
||||
if (getCachedState().get(DefensiveLaserBlock.POWERED)) {
|
||||
if (countdown > 0) {
|
||||
countdown--;
|
||||
}
|
||||
if (countdown == 1) {
|
||||
addAction(new Action(Config.DEFENSIVE_LASER_FIRE_ENERGY_REQUIRED, (world, pos, state) -> {
|
||||
firing = false;
|
||||
|
||||
private void fire(World world, BlockPos pos) {
|
||||
List<LivingEntity> entities = getEntities(entity -> true);
|
||||
Vec3d posVec = getPosVec();
|
||||
Vec3d posVec = getPosVec(pos);
|
||||
Vec3d collision = null;
|
||||
for (LivingEntity entity : entities) {
|
||||
Optional<Vec3d> optional = entity.getBoundingBox().rayTrace(getPosVec(), getPosVec().add(rotation.getRayVector().multiply(Config.DEFENSIVE_LASER_RANGE)));
|
||||
Optional<Vec3d> optional = entity.getBoundingBox().rayTrace(posVec, posVec.add(rotation.getRayVector().multiply(Config.DEFENSIVE_LASER_RANGE)));
|
||||
if (optional.isPresent()) {
|
||||
Vec3d vec = optional.get();
|
||||
if (collision == null || vec.distanceTo(posVec) < collision.distanceTo(posVec)) {
|
||||
@ -211,7 +206,7 @@ public class DefensiveLaserBlockEntity extends EnergyReceiverBlockEntity {
|
||||
|
||||
double distance;
|
||||
if (collision != null) {
|
||||
world.createExplosion(null, collision.getX(), collision.getY(), collision.getZ(), 4, Explosion.DestructionType.NONE);
|
||||
world.createExplosion(null, collision.getX(), collision.getY(), collision.getZ(), 3, Explosion.DestructionType.NONE);
|
||||
|
||||
distance = posVec.distanceTo(collision);
|
||||
} else {
|
||||
@ -222,8 +217,22 @@ public class DefensiveLaserBlockEntity extends EnergyReceiverBlockEntity {
|
||||
distance = distance * multiplier;
|
||||
for (int i = 0; i < distance; i++) {
|
||||
Vec3d vec = rotationVec.multiply(i / multiplier).add(posVec);
|
||||
((ServerWorld) getWorld()).spawnParticles(ParticleTypes.END_ROD, vec.getX(), vec.getY(), vec.getZ(), 1, 0, 0, 0, 1);
|
||||
((ServerWorld) world).spawnParticles(ParticleTypes.END_ROD, vec.getX(), vec.getY(), vec.getZ(), 1, 0, 0, 0, 0.25f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tickEnergy() {
|
||||
assert getWorld() != null;
|
||||
addAction(Action.createBlockStatePropertyAction(Config.DEFENSIVE_LASER_IDLE_ENERGY_REQUIRED, DefensiveLaserBlock.POWERED, true, false));
|
||||
if (getCachedState().get(DefensiveLaserBlock.POWERED)) {
|
||||
if (countdown > 0) {
|
||||
countdown--;
|
||||
}
|
||||
if (countdown == 1) {
|
||||
addAction(new Action(Config.DEFENSIVE_LASER_FIRE_ENERGY_REQUIRED, (world, pos, state) -> {
|
||||
firing = false;
|
||||
fire(world, pos);
|
||||
}, (world, pos, state) -> firing = false));
|
||||
target = null;
|
||||
firing = true;
|
||||
|
Reference in New Issue
Block a user