From 2132c4457d402bb61b41ea8b23e21647c6ffd00b Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Sun, 9 Nov 2014 21:14:11 -0800 Subject: [PATCH] Apply formatting to Butterfly classes --- .../entities/AIButterflyFlee.java | 16 +-- .../entities/AIButterflyRest.java | 29 ++--- .../entities/AIButterflyWander.java | 19 +-- .../entities/EntityButterfly.java | 121 +++++++++++------- 4 files changed, 107 insertions(+), 78 deletions(-) diff --git a/src/main/java/forestry/lepidopterology/entities/AIButterflyFlee.java b/src/main/java/forestry/lepidopterology/entities/AIButterflyFlee.java index 6fa49cce5..fd7387adf 100755 --- a/src/main/java/forestry/lepidopterology/entities/AIButterflyFlee.java +++ b/src/main/java/forestry/lepidopterology/entities/AIButterflyFlee.java @@ -15,7 +15,6 @@ import net.minecraft.util.ChunkCoordinates; import forestry.lepidopterology.entities.EntityButterfly.EnumButterflyState; - public class AIButterflyFlee extends AIButterflyBase { private EntityPlayer player; @@ -38,7 +37,7 @@ public class AIButterflyFlee extends AIButterflyBase { return false; flightTarget = getRandomDestination(); - if(flightTarget == null) + if (flightTarget == null) return false; if (player.getDistanceSq(flightTarget.posX, flightTarget.posY, flightTarget.posZ) < player.getDistanceSqToEntity(entity)) @@ -51,16 +50,16 @@ public class AIButterflyFlee extends AIButterflyBase { @Override public boolean continueExecuting() { - if(entity.getState() != EnumButterflyState.FLYING) + if (entity.getState() != EnumButterflyState.FLYING) return false; - if(flightTarget == null) + if (flightTarget == null) return false; // Abort if the flight target changed on us. - if(entity.getDestination() == null || !entity.getDestination().equals(flightTarget)) + if (entity.getDestination() == null || !entity.getDestination().equals(flightTarget)) return false; // Continue if we have not yet reached the destination. - if(entity.getDestination().getDistanceSquared((int)entity.posX, (int)entity.posY, (int)entity.posZ) > 2.0f) + if (entity.getDestination().getDistanceSquared((int) entity.posX, (int) entity.posY, (int) entity.posZ) > 2.0f) return true; entity.setDestination(null); @@ -79,10 +78,11 @@ public class AIButterflyFlee extends AIButterflyBase { @Override public void updateTask() { // Reset destination if we did collide. - if(entity.isInWater()) { + if (entity.isInWater()) { flightTarget = getRandomDestinationUpwards(); entity.setDestination(flightTarget); - } if(entity.isCollided || entity.worldObj.rand.nextInt(300) == 0) { + } + if (entity.isCollided || entity.worldObj.rand.nextInt(300) == 0) { flightTarget = getRandomDestination(); entity.setDestination(flightTarget); } diff --git a/src/main/java/forestry/lepidopterology/entities/AIButterflyRest.java b/src/main/java/forestry/lepidopterology/entities/AIButterflyRest.java index 8c2071dfe..4f0162d1f 100755 --- a/src/main/java/forestry/lepidopterology/entities/AIButterflyRest.java +++ b/src/main/java/forestry/lepidopterology/entities/AIButterflyRest.java @@ -21,23 +21,23 @@ public class AIButterflyRest extends AIButterflyBase { super(entity); setMutexBits(3); } - + @Override public boolean shouldExecute() { - - if(entity.getExhaustion() < EntityButterfly.EXHAUSTION_REST + + if (entity.getExhaustion() < EntityButterfly.EXHAUSTION_REST && entity.canFly()) return false; - - if(!entity.worldObj.isAirBlock((int)entity.posX, ((int)Math.floor(entity.posY)), (int)entity.posZ)) + + if (!entity.worldObj.isAirBlock((int) entity.posX, ((int) Math.floor(entity.posY)), (int) entity.posZ)) return false; - - ChunkCoordinates rest = new ChunkCoordinates((int)entity.posX, ((int)Math.floor(entity.posY)) - 1, (int)entity.posZ); - if(entity.worldObj.isAirBlock(rest.posX, rest.posY, rest.posZ)) + + ChunkCoordinates rest = new ChunkCoordinates((int) entity.posX, ((int) Math.floor(entity.posY)) - 1, (int) entity.posZ); + if (entity.worldObj.isAirBlock(rest.posX, rest.posY, rest.posZ)) return false; - if(Utils.isLiquidBlock(entity.worldObj, rest.posX, rest.posY, rest.posZ)) + if (Utils.isLiquidBlock(entity.worldObj, rest.posX, rest.posY, rest.posZ)) return false; - if(!entity.getButterfly().isAcceptedEnvironment(entity.worldObj, rest.posX, rest.posY, rest.posZ)) + if (!entity.getButterfly().isAcceptedEnvironment(entity.worldObj, rest.posX, rest.posY, rest.posZ)) return false; entity.setDestination(null); @@ -47,14 +47,11 @@ public class AIButterflyRest extends AIButterflyBase { @Override public boolean continueExecuting() { - if(entity.getExhaustion() <= 0 && entity.canFly()) + if (entity.getExhaustion() <= 0 && entity.canFly()) return false; - if(entity.isInWater()) - return false; - - return true; + return !entity.isInWater(); } - + @Override public void startExecuting() { } diff --git a/src/main/java/forestry/lepidopterology/entities/AIButterflyWander.java b/src/main/java/forestry/lepidopterology/entities/AIButterflyWander.java index 155ecfb04..937ba2fca 100755 --- a/src/main/java/forestry/lepidopterology/entities/AIButterflyWander.java +++ b/src/main/java/forestry/lepidopterology/entities/AIButterflyWander.java @@ -26,12 +26,12 @@ public class AIButterflyWander extends AIButterflyBase { @Override public boolean shouldExecute() { - if(entity.getDestination() != null) + if (entity.getDestination() != null) return false; flightTarget = getRandomDestination(); - if(flightTarget == null) { - if(entity.getState().doesMovement) + if (flightTarget == null) { + if (entity.getState().doesMovement) entity.setState(EnumButterflyState.HOVER); return false; } @@ -43,16 +43,16 @@ public class AIButterflyWander extends AIButterflyBase { @Override public boolean continueExecuting() { - if(entity.getState() != EnumButterflyState.FLYING) + if (entity.getState() != EnumButterflyState.FLYING) return false; - if(flightTarget == null) + if (flightTarget == null) return false; // Abort if the flight target changed on us. - if(entity.getDestination() == null || !entity.getDestination().equals(flightTarget)) + if (entity.getDestination() == null || !entity.getDestination().equals(flightTarget)) return false; // Continue if we have not yet reached the destination. - if(entity.getDestination().getDistanceSquared((int)entity.posX, (int)entity.posY, (int)entity.posZ) > 2.0f) + if (entity.getDestination().getDistanceSquared((int) entity.posX, (int) entity.posY, (int) entity.posZ) > 2.0f) return true; entity.setDestination(null); @@ -71,10 +71,11 @@ public class AIButterflyWander extends AIButterflyBase { @Override public void updateTask() { // Reset destination if we did collide. - if(entity.isInWater()) { + if (entity.isInWater()) { flightTarget = getRandomDestinationUpwards(); entity.setDestination(flightTarget); - } if(entity.isCollided || entity.worldObj.rand.nextInt(300) == 0) { + } + if (entity.isCollided || entity.worldObj.rand.nextInt(300) == 0) { flightTarget = getRandomDestination(); entity.setDestination(flightTarget); } diff --git a/src/main/java/forestry/lepidopterology/entities/EntityButterfly.java b/src/main/java/forestry/lepidopterology/entities/EntityButterfly.java index 55138fb2e..a33032bf7 100755 --- a/src/main/java/forestry/lepidopterology/entities/EntityButterfly.java +++ b/src/main/java/forestry/lepidopterology/entities/EntityButterfly.java @@ -43,6 +43,7 @@ import forestry.plugins.PluginLepidopterology; public class EntityButterfly extends EntityCreature implements IEntityButterfly { public enum EnumButterflyState { + FLYING(true), GLIDING(true), RESTING(false), HOVER(false); public static final EnumButterflyState[] VALUES = values(); @@ -54,7 +55,7 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly } public float getWingFlap(EntityButterfly entity, float partialTicktime) { - if(this == RESTING || this == HOVER) { + if (this == RESTING || this == HOVER) { long systemTime = System.currentTimeMillis(); long flapping = systemTime + entity.contained.getIdent().hashCode(); float flap = (float) (flapping % 1000) / 1000; // 0 to 1 @@ -88,7 +89,7 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly private IIndividual pollen; private EnumButterflyState state = DEFAULT_STATE; - private float scale = DEFAULT_BUTTERFLY_SCALE; + private float scale = DEFAULT_BUTTERFLY_SCALE; private String mothTexture; private long lastUpdate; @@ -129,13 +130,13 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly contained.writeToNBT(bio); nbttagcompound.setTag("BTFLY", bio); - if(pollen != null) { + if (pollen != null) { NBTTagCompound pln = new NBTTagCompound(); pollen.writeToNBT(pln); nbttagcompound.setTag("PLN", pln); } - nbttagcompound.setByte("STATE", (byte)state.ordinal()); + nbttagcompound.setByte("STATE", (byte) state.ordinal()); nbttagcompound.setInteger("EXH", exhaustion); } @@ -143,14 +144,12 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly public void readEntityFromNBT(NBTTagCompound nbttagcompound) { super.readEntityFromNBT(nbttagcompound); - if(nbttagcompound.hasKey("BTFLY")) { - contained = new Butterfly((NBTTagCompound)nbttagcompound.getTag("BTFLY")); - } + if (nbttagcompound.hasKey("BTFLY")) + contained = new Butterfly((NBTTagCompound) nbttagcompound.getTag("BTFLY")); setIndividual(contained); - if(nbttagcompound.hasKey("PLN")) { - pollen = AlleleManager.alleleRegistry.getSpeciesRoot("rootTrees").getMember((NBTTagCompound)nbttagcompound.getTag("PLN")); - } + if (nbttagcompound.hasKey("PLN")) + pollen = AlleleManager.alleleRegistry.getSpeciesRoot("rootTrees").getMember((NBTTagCompound) nbttagcompound.getTag("PLN")); state = EnumButterflyState.VALUES[nbttagcompound.getByte("STATE")]; exhaustion = nbttagcompound.getInteger("EXH"); @@ -199,9 +198,9 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly } public void setState(EnumButterflyState state) { - if(state != this.state) { + if (state != this.state) { this.state = state; - dataWatcher.updateObject(DATAWATCHER_ID_STATE, (byte)state.ordinal()); + dataWatcher.updateObject(DATAWATCHER_ID_STATE, (byte) state.ordinal()); } } @@ -232,7 +231,7 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly } public EntityButterfly setIndividual(IButterfly butterfly) { - if(butterfly != null) + if (butterfly != null) contained = butterfly; else contained = PluginLepidopterology.butterflyInterface.templateAsIndividual(PluginLepidopterology.butterflyInterface.getDefaultTemplate()); @@ -240,7 +239,7 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly isImmuneToFire = contained.getGenome().getFireResist(); setSpecies(contained.getGenome().getPrimary()); dataWatcher.updateObject(DATAWATCHER_ID_SPECIES, species.getUID()); - dataWatcher.updateObject(DATAWATCHER_ID_SCALE, (int)(contained.getSize() * 100)); + dataWatcher.updateObject(DATAWATCHER_ID_SCALE, (int) (contained.getSize() * 100)); return this; } @@ -258,22 +257,26 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly @Override public IEntityLivingData onSpawnWithEgg(IEntityLivingData data) { - if(Proxies.common.isSimulating(worldObj)) + if (Proxies.common.isSimulating(worldObj)) setIndividual(contained); return data; } - @Override public boolean getCanSpawnHere() { return true; } + + @Override + public boolean getCanSpawnHere() { + return true; + } @Override protected void entityInit() { super.entityInit(); - if(state == null) + if (state == null) state = DEFAULT_STATE; dataWatcher.addObject(DATAWATCHER_ID_SPECIES, ""); dataWatcher.addObject(DATAWATCHER_ID_SCALE, 75); - dataWatcher.addObject(DATAWATCHER_ID_STATE, (byte)state.ordinal()); + dataWatcher.addObject(DATAWATCHER_ID_STATE, (byte) state.ordinal()); } @Override @@ -284,30 +287,45 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly @SideOnly(Side.CLIENT) private ResourceLocation textureResource; private long lastTextureUpdate; + @SideOnly(Side.CLIENT) public ResourceLocation getTexture() { - if(textureResource == null || lastTextureUpdate != lastUpdate) + if (textureResource == null || lastTextureUpdate != lastUpdate) textureResource = new ResourceLocation(mothTexture); return textureResource; } - @Override public boolean canBePushed() { return false; } - @Override protected void collideWithEntity(Entity other) {} - @Override protected boolean isAIEnabled() { return true; } - @Override protected boolean canDespawn() { return false; } + @Override + public boolean canBePushed() { + return false; + } + + @Override + protected void collideWithEntity(Entity other) { + } + + @Override + protected boolean isAIEnabled() { + return true; + } + + @Override + protected boolean canDespawn() { + return false; + } /* INTERACTION */ @Override public boolean interact(EntityPlayer player) { - if(isDead) + if (isDead) return false; - if(player.getHeldItem() == null) + if (player.getHeldItem() == null) return false; - if(!(player.getHeldItem().getItem() instanceof IToolScoop)) + if (!(player.getHeldItem().getItem() instanceof IToolScoop)) return false; - if(Proxies.common.isSimulating(worldObj)) { + if (Proxies.common.isSimulating(worldObj)) { contained.getGenome().getPrimary().getRoot().getBreedingTracker(worldObj, player.getGameProfile()).registerCatch(contained); StackUtils.dropItemStackAsEntity(PluginLepidopterology.butterflyInterface.getMemberStack(contained.copy(), EnumFlutterType.BUTTERFLY.ordinal()), worldObj, posX, posY, posZ); setDead(); @@ -319,13 +337,12 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly /* LOOT */ @Override protected void dropFewItems(boolean playerKill, int lootLevel) { - for(ItemStack stack : contained.getLootDrop(this, playerKill, lootLevel)) + for (ItemStack stack : contained.getLootDrop(this, playerKill, lootLevel)) StackUtils.dropItemStackAsEntity(stack, worldObj, posX, posY, posZ); // Drop pollen if any - if(getPollen() != null) { + if (getPollen() != null) StackUtils.dropItemStackAsEntity(AlleleManager.alleleRegistry.getSpeciesRoot(getPollen().getClass()).getMemberStack(getPollen(), EnumGermlingType.POLLEN.ordinal()), worldObj, posX, posY, posZ); - } } /* UPDATING */ @@ -334,15 +351,14 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly super.onUpdate(); // Update stuff client side - if(!Proxies.common.isSimulating(worldObj)) { + if (!Proxies.common.isSimulating(worldObj)) { if (species == null || dataWatcher.hasChanges()) { - scale = (float)dataWatcher.getWatchableObjectInt(DATAWATCHER_ID_SCALE) / 100; + scale = (float) dataWatcher.getWatchableObjectInt(DATAWATCHER_ID_SCALE) / 100; String uid = dataWatcher.getWatchableObjectString(DATAWATCHER_ID_SPECIES); - if(species == null || !species.getUID().equals(uid)) { + if (species == null || !species.getUID().equals(uid)) { IAllele allele = AlleleManager.alleleRegistry.getAllele(uid); - if(allele instanceof IAlleleButterflySpecies) { - setSpecies((IAlleleButterflySpecies)allele); - } + if (allele instanceof IAlleleButterflySpecies) + setSpecies((IAlleleButterflySpecies) allele); } } state = EnumButterflyState.VALUES[dataWatcher.getWatchableObjectByte(DATAWATCHER_ID_STATE)]; @@ -351,19 +367,21 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly motionY *= 0.6000000238418579d; // Make sure we die if the butterfly hasn't rested in a long, long time. - if(exhaustion > EXHAUSTION_CONSUMPTION && getRNG().nextInt(20) == 0) + if (exhaustion > EXHAUSTION_CONSUMPTION && getRNG().nextInt(20) == 0) attackEntityFrom(DamageSource.generic, 1); // Reduce cooldowns - if(cooldownEgg > 0) cooldownEgg--; - if(cooldownPollination > 0) cooldownPollination--; + if (cooldownEgg > 0) + cooldownEgg--; + if (cooldownPollination > 0) + cooldownPollination--; } @Override protected void updateAITasks() { super.updateAITasks(); - if(state.doesMovement && flightTarget != null) { + if (state.doesMovement && flightTarget != null) { double diffX = flightTarget.posX + 0.5d - posX; double diffY = flightTarget.posY + 0.1d - posY; double diffZ = flightTarget.posZ + 0.5d - posZ; @@ -374,7 +392,7 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly //float f = (float)(Math.atan2(motionZ, motionX) * 180.0d / Math.PI) - 90f; //rotationYaw += MathHelper.wrapAngleTo180_float(f - rotationYaw); - float horizontal = (float)((Math.atan2(motionZ, motionX) * 180d) / Math.PI) - 90f; + float horizontal = (float) ((Math.atan2(motionZ, motionX) * 180d) / Math.PI) - 90f; rotationYaw += MathHelper.wrapAngleTo180_float(horizontal - rotationYaw); setMoveForward(contained.getGenome().getSpeed()); @@ -382,10 +400,23 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly } - @Override protected boolean canTriggerWalking() { return false; } - @Override protected void fall(float par1) {} - @Override protected void updateFallState(double par1, boolean par3) {} - @Override public boolean doesEntityNotTriggerPressurePlate() { return true; } + @Override + protected boolean canTriggerWalking() { + return false; + } + + @Override + protected void fall(float par1) { + } + + @Override + protected void updateFallState(double par1, boolean par3) { + } + + @Override + public boolean doesEntityNotTriggerPressurePlate() { + return true; + } @Override public float getSwingProgress(float partialTicktime) {