diff options
| author | Draknyte1 <Draknyte1@hotmail.com> | 2016-11-06 19:32:27 +1000 |
|---|---|---|
| committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-11-06 19:32:27 +1000 |
| commit | cbe0e497be8e466c380a5b4fa781b314ede9ada3 (patch) | |
| tree | b85848b432adf458e3abda466ee46d9dfc3e454b /src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/tileentity | |
| parent | c40416b036c0e89451e1558253ccf07bbee028d0 (diff) | |
| download | GT5-Unofficial-cbe0e497be8e466c380a5b4fa781b314ede9ada3.tar.gz GT5-Unofficial-cbe0e497be8e466c380a5b4fa781b314ede9ada3.tar.bz2 GT5-Unofficial-cbe0e497be8e466c380a5b4fa781b314ede9ada3.zip | |
Revert "$ Cleaned up the entire project."
This reverts commit 0669f5eb9d5029a8b94ec552171b0837605f7747.
# Conflicts:
# src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMTE_NuclearReactor.java
# src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntity_MassFabricator.java
Revert "% Cleaned up Imports."
This reverts commit 3654052fb63a571c5eaca7f20714b87c17f7e966.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/tileentity')
| -rw-r--r-- | src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/tileentity/TileEntityKineticWindGenerator.java | 488 |
1 files changed, 269 insertions, 219 deletions
diff --git a/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/tileentity/TileEntityKineticWindGenerator.java b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/tileentity/TileEntityKineticWindGenerator.java index 1dc9d39acf..f094c8f928 100644 --- a/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/tileentity/TileEntityKineticWindGenerator.java +++ b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/tileentity/TileEntityKineticWindGenerator.java @@ -1,19 +1,22 @@ package gtPlusPlus.xmod.ic2.block.kieticgenerator.tileentity; -import java.util.List; -import java.util.Vector; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import ic2.api.energy.tile.IKineticSource; import ic2.api.item.IKineticRotor; import ic2.api.item.IKineticRotor.GearboxType; -import ic2.core.*; +import ic2.core.ContainerBase; +import ic2.core.IC2; +import ic2.core.IHasGui; +import ic2.core.WorldData; import ic2.core.block.invslot.InvSlotConsumableKineticRotor; import ic2.core.block.kineticgenerator.container.ContainerWindKineticGenerator; import ic2.core.block.kineticgenerator.gui.GuiWindKineticGenerator; import ic2.core.block.kineticgenerator.tileentity.TileEntityWindKineticGenerator; +import ic2.core.network.NetworkManager; import ic2.core.util.Util; + +import java.util.List; +import java.util.Vector; + import net.minecraft.block.Block; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; @@ -22,321 +25,368 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import net.minecraft.world.ChunkCache; import net.minecraftforge.common.util.ForgeDirection; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; -public class TileEntityKineticWindGenerator extends TileEntityWindKineticGenerator implements IKineticSource, IHasGui { - private static final double efficiencyRollOffExponent = 2.0D; - private static final int nominalRotationPeriod = 500; - public final InvSlotConsumableKineticRotor rotorSlot; - private double windStrength; - private int obstructedCrossSection; - private int crossSection; - private int updateTicker; - private float rotationSpeed; - - public TileEntityKineticWindGenerator() { - this.updateTicker = IC2.random.nextInt(this.getTickRate()); +public class TileEntityKineticWindGenerator +extends TileEntityWindKineticGenerator +implements IKineticSource, IHasGui +{ + public final InvSlotConsumableKineticRotor rotorSlot; + private double windStrength; + private int obstructedCrossSection; + private int crossSection; + private int updateTicker; + private float rotationSpeed; + private static final double efficiencyRollOffExponent = 2.0D; + private static final int nominalRotationPeriod = 500; + + public TileEntityKineticWindGenerator() + { + this.updateTicker = IC2.random.nextInt(getTickRate()); this.rotorSlot = new InvSlotConsumableKineticRotor(this, "rotorslot", 0, null, 1, null, GearboxType.WIND); } - @Override - public double calcWindStrength() { - double windStr = WorldData.get(this.worldObj).windSim.getWindAt(this.yCoord); - - windStr *= 1.0D - Math.pow(this.obstructedCrossSection / this.crossSection, 2.0D); - - return Math.max(0.0D, windStr); - } - - @Override - public boolean checkrotor() { - return !this.rotorSlot.isEmpty(); - } + + public void update2Entity() + { + super.updateEntity(); - @Override - public int checkSpace(int length, final boolean onlyrotor) { - int box = this.getRotorDiameter() / 2; - int lentemp = 0; - if (onlyrotor) { - length = 1; - lentemp = length + 1; + assert (IC2.platform.isSimulating()); + if (this.updateTicker++ % getTickRate() != 0) { + return; } - if (!onlyrotor) { - box *= 2; + boolean needsInvUpdate = false; + if (!this.rotorSlot.isEmpty()) + { + if (checkSpace(1, true) == 0) + { + if (getActive() != true) { + setActive(true); + } + needsInvUpdate = true; + } + else + { + if (getActive()) { + setActive(false); + } + needsInvUpdate = true; + } } - final ForgeDirection fwdDir = ForgeDirection.VALID_DIRECTIONS[this.getFacing()]; - final ForgeDirection rightDir = fwdDir.getRotation(ForgeDirection.DOWN); - - final int xMaxDist = Math.abs(length * fwdDir.offsetX + box * rightDir.offsetX); - - final int zMaxDist = Math.abs(length * fwdDir.offsetZ + box * rightDir.offsetZ); - - final ChunkCache chunkCache = new ChunkCache(this.worldObj, this.xCoord - xMaxDist, this.yCoord - box, - this.zCoord - zMaxDist, this.xCoord + xMaxDist, this.yCoord + box, this.zCoord + zMaxDist, 0); + else + { + if (getActive()) { + setActive(false); + } + needsInvUpdate = true; + } + if (getActive()) + { + this.crossSection = (getRotorDiameter() / 2 * 2 * 2 + 1); - int ret = 0; - for (int up = -box; up <= box; up++) { - final int y = this.yCoord + up; - for (int right = -box; right <= box; right++) { - boolean occupied = false; - for (int fwd = lentemp - length; fwd <= length; fwd++) { - final int x = this.xCoord + fwd * fwdDir.offsetX + right * rightDir.offsetX; + this.crossSection *= this.crossSection; + this.obstructedCrossSection = checkSpace(getRotorDiameter() * 3, false); + if ((this.obstructedCrossSection > 0) && (this.obstructedCrossSection <= (getRotorDiameter() + 1) / 2)) { + this.obstructedCrossSection = 0; + } else if (this.obstructedCrossSection < 0) { + this.obstructedCrossSection = this.crossSection; + } + this.windStrength = calcWindStrength(); - final int z = this.zCoord + fwd * fwdDir.offsetZ + right * rightDir.offsetZ; + float speed = (float)Util.limit((this.windStrength - getMinWindStrength()) / getMaxWindStrength(), 0.0D, 2.0D); - assert Math.abs(x - this.xCoord) <= xMaxDist; - assert Math.abs(z - this.zCoord) <= zMaxDist; - final Block block = chunkCache.getBlock(x, y, z); - if (!block.isAir(chunkCache, x, y, z)) { - occupied = true; - if ((up != 0 || right != 0 || fwd != 0) - && chunkCache.getTileEntity(x, y, z) instanceof TileEntityKineticWindGenerator - && !onlyrotor) { - return -1; - } - } - } - if (occupied) { - ret++; + setRotationSpeed(speed*2); + if (this.windStrength >= getMinWindStrength()) { + if (this.windStrength <= getMaxWindStrength()) { + this.rotorSlot.damage(1, false); + } else { + this.rotorSlot.damage(4, false); } } } - return ret; } - public boolean enableUpdateEntity() { - return IC2.platform.isSimulating(); - } - @Override - public boolean facingMatchesDirection(final ForgeDirection direction) { - return direction.ordinal() == this.getFacing(); - } @Override - public float getAngle() { - if (this.rotationSpeed > 0.0F) { - final long period = (long) (5.0E+008F / this.rotationSpeed); + public List<String> getNetworkedFields() + { + List<String> ret = new Vector<String>(1); - return (float) (System.nanoTime() % period) / (float) period * 360.0F; - } - return 0.0F; + ret.add("rotationSpeed"); + ret.add("rotorSlot"); + ret.addAll(super.getNetworkedFields()); + + return ret; } @Override - public float getefficiency() { - final ItemStack stack = this.rotorSlot.get(); - if (stack != null && stack.getItem() instanceof IKineticRotor) { - return (float) (((IKineticRotor) stack.getItem()).getEfficiency(stack) * 1.5); - } - return 0.0F; + public ContainerBase<TileEntityWindKineticGenerator> getGuiContainer(EntityPlayer entityPlayer) + { + return new ContainerWindKineticGenerator(entityPlayer, this); } @Override @SideOnly(Side.CLIENT) - public GuiScreen getGui(final EntityPlayer entityPlayer, final boolean isAdmin) { + public GuiScreen getGui(EntityPlayer entityPlayer, boolean isAdmin) + { return new GuiWindKineticGenerator(new ContainerWindKineticGenerator(entityPlayer, this)); } @Override - public ContainerBase<TileEntityWindKineticGenerator> getGuiContainer(final EntityPlayer entityPlayer) { - return new ContainerWindKineticGenerator(entityPlayer, this); + public boolean facingMatchesDirection(ForgeDirection direction) + { + return direction.ordinal() == getFacing(); } @Override - public String getInventoryName() { - return "Advanced Kinetic Wind Generator"; + public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) + { + if ((side == 0) || (side == 1)) { + return false; + } + return getFacing() != side; } @Override - public int getKuOutput() { - if (this.windStrength >= this.getMinWindStrength() && this.getActive()) { - return (int) (this.windStrength * 50.0D * this.getefficiency()); - } - return 0; + public void setFacing(short side) + { + super.setFacing(side); + } + + public boolean enableUpdateEntity() + { + return IC2.platform.isSimulating(); } @Override - public int getMaxWindStrength() { - final ItemStack stack = this.rotorSlot.get(); - if (stack != null && stack.getItem() instanceof IKineticRotor) { - return ((IKineticRotor) stack.getItem()).getMaxWindStrength(stack) * 2; + public String getRotorhealth() + { + if (!this.rotorSlot.isEmpty()) { + return StatCollector.translateToLocalFormatted("ic2.WindKineticGenerator.gui.rotorhealth", new Object[] { Integer.valueOf((int)(100.0F - this.rotorSlot.get().getItemDamage() / this.rotorSlot.get().getMaxDamage() * 100.0F)) }); } - return 0; + return ""; } @Override - public int getMinWindStrength() { - final ItemStack stack = this.rotorSlot.get(); - if (stack != null && stack.getItem() instanceof IKineticRotor) { - return ((IKineticRotor) stack.getItem()).getMinWindStrength(stack) / 2; + public int maxrequestkineticenergyTick(ForgeDirection directionFrom) + { + return getKuOutput(); + } + + @Override + public int requestkineticenergy(ForgeDirection directionFrom, int requestkineticenergy) + { + if (facingMatchesDirection(directionFrom.getOpposite())) { + return Math.min(requestkineticenergy, getKuOutput()); } return 0; } @Override - public List<String> getNetworkedFields() { - final List<String> ret = new Vector<String>(1); + public String getInventoryName() + { + return "Advanced Kinetic Wind Generator"; + } - ret.add("rotationSpeed"); - ret.add("rotorSlot"); - ret.addAll(super.getNetworkedFields()); + @Override + public void onGuiClosed(EntityPlayer entityPlayer) {} - return ret; + @Override + public boolean shouldRenderInPass(int pass) + { + return pass == 0; } @Override - public int getRotorDiameter() { - final ItemStack stack = this.rotorSlot.get(); - if (stack != null && stack.getItem() instanceof IKineticRotor) { - return ((IKineticRotor) stack.getItem()).getDiameter(stack) / 2; + public int checkSpace(int length, boolean onlyrotor) + { + int box = getRotorDiameter() / 2; + int lentemp = 0; + if (onlyrotor) + { + length = 1; + lentemp = length + 1; } - return 0; + if (!onlyrotor) { + box *= 2; + } + ForgeDirection fwdDir = ForgeDirection.VALID_DIRECTIONS[getFacing()]; + ForgeDirection rightDir = fwdDir.getRotation(ForgeDirection.DOWN); + + int xMaxDist = Math.abs(length * fwdDir.offsetX + box * rightDir.offsetX); + + int zMaxDist = Math.abs(length * fwdDir.offsetZ + box * rightDir.offsetZ); + + + ChunkCache chunkCache = new ChunkCache(this.worldObj, this.xCoord - xMaxDist, this.yCoord - box, this.zCoord - zMaxDist, this.xCoord + xMaxDist, this.yCoord + box, this.zCoord + zMaxDist, 0); + + + + int ret = 0; + for (int up = -box; up <= box; up++) + { + int y = this.yCoord + up; + for (int right = -box; right <= box; right++) + { + boolean occupied = false; + for (int fwd = lentemp - length; fwd <= length; fwd++) + { + int x = this.xCoord + fwd * fwdDir.offsetX + right * rightDir.offsetX; + + int z = this.zCoord + fwd * fwdDir.offsetZ + right * rightDir.offsetZ; + + + assert (Math.abs(x - this.xCoord) <= xMaxDist); + assert (Math.abs(z - this.zCoord) <= zMaxDist); + + Block block = chunkCache.getBlock(x, y, z); + if (!block.isAir(chunkCache, x, y, z)) + { + occupied = true; + if (((up != 0) || (right != 0) || (fwd != 0)) && ((chunkCache.getTileEntity(x, y, z) instanceof TileEntityKineticWindGenerator)) && (!onlyrotor)) { + return -1; + } + } + } + if (occupied) { + ret++; + } + } + } + return ret; } @Override - public String getRotorhealth() { - if (!this.rotorSlot.isEmpty()) { - return StatCollector.translateToLocalFormatted("ic2.WindKineticGenerator.gui.rotorhealth", new Object[] { - Integer.valueOf((int) (100.0F - - this.rotorSlot.get().getItemDamage() / this.rotorSlot.get().getMaxDamage() * 100.0F)) - }); - } - return ""; + public boolean checkrotor() + { + return !this.rotorSlot.isEmpty(); } @Override - public ResourceLocation getRotorRenderTexture() { - final ItemStack stack = this.rotorSlot.get(); - if (stack != null && stack.getItem() instanceof IKineticRotor) { - return ((IKineticRotor) stack.getItem()).getRotorRenderTexture(stack); + public boolean rotorspace() + { + return checkSpace(1, true) == 0; + } + + private void setRotationSpeed(float speed) + { + if (this.rotationSpeed != speed) + { + this.rotationSpeed = speed; + ((NetworkManager)IC2.network.get()).updateTileEntityField(this, "rotationSpeed"); } - return new ResourceLocation(IC2.textureDomain, "textures/items/rotors/rotorWoodmodel.png"); } @Override - public int getTickRate() { + public int getTickRate() + { return 32; } @Override - public int getWindStrength() { - return (int) this.windStrength; - } + public double calcWindStrength() + { + double windStr = WorldData.get(this.worldObj).windSim.getWindAt(this.yCoord); - @Override - public boolean guiisminWindStrength() { - return this.windStrength >= this.getMinWindStrength(); + windStr *= (1.0D - Math.pow(this.obstructedCrossSection / this.crossSection, 2.0D)); + + + return Math.max(0.0D, windStr); } @Override - public boolean guiisoverload() { - if (this.windStrength > this.getMaxWindStrength()) { - return true; + public float getAngle() + { + if (this.rotationSpeed > 0.0F) + { + long period = (long) (5.0E+008F / this.rotationSpeed); + + + return (float)(System.nanoTime() % period) / (float)period * 360.0F; } - return false; + return 0.0F; } @Override - public int maxrequestkineticenergyTick(final ForgeDirection directionFrom) { - return this.getKuOutput(); + public float getefficiency() + { + ItemStack stack = this.rotorSlot.get(); + if ((stack != null) && ((stack.getItem() instanceof IKineticRotor))) { + return (float) (((IKineticRotor)stack.getItem()).getEfficiency(stack)*1.5); + } + return 0.0F; } @Override - public void onGuiClosed(final EntityPlayer entityPlayer) { + public int getMinWindStrength() + { + ItemStack stack = this.rotorSlot.get(); + if ((stack != null) && ((stack.getItem() instanceof IKineticRotor))) { + return ((IKineticRotor)stack.getItem()).getMinWindStrength(stack)/2; + } + return 0; } @Override - public int requestkineticenergy(final ForgeDirection directionFrom, final int requestkineticenergy) { - if (this.facingMatchesDirection(directionFrom.getOpposite())) { - return Math.min(requestkineticenergy, this.getKuOutput()); + public int getMaxWindStrength() + { + ItemStack stack = this.rotorSlot.get(); + if ((stack != null) && ((stack.getItem() instanceof IKineticRotor))) { + return ((IKineticRotor)stack.getItem()).getMaxWindStrength(stack)*2; } return 0; } @Override - public boolean rotorspace() { - return this.checkSpace(1, true) == 0; + public int getRotorDiameter() + { + ItemStack stack = this.rotorSlot.get(); + if ((stack != null) && ((stack.getItem() instanceof IKineticRotor))) { + return ((IKineticRotor)stack.getItem()).getDiameter(stack)/2; + } + return 0; } @Override - public void setFacing(final short side) { - super.setFacing(side); + public ResourceLocation getRotorRenderTexture() + { + ItemStack stack = this.rotorSlot.get(); + if ((stack != null) && ((stack.getItem() instanceof IKineticRotor))) { + return ((IKineticRotor)stack.getItem()).getRotorRenderTexture(stack); + } + return new ResourceLocation(IC2.textureDomain, "textures/items/rotors/rotorWoodmodel.png"); } - private void setRotationSpeed(final float speed) { - if (this.rotationSpeed != speed) { - this.rotationSpeed = speed; - IC2.network.get().updateTileEntityField(this, "rotationSpeed"); + @Override + public boolean guiisoverload() + { + if (this.windStrength > getMaxWindStrength()) { + return true; } + return false; } @Override - public boolean shouldRenderInPass(final int pass) { - return pass == 0; + public boolean guiisminWindStrength() + { + return this.windStrength >= getMinWindStrength(); } - public void update2Entity() { - super.updateEntity(); - - assert IC2.platform.isSimulating(); - if (this.updateTicker++ % this.getTickRate() != 0) { - return; - } - boolean needsInvUpdate = false; - if (!this.rotorSlot.isEmpty()) { - if (this.checkSpace(1, true) == 0) { - if (this.getActive() != true) { - this.setActive(true); - } - needsInvUpdate = true; - } - else { - if (this.getActive()) { - this.setActive(false); - } - needsInvUpdate = true; - } - } - else { - if (this.getActive()) { - this.setActive(false); - } - needsInvUpdate = true; - } - if (this.getActive()) { - this.crossSection = this.getRotorDiameter() / 2 * 2 * 2 + 1; - - this.crossSection *= this.crossSection; - this.obstructedCrossSection = this.checkSpace(this.getRotorDiameter() * 3, false); - if (this.obstructedCrossSection > 0 && this.obstructedCrossSection <= (this.getRotorDiameter() + 1) / 2) { - this.obstructedCrossSection = 0; - } - else if (this.obstructedCrossSection < 0) { - this.obstructedCrossSection = this.crossSection; - } - this.windStrength = this.calcWindStrength(); - - final float speed = (float) Util - .limit((this.windStrength - this.getMinWindStrength()) / this.getMaxWindStrength(), 0.0D, 2.0D); - - this.setRotationSpeed(speed * 2); - if (this.windStrength >= this.getMinWindStrength()) { - if (this.windStrength <= this.getMaxWindStrength()) { - this.rotorSlot.damage(1, false); - } - else { - this.rotorSlot.damage(4, false); - } - } + @Override + public int getKuOutput() + { + if ((this.windStrength >= getMinWindStrength()) && (getActive())) { + return (int)(this.windStrength * 50.0D * getefficiency()); } + return 0; } @Override - public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final int side) { - if (side == 0 || side == 1) { - return false; - } - return this.getFacing() != side; + public int getWindStrength() + { + return (int)this.windStrength; } } |
