Cleanup & reformat

This commit is contained in:
John Yorke committed 2021-11-25 23:38:31 -04:00
1 parent f479b19255
commit 38e0cefaa2
76 files changed
+2371 -2766

No files matched your search

@@ -1,6 +1,7 @@
package taintedmagic.common.entities;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
@@ -21,191 +22,168 @@ import thaumcraft.common.Thaumcraft;
import thaumcraft.common.lib.utils.EntityUtils;
/**
* this class is based off of EntityHomingShard.class created by <Azanor> as
* part of Thaumcraft 5
* This class is based off of EntityHomingShard.class created by <Azanor> as part of Thaumcraft 5
*/
public class EntityHomingShard extends EntityThrowable implements IEntityAdditionalSpawnData
{
Class targetClass = null;
boolean persistant = false;
public class EntityHomingShard extends EntityThrowable implements IEntityAdditionalSpawnData {
int targetID = 0;
EntityLivingBase target;
private Class targetClass;
private boolean persistent;
private EntityLivingBase target;
Material[] mats = { Material.plants, Material.air, Material.leaves, Material.portal, Material.vine, Material.web };
private static final Material[] MATS =
{ Material.plants, Material.air, Material.leaves, Material.portal, Material.vine, Material.web };
public EntityHomingShard (World world)
{
public EntityHomingShard (final World world) {
super(world);
}
public EntityHomingShard (World world, EntityLivingBase thrower, EntityLivingBase target, int strength, boolean b)
{
public EntityHomingShard (final World world, final EntityLivingBase thrower, final EntityLivingBase target,
final int strength, final boolean persistent) {
super(world, thrower);
this.target = target;
this.targetClass = target.getClass();
this.persistant = b;
this.persistent = persistent;
setStrength(strength);
Vec3 vec = thrower.getLookVec();
final Vec3 vec = thrower.getLookVec();
setLocationAndAngles(thrower.posX + vec.xCoord / 2.0D, thrower.posY + thrower.getEyeHeight() + vec.yCoord / 2.0D,
thrower.posZ + vec.zCoord / 2.0D, thrower.rotationYaw, thrower.rotationPitch);
float f = 0.5F;
float ry = thrower.rotationYaw + (this.rand.nextFloat() - this.rand.nextFloat()) * 60.0F;
float rp = thrower.rotationPitch + (this.rand.nextFloat() - this.rand.nextFloat()) * 60.0F;
this.motionX = (-MathHelper.sin(ry / 180.0F * (float) Math.PI) * MathHelper.cos(rp / 180.0F * (float) Math.PI) * f);
this.motionZ = (MathHelper.cos(ry / 180.0F * (float) Math.PI) * MathHelper.cos(rp / 180.0F * (float) Math.PI) * f);
this.motionY = (-MathHelper.sin(rp / 180.0F * (float) Math.PI) * f);
final float f = 0.5F;
final float ry = thrower.rotationYaw + (rand.nextFloat() - rand.nextFloat()) * 60.0F;
final float rp = thrower.rotationPitch + (rand.nextFloat() - rand.nextFloat()) * 60.0F;
motionX = -MathHelper.sin(ry / 180.0F * (float) Math.PI) * MathHelper.cos(rp / 180.0F * (float) Math.PI) * f;
motionZ = MathHelper.cos(ry / 180.0F * (float) Math.PI) * MathHelper.cos(rp / 180.0F * (float) Math.PI) * f;
motionY = -MathHelper.sin(rp / 180.0F * (float) Math.PI) * f;
}
@Override
public boolean shouldRenderInPass (int pass)
{
public boolean shouldRenderInPass (final int pass) {
return pass == 1;
}
@Override
public void entityInit ()
{
public void entityInit () {
super.entityInit();
this.dataWatcher.addObject(17, (byte) 0);
dataWatcher.addObject(17, (byte) 0);
}
public void setStrength (int strength)
{
this.dataWatcher.updateObject(17, Byte.valueOf((byte) strength));
public void setStrength (final int strength) {
dataWatcher.updateObject(17, Byte.valueOf((byte) strength));
}
public int getStrength ()
{
return this.dataWatcher.getWatchableObjectByte(17);
public int getStrength () {
return dataWatcher.getWatchableObjectByte(17);
}
@Override
protected float getGravityVelocity ()
{
protected float getGravityVelocity () {
return 0.0F;
}
@Override
public void writeSpawnData (ByteBuf buf)
{
public void writeSpawnData (final ByteBuf buf) {
int id = -1;
if (this.target != null) id = this.target.getEntityId();
if (target != null) {
id = target.getEntityId();
}
buf.writeInt(id);
}
@Override
public void readSpawnData (ByteBuf buf)
{
int id = buf.readInt();
try
{
if (id >= 0) this.target = ((EntityLivingBase) this.worldObj.getEntityByID(id));
}
catch (Exception e)
{
public void readSpawnData (final ByteBuf buf) {
final int id = buf.readInt();
if (id >= 0) {
target = (EntityLivingBase) worldObj.getEntityByID(id);
}
}
@Override
protected void onImpact (MovingObjectPosition mop)
{
if (!this.worldObj.isRemote && mop.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY
&& (getThrower() == null || (getThrower() != null && mop.entityHit != getThrower())))
{
protected void onImpact (final MovingObjectPosition mop) {
if (!worldObj.isRemote && mop.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY
&& (getThrower() == null || getThrower() != null && mop.entityHit != getThrower())) {
mop.entityHit.attackEntityFrom(DamageSource.causeIndirectMagicDamage(this, getThrower()),
2.0F + getStrength() * 0.5F);
this.worldObj.playSoundAtEntity(this, "thaumcraft:zap", 1.0F,
1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F);
this.worldObj.setEntityState(this, (byte) 16);
worldObj.playSoundAtEntity(this, "thaumcraft:zap", 1.0F, 1.0F + (rand.nextFloat() - rand.nextFloat()) * 0.2F);
worldObj.setEntityState(this, (byte) 16);
setDead();
}
if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
{
Block block = this.worldObj.getBlock(mop.blockX, mop.blockY, mop.blockZ);
if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
final Block block = worldObj.getBlock(mop.blockX, mop.blockY, mop.blockZ);
List<Material> whitelisted = new ArrayList<Material>(mats.length);
for (int i = 0; i < mats.length; i++)
whitelisted.add(mats[i]);
final List<Material> whitelisted = new ArrayList<>(MATS.length);
Collections.addAll(whitelisted, MATS);
if (!whitelisted.contains(block.getMaterial()))
{
this.motionZ *= -0.8D;
this.motionX *= -0.8D;
this.motionY *= -0.8D;
if (!whitelisted.contains(block.getMaterial())) {
motionZ *= -0.8D;
motionX *= -0.8D;
motionY *= -0.8D;
}
}
}
@Override
@SideOnly (Side.CLIENT)
public void handleHealthUpdate (byte b)
{
if (b == 16) Thaumcraft.proxy.burst(worldObj, this.posX, this.posY, this.posZ, 0.3F);
else super.handleHealthUpdate(b);
public void handleHealthUpdate (final byte b) {
if (b == 16) {
Thaumcraft.proxy.burst(worldObj, posX, posY, posZ, 0.3F);
}
else {
super.handleHealthUpdate(b);
}
}
@Override
public void onUpdate ()
{
double motion = Math.abs(this.motionX) + Math.abs(this.motionY) + Math.abs(this.motionZ);
if (motion > 0.0D && this.worldObj.isRemote) Thaumcraft.proxy.sparkle(
(float) this.posX + (this.worldObj.rand.nextFloat() - this.worldObj.rand.nextFloat()) * 0.25F,
(float) this.posY + (this.worldObj.rand.nextFloat() - this.worldObj.rand.nextFloat()) * 0.25F,
(float) this.posZ + (this.worldObj.rand.nextFloat() - this.worldObj.rand.nextFloat()) * 0.25F, 0.5F, 0, 0.0F);
public void onUpdate () {
final double motion = Math.abs(motionX) + Math.abs(motionY) + Math.abs(motionZ);
if (motion > 0.0D && worldObj.isRemote) {
Thaumcraft.proxy.sparkle((float) posX + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) * 0.25F,
(float) posY + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) * 0.25F,
(float) posZ + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) * 0.25F, 0.5F, 0, 0.0F);
}
super.onUpdate();
if (!this.worldObj.isRemote)
{
if (this.persistant
&& (this.target == null || this.target.isDead || this.target.getDistanceSqToEntity(this) > 1250.0D))
{
ArrayList<Entity> ents = EntityUtils.getEntitiesInRange(this.worldObj, this.posX, this.posY, this.posZ, this,
this.targetClass, 16.0D);
if (!worldObj.isRemote) {
if (persistent && (target == null || target.isDead || target.getDistanceSqToEntity(this) > 1250.0D)) {
final ArrayList<Entity> ents =
EntityUtils.getEntitiesInRange(worldObj, posX, posY, posZ, this, targetClass, 16.0D);
for (Entity entity : ents)
{
for (final Entity entity : ents) {
if (entity instanceof EntityLivingBase && !entity.isDead
&& (getThrower() == null || entity.getEntityId() != getThrower().getEntityId()))
{
this.target = ((EntityLivingBase) entity);
&& (getThrower() == null || entity.getEntityId() != getThrower().getEntityId())) {
target = (EntityLivingBase) entity;
break;
}
}
}
if (this.target == null || this.target.isDead)
{
this.worldObj.setEntityState(this, (byte) 16);
if (target == null || target.isDead) {
worldObj.setEntityState(this, (byte) 16);
setDead();
}
}
if (this.ticksExisted > 300)
{
this.worldObj.setEntityState(this, (byte) 16);
if (ticksExisted > 300) {
worldObj.setEntityState(this, (byte) 16);
setDead();
}
if (this.ticksExisted % 10 == 0 && this.target != null && !this.target.isDead)
{
double d = getDistanceToEntity(this.target);
double dx = this.target.posX - this.posX;
double dy = this.target.boundingBox.minY + this.target.height * 0.6D - this.posY;
double dz = this.target.posZ - this.posZ;
if (ticksExisted % 10 == 0 && target != null && !target.isDead) {
final double d = getDistanceToEntity(target);
double dx = target.posX - posX;
double dy = target.boundingBox.minY + target.height * 0.6D - posY;
double dz = target.posZ - posZ;
dx /= d;
dy /= d;
dz /= d;
this.motionX = dx;
this.motionY = dy;
this.motionZ = dz;
motionX = dx;
motionY = dy;
motionZ = dz;
this.worldObj.playSoundAtEntity(this, "taintedmagic:shard", 0.1F, 2.0F * this.worldObj.rand.nextFloat());
worldObj.playSoundAtEntity(this, "taintedmagic:shard", 0.1F, 2.0F * worldObj.rand.nextFloat());
}
this.motionX *= 0.85D;
this.motionY *= 0.85D;
this.motionZ *= 0.85D;
motionX *= 0.85D;
motionY *= 0.85D;
motionZ *= 0.85D;
}
}