diff options
author | Draknyte1 <Draknyte1@hotmail.com> | 2016-09-07 16:36:25 +1000 |
---|---|---|
committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-09-07 16:36:25 +1000 |
commit | 221c2f0fe81430e7dd4087e5f5845bd7c62ec56d (patch) | |
tree | d6e0faaef01b9d517828557e1be82500d476f95e /src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator | |
parent | 5872c0947ce7bc788b03fa2fb690b8815d3d0a04 (diff) | |
download | GT5-Unofficial-221c2f0fe81430e7dd4087e5f5845bd7c62ec56d.tar.gz GT5-Unofficial-221c2f0fe81430e7dd4087e5f5845bd7c62ec56d.tar.bz2 GT5-Unofficial-221c2f0fe81430e7dd4087e5f5845bd7c62ec56d.zip |
% Refactored the entire project to stop using MiscUtils everywhere possible, now it's gtPlusPlus.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator')
6 files changed, 624 insertions, 0 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 new file mode 100644 index 0000000000..74d94011ea --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/IC2_BlockKineticGenerator.java @@ -0,0 +1,76 @@ +package gtPlusPlus.xmod.ic2.block.kieticgenerator; + +import gtPlusPlus.core.creative.AddToCreativeTab; +import ic2.core.block.BlockMultiID; +import ic2.core.block.kineticgenerator.tileentity.TileEntityManualKineticGenerator; +import ic2.core.block.kineticgenerator.tileentity.TileEntityWindKineticGenerator; +import ic2.core.init.InternalName; +import ic2.core.item.block.ItemKineticGenerator; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import org.apache.commons.lang3.mutable.MutableObject; + +import cpw.mods.fml.common.registry.GameRegistry; + +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); + } +} diff --git a/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/IC2_TEComponent.java b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/IC2_TEComponent.java new file mode 100644 index 0000000000..f356441921 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/IC2_TEComponent.java @@ -0,0 +1,48 @@ +package gtPlusPlus.xmod.ic2.block.kieticgenerator; + +import ic2.core.block.TileEntityBlock; + +import java.io.DataInput; +import java.io.IOException; + +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() {} +} diff --git a/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/container/ContainerKineticWindgenerator.java b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/container/ContainerKineticWindgenerator.java new file mode 100644 index 0000000000..b3ceea52d4 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/container/ContainerKineticWindgenerator.java @@ -0,0 +1,27 @@ +package gtPlusPlus.xmod.ic2.block.kieticgenerator.container; + +import ic2.core.ContainerFullInv; +import ic2.core.block.kineticgenerator.tileentity.TileEntityWindKineticGenerator; +import ic2.core.slot.SlotInvSlot; + +import java.util.List; + +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; + } +} diff --git a/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/container/IC2_ContainerBase.java b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/container/IC2_ContainerBase.java new file mode 100644 index 0000000000..740991c5d3 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/container/IC2_ContainerBase.java @@ -0,0 +1,5 @@ +package gtPlusPlus.xmod.ic2.block.kieticgenerator.container; + +public class IC2_ContainerBase { + +} diff --git a/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/gui/GuiKineticWindGenerator.java b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/gui/GuiKineticWindGenerator.java new file mode 100644 index 0000000000..f677e7fcfb --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/gui/GuiKineticWindGenerator.java @@ -0,0 +1,76 @@ +package gtPlusPlus.xmod.ic2.block.kieticgenerator.gui; + +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; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@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"); +} diff --git a/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/tileentity/TileEntityKineticWindGenerator.java b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/tileentity/TileEntityKineticWindGenerator.java new file mode 100644 index 0000000000..f094c8f928 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/ic2/block/kieticgenerator/tileentity/TileEntityKineticWindGenerator.java @@ -0,0 +1,392 @@ +package gtPlusPlus.xmod.ic2.block.kieticgenerator.tileentity; + +import ic2.api.energy.tile.IKineticSource; +import ic2.api.item.IKineticRotor; +import ic2.api.item.IKineticRotor.GearboxType; +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; +import net.minecraft.item.ItemStack; +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 +{ + 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); + } + + + 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); + + 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(); + + float speed = (float)Util.limit((this.windStrength - getMinWindStrength()) / getMaxWindStrength(), 0.0D, 2.0D); + + + setRotationSpeed(speed*2); + if (this.windStrength >= getMinWindStrength()) { + if (this.windStrength <= getMaxWindStrength()) { + this.rotorSlot.damage(1, false); + } else { + this.rotorSlot.damage(4, false); + } + } + } + } + + + + @Override + public List<String> getNetworkedFields() + { + List<String> ret = new Vector<String>(1); + + ret.add("rotationSpeed"); + ret.add("rotorSlot"); + ret.addAll(super.getNetworkedFields()); + + return ret; + } + + @Override + public ContainerBase<TileEntityWindKineticGenerator> getGuiContainer(EntityPlayer entityPlayer) + { + return new ContainerWindKineticGenerator(entityPlayer, this); + } + + @Override + @SideOnly(Side.CLIENT) + public GuiScreen getGui(EntityPlayer entityPlayer, boolean isAdmin) + { + return new GuiWindKineticGenerator(new ContainerWindKineticGenerator(entityPlayer, this)); + } + + @Override + public boolean facingMatchesDirection(ForgeDirection direction) + { + return direction.ordinal() == getFacing(); + } + + @Override + public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) + { + if ((side == 0) || (side == 1)) { + return false; + } + return getFacing() != side; + } + + @Override + public void setFacing(short side) + { + super.setFacing(side); + } + + public boolean enableUpdateEntity() + { + return IC2.platform.isSimulating(); + } + + @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 ""; + } + + @Override + 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 String getInventoryName() + { + return "Advanced Kinetic Wind Generator"; + } + + @Override + public void onGuiClosed(EntityPlayer entityPlayer) {} + + @Override + public boolean shouldRenderInPass(int pass) + { + return pass == 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); + + 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 boolean checkrotor() + { + return !this.rotorSlot.isEmpty(); + } + + @Override + 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"); + } + } + + @Override + 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); + } + + @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; + } + + @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); + } + return 0.0F; + } + + @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; + } + + @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; + } + + @Override + 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 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"); + } + + @Override + public boolean guiisoverload() + { + if (this.windStrength > getMaxWindStrength()) { + return true; + } + return false; + } + + @Override + public boolean guiisminWindStrength() + { + return this.windStrength >= getMinWindStrength(); + } + + @Override + public int getKuOutput() + { + if ((this.windStrength >= getMinWindStrength()) && (getActive())) { + return (int)(this.windStrength * 50.0D * getefficiency()); + } + return 0; + } + + @Override + public int getWindStrength() + { + return (int)this.windStrength; + } +} |