diff options
author | draknyte1 <draknyte1@hotmail.com> | 2016-11-04 15:23:26 +1000 |
---|---|---|
committer | draknyte1 <draknyte1@hotmail.com> | 2016-11-04 15:23:26 +1000 |
commit | 0669f5eb9d5029a8b94ec552171b0837605f7747 (patch) | |
tree | 6b40e64c04d51b7a33cf2f0b35f7232cf37c4247 /src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator | |
parent | 3654052fb63a571c5eaca7f20714b87c17f7e966 (diff) | |
download | GT5-Unofficial-0669f5eb9d5029a8b94ec552171b0837605f7747.tar.gz GT5-Unofficial-0669f5eb9d5029a8b94ec552171b0837605f7747.tar.bz2 GT5-Unofficial-0669f5eb9d5029a8b94ec552171b0837605f7747.zip |
$ Cleaned up the entire project.
> Much neat, very nices.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator')
5 files changed, 375 insertions, 428 deletions
diff --git a/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/IC2_BlockKineticGenerator.java b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/IC2_BlockKineticGenerator.java index b0a6b0d6fb..d4597cecab 100644 --- a/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/IC2_BlockKineticGenerator.java +++ b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/IC2_BlockKineticGenerator.java @@ -15,61 +15,53 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -public class IC2_BlockKineticGenerator - extends BlockMultiID -{ - public IC2_BlockKineticGenerator(InternalName internalName1) - { - super(internalName1, Material.iron, ItemKineticGenerator.class); - - setHardness(3.0F); - setStepSound(Block.soundTypeMetal); - this.setCreativeTab(AddToCreativeTab.tabMachines); - - GameRegistry.registerTileEntity(TileEntityWindKineticGenerator.class, "Advanced Kinetic Wind Generator"); - - } - - @Override -public String getTextureFolder(int id) - { - return "kineticgenerator"; - } - - @Override -public int damageDropped(int meta) - { - return meta; - } - - @Override -public Class<? extends TileEntity> getTeClass(int meta, MutableObject<Class<?>[]> ctorArgTypes, MutableObject<Object[]> ctorArgs) - { - try - { - switch (meta) - { - case 0: - return TileEntityWindKineticGenerator.class; - } - } - catch (Exception e) - { - throw new RuntimeException(e); - } - return null; - } - - @Override -public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float a, float b, float c) - { - if (entityPlayer.isSneaking()) { - return false; - } - TileEntity te = getOwnTe(world, x, y, z); - if ((te != null) && ((te instanceof TileEntityManualKineticGenerator))) { - return ((TileEntityManualKineticGenerator)te).playerKlicked(entityPlayer); - } - return super.onBlockActivated(world, x, y, z, entityPlayer, side, a, b, c); - } +public class IC2_BlockKineticGenerator extends BlockMultiID { + public IC2_BlockKineticGenerator(final InternalName internalName1) { + super(internalName1, Material.iron, ItemKineticGenerator.class); + + this.setHardness(3.0F); + this.setStepSound(Block.soundTypeMetal); + this.setCreativeTab(AddToCreativeTab.tabMachines); + + GameRegistry.registerTileEntity(TileEntityWindKineticGenerator.class, "Advanced Kinetic Wind Generator"); + + } + + @Override + public int damageDropped(final int meta) { + return meta; + } + + @Override + public Class<? extends TileEntity> getTeClass(final int meta, final MutableObject<Class<?>[]> ctorArgTypes, + final MutableObject<Object[]> ctorArgs) { + try { + switch (meta) { + case 0: + return TileEntityWindKineticGenerator.class; + } + } + catch (final Exception e) { + throw new RuntimeException(e); + } + return null; + } + + @Override + public String getTextureFolder(final int id) { + return "kineticgenerator"; + } + + @Override + public boolean onBlockActivated(final World world, final int x, final int y, final int z, + final EntityPlayer entityPlayer, final int side, final float a, final float b, final float c) { + if (entityPlayer.isSneaking()) { + return false; + } + final TileEntity te = this.getOwnTe(world, x, y, z); + if (te != null && te instanceof TileEntityManualKineticGenerator) { + return ((TileEntityManualKineticGenerator) te).playerKlicked(entityPlayer); + } + return super.onBlockActivated(world, x, y, z, entityPlayer, side, a, b, c); + } } diff --git a/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/IC2_TEComponent.java b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/IC2_TEComponent.java index e41097c6ef..7d61881016 100644 --- a/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/IC2_TEComponent.java +++ b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/IC2_TEComponent.java @@ -8,40 +8,41 @@ import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; -public abstract class IC2_TEComponent -{ - protected final TileEntityBlock parent; - - public IC2_TEComponent(TileEntityBlock parent) - { - this.parent = parent; - } - - public abstract String getDefaultName(); - - public void readFromNbt(NBTTagCompound nbt) {} - - public NBTTagCompound writeToNbt() - { - return null; - } - - public void onLoaded() {} - - public void onUnloaded() {} - - public void onNeighborUpdate(Block srcBlock) {} - - public void onContainerUpdate(String name, EntityPlayerMP player) {} - - public void onNetworkUpdate(DataInput is) - throws IOException - {} - - public boolean enableWorldTick() - { - return false; - } - - public void onWorldTick() {} +public abstract class IC2_TEComponent { + protected final TileEntityBlock parent; + + public IC2_TEComponent(final TileEntityBlock parent) { + this.parent = parent; + } + + public boolean enableWorldTick() { + return false; + } + + public abstract String getDefaultName(); + + public void onContainerUpdate(final String name, final EntityPlayerMP player) { + } + + public void onLoaded() { + } + + public void onNeighborUpdate(final Block srcBlock) { + } + + public void onNetworkUpdate(final DataInput is) throws IOException { + } + + public void onUnloaded() { + } + + public void onWorldTick() { + } + + public void readFromNbt(final NBTTagCompound nbt) { + } + + public NBTTagCompound writeToNbt() { + return null; + } } diff --git a/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/container/ContainerKineticWindgenerator.java b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/container/ContainerKineticWindgenerator.java index 132aee6f00..7d65a042ec 100644 --- a/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/container/ContainerKineticWindgenerator.java +++ b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/container/ContainerKineticWindgenerator.java @@ -7,20 +7,18 @@ import ic2.core.block.kineticgenerator.tileentity.TileEntityWindKineticGenerator import ic2.core.slot.SlotInvSlot; import net.minecraft.entity.player.EntityPlayer; -public class ContainerKineticWindgenerator - extends ContainerFullInv<TileEntityWindKineticGenerator> -{ - public ContainerKineticWindgenerator(EntityPlayer entityPlayer, TileEntityWindKineticGenerator tileEntity1) - { - super(entityPlayer, tileEntity1, 166); - - addSlotToContainer(new SlotInvSlot(tileEntity1.rotorSlot, 0, 80, 26)); - } - - public List<String> getNetworkedFields() - { - List<String> ret = super.getNetworkedFields(); - ret.add("windStrength"); - return ret; - } +public class ContainerKineticWindgenerator extends ContainerFullInv<TileEntityWindKineticGenerator> { + public ContainerKineticWindgenerator(final EntityPlayer entityPlayer, + final TileEntityWindKineticGenerator tileEntity1) { + super(entityPlayer, tileEntity1, 166); + + this.addSlotToContainer(new SlotInvSlot(tileEntity1.rotorSlot, 0, 80, 26)); + } + + @Override + public List<String> getNetworkedFields() { + final List<String> ret = super.getNetworkedFields(); + ret.add("windStrength"); + return ret; + } } diff --git a/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/gui/GuiKineticWindGenerator.java b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/gui/GuiKineticWindGenerator.java index 5612a43651..3380b83c39 100644 --- a/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/gui/GuiKineticWindGenerator.java +++ b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/gui/GuiKineticWindGenerator.java @@ -6,70 +6,72 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import ic2.core.IC2; import ic2.core.block.kineticgenerator.container.ContainerWindKineticGenerator; -import ic2.core.block.kineticgenerator.tileentity.TileEntityWindKineticGenerator; import ic2.core.util.GuiTooltipHelper; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; @SideOnly(Side.CLIENT) -public class GuiKineticWindGenerator - extends GuiContainer -{ - public ContainerWindKineticGenerator container; - public String name; - - public GuiKineticWindGenerator(ContainerWindKineticGenerator container1) - { - super(container1); - - this.container = container1; - this.name = StatCollector.translateToLocal("ic2.WindKineticGenerator.gui.name"); - } - - protected void drawGuiContainerForegroundLayer(int par1, int par2) - { - this.fontRendererObj.drawString(this.name, (this.xSize - this.fontRendererObj.getStringWidth(this.name)) / 2, 6, 4210752); - if (((TileEntityWindKineticGenerator)this.container.base).checkrotor()) - { - if (!((TileEntityWindKineticGenerator)this.container.base).rotorspace()) - { - this.fontRendererObj.drawString(StatCollector.translateToLocal("ic2.WindKineticGenerator.gui.rotorspace"), 20, 52, 2157374); - } - else if ((((TileEntityWindKineticGenerator)this.container.base).checkrotor()) && (!((TileEntityWindKineticGenerator)this.container.base).guiisminWindStrength())) - { - this.fontRendererObj.drawString(StatCollector.translateToLocal("ic2.WindKineticGenerator.gui.windweak1"), 27, 52, 2157374); - this.fontRendererObj.drawString(StatCollector.translateToLocal("ic2.WindKineticGenerator.gui.windweak2"), 24, 69, 2157374); - } - else - { - this.fontRendererObj.drawString(StatCollector.translateToLocalFormatted("ic2.WindKineticGenerator.gui.output", new Object[] { Integer.valueOf(((TileEntityWindKineticGenerator)this.container.base).getKuOutput()) }), 55, 52, 2157374); - this.fontRendererObj.drawString(((TileEntityWindKineticGenerator)this.container.base).getRotorhealth() + " %", 46, 70, 2157374); - if (((TileEntityWindKineticGenerator)this.container.base).guiisoverload()) - { - GuiTooltipHelper.drawAreaTooltip(par1 - this.guiLeft, par2 - this.guiTop, StatCollector.translateToLocal("ic2.WindKineticGenerator.error.overload"), 44, 20, 79, 45); - GuiTooltipHelper.drawAreaTooltip(par1 - this.guiLeft, par2 - this.guiTop, StatCollector.translateToLocal("ic2.WindKineticGenerator.error.overload2"), 102, 20, 131, 45); - } - } - } - else { - this.fontRendererObj.drawString(StatCollector.translateToLocal("ic2.WindKineticGenerator.gui.rotormiss"), 27, 52, 2157374); - } - } - - protected void drawGuiContainerBackgroundLayer(float f, int x, int y) - { - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.mc.getTextureManager().bindTexture(background); - int j = (this.width - this.xSize) / 2; - int k = (this.height - this.ySize) / 2; - drawTexturedModalRect(j, k, 0, 0, this.xSize, this.ySize); - if ((((TileEntityWindKineticGenerator)this.container.base).guiisoverload()) && (((TileEntityWindKineticGenerator)this.container.base).checkrotor())) - { - drawTexturedModalRect(j + 44, k + 20, 176, 0, 30, 26); - drawTexturedModalRect(j + 102, k + 20, 176, 0, 30, 26); - } - } - - private static final ResourceLocation background = new ResourceLocation(IC2.textureDomain, "textures/gui/GUIWindKineticGenerator.png"); +public class GuiKineticWindGenerator extends GuiContainer { + private static final ResourceLocation background = new ResourceLocation(IC2.textureDomain, + "textures/gui/GUIWindKineticGenerator.png"); + public ContainerWindKineticGenerator container; + + public String name; + + public GuiKineticWindGenerator(final ContainerWindKineticGenerator container1) { + super(container1); + + this.container = container1; + this.name = StatCollector.translateToLocal("ic2.WindKineticGenerator.gui.name"); + } + + @Override + protected void drawGuiContainerBackgroundLayer(final float f, final int x, final int y) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.getTextureManager().bindTexture(GuiKineticWindGenerator.background); + final int j = (this.width - this.xSize) / 2; + final int k = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(j, k, 0, 0, this.xSize, this.ySize); + if (this.container.base.guiisoverload() && this.container.base.checkrotor()) { + this.drawTexturedModalRect(j + 44, k + 20, 176, 0, 30, 26); + this.drawTexturedModalRect(j + 102, k + 20, 176, 0, 30, 26); + } + } + + @Override + protected void drawGuiContainerForegroundLayer(final int par1, final int par2) { + this.fontRendererObj.drawString(this.name, (this.xSize - this.fontRendererObj.getStringWidth(this.name)) / 2, 6, + 4210752); + if (this.container.base.checkrotor()) { + if (!this.container.base.rotorspace()) { + this.fontRendererObj.drawString( + StatCollector.translateToLocal("ic2.WindKineticGenerator.gui.rotorspace"), 20, 52, 2157374); + } + else if (this.container.base.checkrotor() && !this.container.base.guiisminWindStrength()) { + this.fontRendererObj.drawString( + StatCollector.translateToLocal("ic2.WindKineticGenerator.gui.windweak1"), 27, 52, 2157374); + this.fontRendererObj.drawString( + StatCollector.translateToLocal("ic2.WindKineticGenerator.gui.windweak2"), 24, 69, 2157374); + } + else { + this.fontRendererObj.drawString( + StatCollector.translateToLocalFormatted("ic2.WindKineticGenerator.gui.output", new Object[] { + Integer.valueOf(this.container.base.getKuOutput()) + }), 55, 52, 2157374); + this.fontRendererObj.drawString(this.container.base.getRotorhealth() + " %", 46, 70, 2157374); + if (this.container.base.guiisoverload()) { + GuiTooltipHelper.drawAreaTooltip(par1 - this.guiLeft, par2 - this.guiTop, + StatCollector.translateToLocal("ic2.WindKineticGenerator.error.overload"), 44, 20, 79, 45); + GuiTooltipHelper.drawAreaTooltip(par1 - this.guiLeft, par2 - this.guiTop, + StatCollector.translateToLocal("ic2.WindKineticGenerator.error.overload2"), 102, 20, 131, + 45); + } + } + } + else { + this.fontRendererObj.drawString(StatCollector.translateToLocal("ic2.WindKineticGenerator.gui.rotormiss"), + 27, 52, 2157374); + } + } } 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 bb5531ea9a..1dc9d39acf 100644 --- a/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/tileentity/TileEntityKineticWindGenerator.java +++ b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/tileentity/TileEntityKineticWindGenerator.java @@ -13,7 +13,6 @@ 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 net.minecraft.block.Block; import net.minecraft.client.gui.GuiScreen; @@ -24,365 +23,320 @@ import net.minecraft.util.StatCollector; import net.minecraft.world.ChunkCache; import net.minecraftforge.common.util.ForgeDirection; -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()); +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()); this.rotorSlot = new InvSlotConsumableKineticRotor(this, "rotorslot", 0, null, 1, null, GearboxType.WIND); } - - public void update2Entity() - { - super.updateEntity(); - - assert (IC2.platform.isSimulating()); - if (this.updateTicker++ % getTickRate() != 0) { - return; - } - 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; - } - } - else - { - if (getActive()) { - setActive(false); - } - needsInvUpdate = true; - } - if (getActive()) - { - this.crossSection = (getRotorDiameter() / 2 * 2 * 2 + 1); + @Override + public double calcWindStrength() { + double windStr = WorldData.get(this.worldObj).windSim.getWindAt(this.yCoord); - 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(); + windStr *= 1.0D - Math.pow(this.obstructedCrossSection / this.crossSection, 2.0D); - float speed = (float)Util.limit((this.windStrength - getMinWindStrength()) / getMaxWindStrength(), 0.0D, 2.0D); + return Math.max(0.0D, windStr); + } + @Override + public boolean checkrotor() { + return !this.rotorSlot.isEmpty(); + } - setRotationSpeed(speed*2); - if (this.windStrength >= getMinWindStrength()) { - if (this.windStrength <= getMaxWindStrength()) { - this.rotorSlot.damage(1, false); - } else { - this.rotorSlot.damage(4, false); - } - } + @Override + public int checkSpace(int length, final boolean onlyrotor) { + int box = this.getRotorDiameter() / 2; + int lentemp = 0; + if (onlyrotor) { + length = 1; + lentemp = length + 1; } - } + if (!onlyrotor) { + box *= 2; + } + 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); - @Override - public List<String> getNetworkedFields() - { - List<String> ret = new Vector<String>(1); + 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); - ret.add("rotationSpeed"); - ret.add("rotorSlot"); - ret.addAll(super.getNetworkedFields()); + 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; + + final int z = this.zCoord + fwd * fwdDir.offsetZ + right * rightDir.offsetZ; + + 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++; + } + } + } return ret; } - @Override - public ContainerBase<TileEntityWindKineticGenerator> getGuiContainer(EntityPlayer entityPlayer) - { - return new ContainerWindKineticGenerator(entityPlayer, this); + public boolean enableUpdateEntity() { + return IC2.platform.isSimulating(); } @Override - @SideOnly(Side.CLIENT) - public GuiScreen getGui(EntityPlayer entityPlayer, boolean isAdmin) - { - return new GuiWindKineticGenerator(new ContainerWindKineticGenerator(entityPlayer, this)); + public boolean facingMatchesDirection(final ForgeDirection direction) { + return direction.ordinal() == this.getFacing(); } @Override - public boolean facingMatchesDirection(ForgeDirection direction) - { - return direction.ordinal() == getFacing(); - } + public float getAngle() { + if (this.rotationSpeed > 0.0F) { + final long period = (long) (5.0E+008F / this.rotationSpeed); - @Override - public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) - { - if ((side == 0) || (side == 1)) { - return false; + return (float) (System.nanoTime() % period) / (float) period * 360.0F; } - return getFacing() != side; + return 0.0F; } @Override - public void setFacing(short side) - { - super.setFacing(side); + 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 boolean enableUpdateEntity() - { - return IC2.platform.isSimulating(); + @Override + @SideOnly(Side.CLIENT) + public GuiScreen getGui(final EntityPlayer entityPlayer, final boolean isAdmin) { + return new GuiWindKineticGenerator(new ContainerWindKineticGenerator(entityPlayer, this)); } @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 ContainerBase<TileEntityWindKineticGenerator> getGuiContainer(final EntityPlayer entityPlayer) { + return new ContainerWindKineticGenerator(entityPlayer, this); } @Override - public int maxrequestkineticenergyTick(ForgeDirection directionFrom) - { - return getKuOutput(); + public String getInventoryName() { + return "Advanced Kinetic Wind Generator"; } @Override - public int requestkineticenergy(ForgeDirection directionFrom, int requestkineticenergy) - { - if (facingMatchesDirection(directionFrom.getOpposite())) { - return Math.min(requestkineticenergy, getKuOutput()); + public int getKuOutput() { + if (this.windStrength >= this.getMinWindStrength() && this.getActive()) { + return (int) (this.windStrength * 50.0D * this.getefficiency()); } return 0; } @Override - public String getInventoryName() - { - return "Advanced Kinetic Wind Generator"; + public int getMaxWindStrength() { + final ItemStack stack = this.rotorSlot.get(); + if (stack != null && stack.getItem() instanceof IKineticRotor) { + return ((IKineticRotor) stack.getItem()).getMaxWindStrength(stack) * 2; + } + return 0; } @Override - public void onGuiClosed(EntityPlayer entityPlayer) {} - - @Override - public boolean shouldRenderInPass(int pass) - { - return pass == 0; + public int getMinWindStrength() { + final ItemStack stack = this.rotorSlot.get(); + if (stack != null && stack.getItem() instanceof IKineticRotor) { + return ((IKineticRotor) stack.getItem()).getMinWindStrength(stack) / 2; + } + return 0; } @Override - public int checkSpace(int length, boolean onlyrotor) - { - int box = getRotorDiameter() / 2; - int lentemp = 0; - if (onlyrotor) - { - length = 1; - lentemp = length + 1; - } - if (!onlyrotor) { - box *= 2; - } - ForgeDirection fwdDir = ForgeDirection.VALID_DIRECTIONS[getFacing()]; - ForgeDirection rightDir = fwdDir.getRotation(ForgeDirection.DOWN); + public List<String> getNetworkedFields() { + final List<String> ret = new Vector<String>(1); - 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); + ret.add("rotationSpeed"); + ret.add("rotorSlot"); + ret.addAll(super.getNetworkedFields()); - 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 boolean checkrotor() - { - return !this.rotorSlot.isEmpty(); + public int getRotorDiameter() { + final ItemStack stack = this.rotorSlot.get(); + if (stack != null && stack.getItem() instanceof IKineticRotor) { + return ((IKineticRotor) stack.getItem()).getDiameter(stack) / 2; + } + return 0; } @Override - public boolean rotorspace() - { - return checkSpace(1, true) == 0; + 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 ""; } - private void setRotationSpeed(float speed) - { - if (this.rotationSpeed != speed) - { - this.rotationSpeed = speed; - ((NetworkManager)IC2.network.get()).updateTileEntityField(this, "rotationSpeed"); + @Override + public ResourceLocation getRotorRenderTexture() { + final 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"); } @Override - public int getTickRate() - { + public int getTickRate() { return 32; } @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); + public int getWindStrength() { + return (int) this.windStrength; } @Override - 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 0.0F; + public boolean guiisminWindStrength() { + return this.windStrength >= this.getMinWindStrength(); } @Override - public float getefficiency() - { - ItemStack stack = this.rotorSlot.get(); - if ((stack != null) && ((stack.getItem() instanceof IKineticRotor))) { - return (float) (((IKineticRotor)stack.getItem()).getEfficiency(stack)*1.5); + public boolean guiisoverload() { + if (this.windStrength > this.getMaxWindStrength()) { + return true; } - return 0.0F; + return false; } @Override - public int getMinWindStrength() - { - ItemStack stack = this.rotorSlot.get(); - if ((stack != null) && ((stack.getItem() instanceof IKineticRotor))) { - return ((IKineticRotor)stack.getItem()).getMinWindStrength(stack)/2; - } - return 0; + public int maxrequestkineticenergyTick(final ForgeDirection directionFrom) { + return this.getKuOutput(); } @Override - public int getMaxWindStrength() - { - ItemStack stack = this.rotorSlot.get(); - if ((stack != null) && ((stack.getItem() instanceof IKineticRotor))) { - return ((IKineticRotor)stack.getItem()).getMaxWindStrength(stack)*2; - } - return 0; + public void onGuiClosed(final EntityPlayer entityPlayer) { } @Override - public int getRotorDiameter() - { - ItemStack stack = this.rotorSlot.get(); - if ((stack != null) && ((stack.getItem() instanceof IKineticRotor))) { - return ((IKineticRotor)stack.getItem()).getDiameter(stack)/2; + public int requestkineticenergy(final ForgeDirection directionFrom, final int requestkineticenergy) { + if (this.facingMatchesDirection(directionFrom.getOpposite())) { + return Math.min(requestkineticenergy, this.getKuOutput()); } return 0; } @Override - 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"); + public boolean rotorspace() { + return this.checkSpace(1, true) == 0; } @Override - public boolean guiisoverload() - { - if (this.windStrength > getMaxWindStrength()) { - return true; + public void setFacing(final short side) { + super.setFacing(side); + } + + private void setRotationSpeed(final float speed) { + if (this.rotationSpeed != speed) { + this.rotationSpeed = speed; + IC2.network.get().updateTileEntityField(this, "rotationSpeed"); } - return false; } @Override - public boolean guiisminWindStrength() - { - return this.windStrength >= getMinWindStrength(); + public boolean shouldRenderInPass(final int pass) { + return pass == 0; } - @Override - public int getKuOutput() - { - if ((this.windStrength >= getMinWindStrength()) && (getActive())) { - return (int)(this.windStrength * 50.0D * getefficiency()); + 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); + } + } } - return 0; } @Override - public int getWindStrength() - { - return (int)this.windStrength; + public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final int side) { + if (side == 0 || side == 1) { + return false; + } + return this.getFacing() != side; } } |