summaryrefslogtreecommitdiff
path: root/ihl/crop_harvestors
diff options
context:
space:
mode:
authorFoghrye4 <foghrye4@gmail.com>2016-04-11 19:44:54 +0300
committerFoghrye4 <foghrye4@gmail.com>2016-04-11 19:44:54 +0300
commit05c78126859231a68e199dc34613689bd0978e2f (patch)
tree050bea104a18c72905095d29f31bec2935a27a24 /ihl/crop_harvestors
Initial commit
Diffstat (limited to 'ihl/crop_harvestors')
-rw-r--r--ihl/crop_harvestors/BlobEntityFX.java84
-rw-r--r--ihl/crop_harvestors/BlobRenderFX.java63
-rw-r--r--ihl/crop_harvestors/BlowerBlock.java170
-rw-r--r--ihl/crop_harvestors/BlowerContainer.java89
-rw-r--r--ihl/crop_harvestors/BlowerGui.java66
-rw-r--r--ihl/crop_harvestors/BlowerTileEntity.java1074
-rw-r--r--ihl/crop_harvestors/RubberTreeBlock.java167
-rw-r--r--ihl/crop_harvestors/SackBlock.java167
-rw-r--r--ihl/crop_harvestors/SackModel.java103
-rw-r--r--ihl/crop_harvestors/SackRender.java95
-rw-r--r--ihl/crop_harvestors/SackTileEntity.java569
11 files changed, 2647 insertions, 0 deletions
diff --git a/ihl/crop_harvestors/BlobEntityFX.java b/ihl/crop_harvestors/BlobEntityFX.java
new file mode 100644
index 0000000..60a3ad9
--- /dev/null
+++ b/ihl/crop_harvestors/BlobEntityFX.java
@@ -0,0 +1,84 @@
+package ihl.crop_harvestors;
+
+import net.minecraft.client.particle.EntityFX;
+import net.minecraft.client.renderer.Tessellator;
+import net.minecraft.world.World;
+
+public class BlobEntityFX extends EntityFX {
+
+ public FluidType fluid = FluidType.RESIN;
+
+ public BlobEntityFX(World world, double x, double y, double z)
+ {
+ super(world, x, y, z);
+ this.noClip = true;
+ }
+
+ public BlobEntityFX(World par1World, double par2, double par4, double par6, double par8, double par10, double par12, float par14, FluidType fluid1)
+ {
+ super(par1World, par2, par4, par6, 0.0D, 0.0D, 0.0D);
+ this.motionX *= 0.1D;
+ this.motionY *= 0.1D;
+ this.motionZ *= 0.1D;
+ this.motionX += par8;
+ this.motionY += par10;
+ this.motionZ += par12;
+ this.particleScale *= par14;
+ this.particleMaxAge = (int)(8.0D / (Math.random() * 0.8D + 0.2D));
+ this.noClip = true;
+ fluid=fluid1;
+ }
+
+ @Override
+ public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7)
+ {
+ float var8 = ((float)this.particleAge) / (float)this.particleMaxAge * 32.0F;
+
+ if (var8 < 0.0F)
+ {
+ var8 = 0.0F;
+ }
+
+ if (var8 > 1.0F)
+ {
+ var8 = 1.0F;
+ }
+ this.renderParticle2(par1Tessellator, par2, par3, par4, par5, par6, par7);
+ }
+
+ public void renderParticle2(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7)
+ {
+ float var12 = 0.1F * this.particleScale;
+ float var13 = (float)(this.prevPosX + (this.posX - this.prevPosX) * par2 - interpPosX);
+ float var14 = (float)(this.prevPosY + (this.posY - this.prevPosY) * par2 - interpPosY);
+ float var15 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * par2 - interpPosZ);
+ par1Tessellator.addVertexWithUV(var13 - par3 * var12 - par6 * var12, var14 - par4 * var12, var15 - par5 * var12 - par7 * var12, 1D, 1D);
+ par1Tessellator.addVertexWithUV(var13 - par3 * var12 + par6 * var12, var14 + par4 * var12, var15 - par5 * var12 + par7 * var12, 1D, 0D);
+ par1Tessellator.addVertexWithUV(var13 + par3 * var12 + par6 * var12, var14 + par4 * var12, var15 + par5 * var12 + par7 * var12, 0D, 0D);
+ par1Tessellator.addVertexWithUV(var13 + par3 * var12 - par6 * var12, var14 - par4 * var12, var15 + par5 * var12 - par7 * var12, 0D, 1D);
+ }
+
+ @Override
+ public void onUpdate()
+ {
+ this.prevPosX = this.posX;
+ this.prevPosY = this.posY;
+ this.prevPosZ = this.posZ;
+
+ if (this.particleAge++ >= this.particleMaxAge)
+ {
+ this.setDead();
+ }
+ this.motionX *= 0.5D;
+ this.motionZ *= 0.5D;
+ this.moveEntity(this.motionX, this.motionY, this.motionZ);
+ this.motionY -= 0.001D;
+ this.motionY *= 0.96D;
+ }
+
+ public enum FluidType
+ {
+ SAP,
+ RESIN
+ }
+}
diff --git a/ihl/crop_harvestors/BlobRenderFX.java b/ihl/crop_harvestors/BlobRenderFX.java
new file mode 100644
index 0000000..21fe3a3
--- /dev/null
+++ b/ihl/crop_harvestors/BlobRenderFX.java
@@ -0,0 +1,63 @@
+package ihl.crop_harvestors;
+
+import ihl.IHLModInfo;
+import net.minecraft.client.particle.EntityFX;
+import net.minecraft.client.renderer.ActiveRenderInfo;
+import net.minecraft.client.renderer.Tessellator;
+import net.minecraft.client.renderer.entity.Render;
+import net.minecraft.entity.Entity;
+import net.minecraft.util.ResourceLocation;
+import org.lwjgl.opengl.GL11;
+
+public class BlobRenderFX extends Render{
+ private ResourceLocation tex, tex2;
+
+public BlobRenderFX()
+{
+ super();
+ tex = new ResourceLocation(IHLModInfo.MODID+":textures/particles/blob.png");
+ tex2 = new ResourceLocation(IHLModInfo.MODID+":textures/particles/blobOfResin.png");
+}
+
+@Override
+public void doRender(Entity entity, double x, double y, double z,
+ float arg4, float arg5)
+{
+ float var3 = ActiveRenderInfo.rotationX;
+ float var4 = ActiveRenderInfo.rotationZ;
+ float var5 = ActiveRenderInfo.rotationYZ;
+ float var6 = ActiveRenderInfo.rotationXY;
+ float var7 = ActiveRenderInfo.rotationXZ;
+ EntityFX.interpPosX = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * arg4;
+ EntityFX.interpPosY = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * arg4;
+ EntityFX.interpPosZ = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * arg4;
+ if(((BlobEntityFX)entity).fluid==BlobEntityFX.FluidType.RESIN)
+ {
+ this.renderManager.renderEngine.bindTexture(tex);
+ }
+ else
+ {
+ this.renderManager.renderEngine.bindTexture(tex2);
+ }
+ GL11.glPushMatrix();
+ GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
+ GL11.glTranslatef((float)x, (float)y, (float)z);
+ GL11.glEnable(GL11.GL_BLEND);
+ GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
+ GL11.glAlphaFunc(GL11.GL_GREATER, 0.003921569F);
+ Tessellator var9 = Tessellator.instance;
+ var9.startDrawingQuads();
+ EntityFX var11 = (EntityFX) entity;
+ var11.renderParticle(var9, arg4, var3, var7, var4, var5, var6);
+ var9.draw();
+ GL11.glDisable(GL11.GL_BLEND);
+ GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
+ GL11.glPopMatrix();
+}
+
+ @Override
+ protected ResourceLocation getEntityTexture(Entity arg0)
+ {
+ return tex;
+ }
+} \ No newline at end of file
diff --git a/ihl/crop_harvestors/BlowerBlock.java b/ihl/crop_harvestors/BlowerBlock.java
new file mode 100644
index 0000000..9d4c782
--- /dev/null
+++ b/ihl/crop_harvestors/BlowerBlock.java
@@ -0,0 +1,170 @@
+package ihl.crop_harvestors;
+
+import java.util.Random;
+
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import ic2.api.item.IC2Items;
+import ihl.IHLCreativeTab;
+import ihl.IHLModInfo;
+import ihl.utils.IHLUtils;
+import net.minecraft.block.Block;
+import net.minecraft.block.ITileEntityProvider;
+import net.minecraft.block.material.Material;
+import net.minecraft.client.renderer.texture.IIconRegister;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.IIcon;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+
+public class BlowerBlock extends Block implements ITileEntityProvider{
+
+ IIcon textureLeft, textureRight, textureBack;
+
+ public BlowerBlock(Material material)
+ {
+ super(material);
+ this.setCreativeTab(IHLCreativeTab.tab);
+ }
+
+ @Override
+ public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
+ {
+ return IC2Items.getItem("machine").getItem();
+ }
+
+ @Override
+ public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
+ {
+ TileEntity te = world.getTileEntity(x,y,z);
+ if(te instanceof BlowerTileEntity)
+ {
+ BlowerTileEntity bte = (BlowerTileEntity)te;
+ bte.updateChecksum=-1;
+ }
+ }
+
+ @Override
+ public void dropBlockAsItemWithChance(World world, int x, int y, int z, int meta, float chance, int flag)
+ {
+ }
+
+ @Override
+ public TileEntity createNewTileEntity(World world, int var2) {
+ return new BlowerTileEntity();
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public void registerBlockIcons(IIconRegister par1IconRegister)
+ {
+ this.blockIcon = par1IconRegister.registerIcon(IHLModInfo.MODID + ":blowerFront");
+ this.textureBack = par1IconRegister.registerIcon(IHLModInfo.MODID + ":blowerBack");
+ this.textureLeft = par1IconRegister.registerIcon(IHLModInfo.MODID + ":blowerLeft");
+ this.textureRight = par1IconRegister.registerIcon(IHLModInfo.MODID + ":blowerRight");
+ }
+
+ @Override
+ public boolean hasTileEntity(int metadata)
+ {
+ return true;
+ }
+
+ @Override
+ public boolean onBlockActivated(World world,int x,int y,int z,EntityPlayer entityPlayer,int i,float pos_x,float pos_y,float pos_z){
+ TileEntity te = world.getTileEntity(x,y,z);
+ if(te instanceof BlowerTileEntity)
+ {
+ BlowerTileEntity bte = (BlowerTileEntity)te;
+ if (bte == null || entityPlayer.isSneaking()) {
+ return false;
+ }
+ else
+ {
+ return bte.getGui(entityPlayer);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Called when the block is placed in the world.
+ */
+ @Override
+ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack)
+ {
+ TileEntity t = world.getTileEntity(x, y, z);
+ if(t!=null && t instanceof BlowerTileEntity)
+ {
+ ((BlowerTileEntity)t).setFacing(IHLUtils.getFacingFromPlayerView(player, false));
+ }
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side)
+ {
+ int facing=3;
+ int mask[] = {
+ 0,1,2,3,4,5,
+ 1,0,3,2,4,5,
+ 3,2,0,1,4,5,
+ 2,3,1,0,4,5,
+ 2,3,5,4,0,1,
+ 2,3,4,5,1,0
+ };
+ TileEntity te = world.getTileEntity(x, y, z);
+ if(te!=null)
+ {
+ BlowerTileEntity tebh = (BlowerTileEntity) te;
+ facing=tebh.getFacing();
+ }
+
+ switch (mask[facing*6+side])
+ {
+ case 0:
+ return this.blockIcon;
+ case 1:
+ return this.textureBack;
+ case 2:
+ return this.textureBack;
+ case 3:
+ return this.textureBack;
+ case 4:
+ return this.textureLeft;
+ case 5:
+ return this.textureRight;
+ default:
+ return this.textureLeft;
+ }
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public IIcon getIcon(int side, int meta)
+ {
+ IIcon sideIcon = this.blockIcon;
+ switch (side)
+ {
+ case 0:
+ return this.blockIcon;
+ case 1:
+ return this.textureBack;
+ case 2:
+ return this.textureLeft;
+ case 3:
+ return this.textureRight;
+ case 4:
+ return this.textureBack;
+ case 5:
+ return this.textureBack;
+ default:
+ return this.textureLeft;
+ }
+ }
+
+}
diff --git a/ihl/crop_harvestors/BlowerContainer.java b/ihl/crop_harvestors/BlowerContainer.java
new file mode 100644
index 0000000..65393bf
--- /dev/null
+++ b/ihl/crop_harvestors/BlowerContainer.java
@@ -0,0 +1,89 @@
+package ihl.crop_harvestors;
+
+import ic2.core.ContainerBase;
+import ic2.core.slot.SlotInvSlot;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.ICrafting;
+import net.minecraft.inventory.Slot;
+
+public class BlowerContainer extends ContainerBase {
+
+ protected BlowerTileEntity tileEntity;
+ public int lastStorage = -1;
+ public int lastAirSpeed = -1;
+ private final static int height=166;
+
+ public BlowerContainer(EntityPlayer entityPlayer, BlowerTileEntity tileEntity1){
+ super(tileEntity1);
+ this.tileEntity = tileEntity1;
+ int col;
+
+ for (col = 0; col < 3; ++col)
+ {
+ for (int col1 = 0; col1 < 9; ++col1)
+ {
+ this.addSlotToContainer(new Slot(entityPlayer.inventory, col1 + col * 9 + 9, 8 + col1 * 18, height + -82 + col * 18));
+ }
+ }
+
+ for (col = 0; col < 9; ++col)
+ {
+ this.addSlotToContainer(new Slot(entityPlayer.inventory, col, 8 + col * 18, height + -24));
+ }
+
+ this.addSlotToContainer(new SlotInvSlot(tileEntity1.dischargeSlot, 0, 26, 26));
+ for(int row=0;row<=3;row++)
+ {
+ this.addSlotToContainer(new SlotInvSlot(tileEntity1.upgradeSlot, row, 152, 8+row*18));
+ }
+ }
+
+ @Override
+ public void detectAndSendChanges()
+ {
+ super.detectAndSendChanges();
+ for (int i = 0; i < this.crafters.size(); ++i)
+ {
+ ICrafting icrafting = (ICrafting)this.crafters.get(i);
+
+ if (this.tileEntity.getStored() != this.lastStorage)
+ {
+ icrafting.sendProgressBarUpdate(this, 0, (this.tileEntity.getStored()>>15) & Short.MAX_VALUE);
+ icrafting.sendProgressBarUpdate(this, 1, (short)(this.tileEntity.getStored() & Short.MAX_VALUE));
+
+ }
+
+ if (this.tileEntity.airSpeedBase != this.lastAirSpeed)
+ {
+ icrafting.sendProgressBarUpdate(this, 2, this.tileEntity.airSpeedBase);
+ }
+ }
+
+ this.lastStorage = this.tileEntity.getStored();
+ this.lastAirSpeed = this.tileEntity.airSpeedBase;
+ }
+
+ @Override
+ public void updateProgressBar(int index, int value)
+ {
+ super.updateProgressBar(index, value);
+
+ switch (index)
+ {
+ case 0:
+ this.tileEntity.setStored(value<<15);
+ break;
+ case 1:
+ this.tileEntity.setStored(this.tileEntity.getStored()+value);
+ break;
+ case 2:
+ this.tileEntity.airSpeedBase=value;
+ break;
+ }
+ }
+
+ @Override
+ public boolean canInteractWith(EntityPlayer var1) {
+ return tileEntity.isUseableByPlayer(var1);
+ }
+}
diff --git a/ihl/crop_harvestors/BlowerGui.java b/ihl/crop_harvestors/BlowerGui.java
new file mode 100644
index 0000000..f74ac51
--- /dev/null
+++ b/ihl/crop_harvestors/BlowerGui.java
@@ -0,0 +1,66 @@
+package ihl.crop_harvestors;
+
+import cpw.mods.fml.relauncher.Side;
+
+import cpw.mods.fml.relauncher.SideOnly;
+import net.minecraft.client.gui.inventory.GuiContainer;
+import net.minecraft.util.ResourceLocation;
+import net.minecraft.util.StatCollector;
+
+import org.lwjgl.opengl.GL11;
+
+@SideOnly(Side.CLIENT)
+public class BlowerGui extends GuiContainer {
+ private static final ResourceLocation background = new ResourceLocation("ihl", "textures/gui/GUIBlower.png");
+ private BlowerContainer container;
+
+ public BlowerGui (BlowerContainer container1) {
+ //the container is instanciated and passed to the superclass for handling
+ super(container1);
+ this.container=container1;
+ }
+
+ @Override
+ public void initGui()
+ {
+ super.initGui();
+ int x = (width - xSize) / 2;
+ int y = (height - ySize) / 2;
+ }
+
+ @Override
+ protected void drawGuiContainerForegroundLayer(int param1, int param2) {
+ //the parameters for drawString are: string, x, y, color
+ String title = StatCollector.translateToLocal("tile.blowerBlock.name");
+ fontRendererObj.drawStringWithShadow(title, 8, 8, 16767839);
+ String airspeed = StatCollector.translateToLocal("ihl.gui.blower");
+ String units = StatCollector.translateToLocal("ihl.gui.blowerUnits");
+ fontRendererObj.drawString(airspeed, 8, 60, 852037);
+ float e = container.tileEntity.getActive()?container.tileEntity.airSpeedBase/10F:0F;
+ String eStr = String.valueOf(e);
+ int w = this.fontRendererObj.getStringWidth(eStr);
+ fontRendererObj.drawString(eStr, 60-w, 71, 16767839);
+ fontRendererObj.drawString(units, 62, 71, 852037);
+ GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
+ this.mc.renderEngine.bindTexture(background);
+ //charge
+ if (this.container.tileEntity.getStored() > 0)
+ {
+ int chargeLevel=Math.min(Math.round(this.container.tileEntity.getStored()*13.0F/this.container.tileEntity.maxStorage),13);
+ this.drawTexturedModalRect(11, 28+13-chargeLevel, xSize, 13-chargeLevel, 7, chargeLevel);
+ }
+
+
+ }
+
+ @Override
+ protected void drawGuiContainerBackgroundLayer(float par1, int par2,
+ int par3) {
+ //draw your Gui here, only thing you need to change is the path
+ GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
+ this.mc.renderEngine.bindTexture(background);
+ int x = (width - xSize) / 2;
+ int y = (height - ySize) / 2;
+ this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
+ }
+} \ No newline at end of file
diff --git a/ihl/crop_harvestors/BlowerTileEntity.java b/ihl/crop_harvestors/BlowerTileEntity.java
new file mode 100644
index 0000000..1c06f6c
--- /dev/null
+++ b/ihl/crop_harvestors/BlowerTileEntity.java
@@ -0,0 +1,1074 @@
+package ihl.crop_harvestors;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+import java.util.Set;
+
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+
+import net.minecraft.block.Block;
+import net.minecraft.client.gui.GuiScreen;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.item.EntityItem;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.AxisAlignedBB;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.common.util.ForgeDirection;
+import ic2.api.energy.event.EnergyTileLoadEvent;
+import ic2.api.energy.event.EnergyTileUnloadEvent;
+import ic2.api.energy.tile.IEnergySink;
+import ic2.api.item.IC2Items;
+import ic2.core.ContainerBase;
+import ic2.core.IC2;
+import ic2.core.IHasGui;
+import ic2.core.audio.AudioSource;
+import ic2.core.audio.PositionSpec;
+import ic2.core.block.TileEntityInventory;
+import ic2.core.block.invslot.InvSlot;
+import ic2.core.block.invslot.InvSlotUpgrade;
+import ic2.core.block.invslot.InvSlot.Access;
+import ic2.core.network.NetworkManager;
+import ic2.core.upgrade.IUpgradableBlock;
+import ic2.core.upgrade.UpgradableProperty;
+import ihl.IHLMod;
+import ihl.utils.IHLInvSlotDischarge;
+
+public class BlowerTileEntity extends TileEntityInventory implements IEnergySink, IHasGui, IUpgradableBlock
+{
+ private int startUpCounter=0;
+ private int tier=1;
+ private int defaultTier=1;
+ public int maxStorage=100;
+ private int defaultMaxStorage=100;
+ private double energy=0D;
+ private double defaultEnergyConsume=5D;
+ private double energyConsume=5D;
+ private int defaultAirSpeedBase=100;
+ public int airSpeedBase=100;
+ private boolean shouldCalculateAirFlow=true;
+ private int sCAFCount=0;
+ public boolean addedToEnergyNet = false;
+ private boolean hasEntityInFlow=false;
+ private ArrayList<AirSpeedZone> aszlist = new ArrayList();
+ public final InvSlotUpgrade upgradeSlot;
+ public final IHLInvSlotDischarge dischargeSlot;
+ public int updateChecksum=-1;
+ private final float lambda=0.00001F;
+ private Random rand = new Random();
+ public int operationRange=-1;
+ public int lastOperationRange=0;
+
+ private AudioSource startAS;
+ private AudioSource loopAS;
+ private AudioSource stopAS;
+
+ public BlowerTileEntity()
+ {
+ this.defaultTier=IHLMod.config.blowerTier;
+ this.defaultMaxStorage=IHLMod.config.blowerMaxEnergyStorage;
+ this.defaultEnergyConsume=IHLMod.config.blowerEnergyConsumePerTick;
+ this.upgradeSlot = new InvSlotUpgrade(this, "upgrade", 2, 4);
+ this.dischargeSlot = new IHLInvSlotDischarge(this, 1, Access.IO, this.tier, InvSlot.InvSide.BOTTOM);
+ }
+
+ @Override
+ public List<String> getNetworkedFields()
+ {
+ List<String> fields = super.getNetworkedFields();
+ fields.add("tier");
+ fields.add("airSpeedBase");
+ fields.add("maxStorage");
+ return fields;
+ }
+
+ @Override
+ public void readFromNBT(NBTTagCompound nbttagcompound)
+ {
+ super.readFromNBT(nbttagcompound);
+ try
+ {
+ this.energy = nbttagcompound.getDouble("energy");
+ }
+ catch (Exception var3)
+ {
+ this.energy = nbttagcompound.getInteger("energy");
+
+ if (this.maxStorage > Integer.MAX_VALUE)
+ {
+ this.energy *= 10.0D;
+ }
+ }
+ }
+
+ @Override
+ public void writeToNBT(NBTTagCompound nbttagcompound)
+ {
+ super.writeToNBT(nbttagcompound);
+ nbttagcompound.setDouble("energy", this.energy);
+ }
+
+ @Override
+ public void onLoaded()
+ {
+ super.onLoaded();
+ if (IC2.platform.isSimulating())
+ {
+ MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
+ this.addedToEnergyNet = true;
+ }
+ if (IC2.platform.isRendering() && (this.startAS==null||this.loopAS==null||this.stopAS==null))
+ {
+ this.startAS = IC2.audioManager.createSource(this, PositionSpec.Center, this.getStartSoundFile(),false,false, 1F);
+ this.loopAS = IC2.audioManager.createSource(this, PositionSpec.Center, this.getLoopSoundFile(),true,false, 1F);
+ this.stopAS = IC2.audioManager.createSource(this, PositionSpec.Center, this.getStopSoundFile(),false,false, 1F);
+ }
+ }
+
+ @Override
+ public void onUnloaded()
+ {
+ if (IC2.platform.isRendering() && this.loopAS != null)
+ {
+ this.startAS.stop();
+ this.loopAS.stop();
+ this.stopAS.stop();
+ this.startAS = null;
+ this.loopAS = null;
+ this.stopAS = null;
+ IC2.audioManager.removeSources(this);
+ }
+
+ if (IC2.platform.isSimulating() && this.addedToEnergyNet)
+ {
+ MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
+ this.addedToEnergyNet = false;
+ }
+ super.onUnloaded();
+ }
+
+ @Override
+ public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
+ return this.getFacing()!=(short)side;
+ }
+
+ @Override
+ public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
+ if(this.dischargeSlot.get()!=null)this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.xCoord, this.yCoord+1, this.zCoord, this.dischargeSlot.get()));
+ if(this.upgradeSlot.get(0)!=null)this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.xCoord, this.yCoord+1, this.zCoord, this.upgradeSlot.get(0)));
+ if(this.upgradeSlot.get(1)!=null)this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.xCoord, this.yCoord+1, this.zCoord, this.upgradeSlot.get(1)));
+ if(this.upgradeSlot.get(2)!=null)this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.xCoord, this.yCoord+1, this.zCoord, this.upgradeSlot.get(2)));
+ if(this.upgradeSlot.get(3)!=null)this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.xCoord, this.yCoord+1, this.zCoord, this.upgradeSlot.get(3)));
+ return new ItemStack(IHLMod.blowerBlock,1);
+ }
+
+ @Override
+ public void setFacing(short facing1)
+ {
+ super.setFacing(facing1);
+ this.updateChecksum=-1;
+ }
+
+ public boolean enableUpdateEntity()
+ {
+ return true;
+ }
+
+ public String getStartSoundFile()
+ {
+ return "Machines/IHL Industrial Fan/start.ogg";
+ }
+
+ public String getLoopSoundFile()
+ {
+ return "Machines/IHL Industrial Fan/loop.ogg";
+ }
+
+ public String getStopSoundFile()
+ {
+ return "Machines/IHL Industrial Fan/stop.ogg";
+ }
+
+ @Override
+ public void updateEntityClient()
+ {
+ this.updateBoth();
+ if(IC2.platform.isRendering() && this.loopAS!=null)
+ {
+ if(this.getActive())
+ {
+ if(this.startUpCounter>12)
+ {
+ this.startUpCounter=0;
+ }
+ if(this.startUpCounter==0)
+ {
+ this.stopAS.stop();
+ this.startAS.play();
+ }
+ if(this.startUpCounter<10)
+ {
+ this.startUpCounter++;
+ }
+ else if(this.startUpCounter==10)
+ {
+ this.startAS.stop();
+ this.loopAS.play();
+ this.startUpCounter++;
+ }
+ }
+ else if(this.startUpCounter>0)
+ {
+ this.startAS.stop();
+ this.loopAS.stop();
+ this.stopAS.play();
+ if(this.startUpCounter<170)
+ {
+ this.startUpCounter++;
+ }
+ else
+ {
+ this.startUpCounter=0;
+ this.stopAS.stop();
+ }
+ }
+ }
+ else if(IC2.platform.isRendering() && !this.getActive() && this.loopAS!=null)
+ {
+ this.loopAS.stop();
+ }
+ }
+
+ public void updateBoth()
+ {
+ if(this.dischargeSlot.tier!=this.tier)
+ {
+ this.dischargeSlot.tier=this.tier;
+ }
+ }
+
+
+ @Override
+ public void updateEntityServer()
+ {
+
+ if (IC2.platform.isSimulating())
+ {
+ this.setOverclockRates();
+ }
+ this.updateBoth();
+ if(this.getDemandedEnergy() > 1.0D)
+ {
+ double amount = this.dischargeSlot.discharge(this.getDemandedEnergy(), false);
+ this.energy += amount;
+ }
+ if(this.energy>this.maxStorage)
+ {
+ this.energy=this.maxStorage;
+ }
+ if(IC2.platform.isSimulating()&&!this.getActive()&&this.energy>=this.energyConsume*2D)
+ {
+ this.setActive(true);
+ }
+ else if(IC2.platform.isSimulating()&&this.getActive()&&this.energy<this.energyConsume)
+ {
+ this.setActive(false);
+ }
+ if(!this.aszlist.isEmpty() && this.getActive())
+ {
+ if(this.energy>=this.energyConsume)this.energy-=this.energyConsume;
+ Iterator<AirSpeedZone> it = this.aszlist.iterator();
+ a:while(it.hasNext())
+ {
+ AirSpeedZone asz = it.next();
+ List<Entity> entityList = worldObj.getEntitiesWithinAABB(Entity.class, asz.getAABB());
+ if(!entityList.isEmpty())
+ {
+ if(this.sCAFCount<=0)
+ {
+ this.aszlist.clear();
+ this.calculateAirSpeed();
+ this.sCAFCount=40;
+ break a;
+ }
+ Iterator<Entity> ei = entityList.iterator();
+ while(ei.hasNext())
+ {
+ Entity ent = ei.next();
+ if(asz.isEntityMoveable(ent))
+ {
+ if(ent instanceof EntityPlayer)
+ {
+ if(worldObj.isRemote)
+ {
+ ent.addVelocity(mX()*0.1D, mY()*0.05D, mZ()*0.1D);
+ }
+ }
+ else
+ {
+ ent.addVelocity(mX()*0.1D, mY()*0.05D, mZ()*0.1D);
+ }
+ }
+ }
+ }
+ }
+
+ }
+ if(this.sCAFCount>0)
+ {
+ this.sCAFCount--;
+ }
+ else
+ {
+ this.calculateAirSpeed();
+ if(this.operationRange==this.lastOperationRange)
+ {
+ this.sCAFCount=600;
+ }
+ else
+ {
+ this.sCAFCount=20;
+ this.lastOperationRange=this.operationRange;
+ }
+ }
+
+
+ }
+
+ private void calculateAirSpeed()
+ {
+ int x=xCoord;
+ int y=yCoord;
+ int z=zCoord;
+ int airSpeed=airSpeedBase;
+ int x0,y0,z0;
+ x0=x;
+ y0=y;
+ z0=z;
+ int flowExtL=0;
+ int flowExtR=0;
+ int flowExtT=0;
+ int flowExtB=0;
+ int flowCanBeExtL=0;
+ int flowCanBeExtR=0;
+ int flowCanBeExtT=0;
+ int flowCanBeExtB=0;
+
+ int checkFlowL=0;
+ int checkFlowR=0;
+ int checkFlowT=0;
+ int checkFlowB=0;
+
+ checkFlowL = Math.max(
+ this.neighborBlowerOperationRange(this.xCoord+mXL()+mX(), this.yCoord+mYL()+mY(),this.zCoord+mZL()+mZ()),
+ this.neighborBlowerOperationRange(this.xCoord+mXL()-mX(), this.yCoord+mYL()-mY(), this.zCoord+mZL()-mZ())
+ );
+ checkFlowR = Math.max(
+ this.neighborBlowerOperationRange(this.xCoord-mXL()+mX(), this.yCoord-mYL()+mY(),this.zCoord-mZL()+mZ()),
+ this.neighborBlowerOperationRange(this.xCoord-mXL()-mX(), this.yCoord-mYL()-mY(), this.zCoord-mZL()-mZ())
+ );
+ checkFlowT = Math.max(Math.max(
+ this.neighborBlowerOperationRange(this.xCoord+mXT()+mX(), this.yCoord+mYT()+mY(),this.zCoord+mZT()+mZ()),
+ this.neighborBlowerOperationRange(this.xCoord+mXT()-mX(), this.yCoord+mYT()-mY(), this.zCoord+mZT()-mZ())
+ ),
+ this.neighborBlowerOperationRange(this.xCoord+mXT(), this.yCoord+mYT(),this.zCoord+mZT()));
+ checkFlowB = Math.max(Math.max(
+ this.neighborBlowerOperationRange(this.xCoord-mXT()+mX(), this.yCoord-mYT()+mY(),this.zCoord-mZT()+mZ()),
+ this.neighborBlowerOperationRange(this.xCoord-mXT()-mX(), this.yCoord-mYT()-mY(), this.zCoord-mZT()-mZ())
+ ),
+ this.neighborBlowerOperationRange(this.xCoord-mXT(), this.yCoord-mYT(),this.zCoord-mZT()));
+ int asg = this.getAirSpeedGrade(airSpeed);
+ a:for(int step=0;step<256;step++)
+ {
+ x+=mX();
+ y+=mY();
+ z+=mZ();
+ airSpeed-=Math.round(lambda*(airSpeed*airSpeed))+1;
+ asg = this.getAirSpeedGrade(airSpeed);
+ if(asg==0)
+ {
+ break;
+ }
+ int i1,i2,il,ir,it,ib;
+ i1=0;i2=0;il=0;ir=0;it=0;ib=0;
+ for(int tb=-flowExtB;tb<=flowExtT;tb++)
+ {
+ i1++;
+ if(this.isAirPassable(x+mXL()*(flowExtL+1)+mXT()*tb,y+mYL()*(flowExtL+1)+mYT()*tb,z+mZL()*(flowExtL+1)+mZT()*tb))
+ {
+ il++;
+ }
+ if(this.isAirPassable(x-mXL()*(flowExtR+1)+mXT()*tb,y-mYL()*(flowExtR+1)+mYT()*tb,z-mZL()*(flowExtR+1)+mZT()*tb))
+ {
+ ir++;
+ }
+ }
+ if(i1==il && step>=checkFlowL)
+ {
+ flowCanBeExtL++;
+ }
+ if(i1==ir && step>=checkFlowR)
+ {
+ flowCanBeExtR++;
+ }
+ for(int lr=-flowExtL;lr<=flowExtR;lr++)
+ {
+ i2++;
+ if(this.isAirPassable(x+mXT()*(flowExtT+1)+mXL()*lr,y+mYT()*(flowExtT+1)+mYL()*lr,z+mZT()*(flowExtT+1)+mZL()*lr))
+ {
+ it++;
+ }
+ if(this.isAirPassable(x-mXT()*(flowExtB+1)+mXL()*lr,y-mYT()*(flowExtB+1)+mYL()*lr,z-mZT()*(flowExtB+1)+mZL()*lr))
+ {
+ ib++;
+ }
+ }
+ if(i2==it && step>=checkFlowT)
+ {
+ flowCanBeExtT++;
+ }
+ if(i2==ib && step>=checkFlowB)
+ {
+ flowCanBeExtB++;
+ }
+ airSpeed-=Math.round(lambda*(airSpeed*airSpeed)*(il+ir+it+ib))+il+ir+it+ib;
+ asg = this.getAirSpeedGrade(airSpeed);
+ if(asg==0)
+ {
+ this.operationRange=step;
+ break;
+ }
+ if(flowCanBeExtB>=4)
+ {
+ flowCanBeExtB=0;
+ this.aszlist.add(new AirSpeedZone(asg,
+ x0-mXL()*flowExtR-mXT()*flowExtB,
+ y0-mYL()*flowExtR-mYT()*flowExtB,
+ z0-mZL()*flowExtR-mZT()*flowExtB,
+ x-mX()+mXL()*flowExtL+mXT()*flowExtT,
+ y-mY()+mYL()*flowExtL+mYT()*flowExtT,
+ z-mZ()+mZL()*flowExtL+mZT()*flowExtT));
+ x0=x;
+ y0=y;
+ z0=z;
+ int s0=(flowExtR+flowExtL+1)*(flowExtT+flowExtB+1);
+ flowExtB++;
+ int s1=(flowExtR+flowExtL+1)*(flowExtT+flowExtB+1);
+ airSpeed=airSpeed*s0/s1;
+ }
+ else if(flowCanBeExtT>=4)
+ {
+ flowCanBeExtT=0;
+ this.aszlist.add(new AirSpeedZone(asg,
+ x0-mXL()*flowExtR-mXT()*flowExtB,
+ y0-mYL()*flowExtR-mYT()*flowExtB,
+ z0-mZL()*flowExtR-mZT()*flowExtB,
+ x-mX()+mXL()*flowExtL+mXT()*flowExtT,
+ y-mY()+mYL()*flowExtL+mYT()*flowExtT,
+ z-mZ()+mZL()*flowExtL+mZT()*flowExtT));
+ x0=x;
+ y0=y;
+ z0=z;
+ int s0=(flowExtR+flowExtL+1)*(flowExtT+flowExtB+1);
+ flowExtT++;
+ int s1=(flowExtR+flowExtL+1)*(flowExtT+flowExtB+1);
+ airSpeed=airSpeed*s0/s1;
+ }
+ else if(flowCanBeExtR>=4)
+ {
+ flowCanBeExtR=0;
+ this.aszlist.add(new AirSpeedZone(asg,
+ x0-mXL()*flowExtR-mXT()*flowExtB,
+ y0-mYL()*flowExtR-mYT()*flowExtB,
+ z0-mZL()*flowExtR-mZT()*flowExtB,
+ x-mX()+mXL()*flowExtL+mXT()*flowExtT,
+ y-mY()+mYL()*flowExtL+mYT()*flowExtT,
+ z-mZ()+mZL()*flowExtL+mZT()*flowExtT));
+ x0=x;
+ y0=y;
+ z0=z;
+ int s0=(flowExtR+flowExtL+1)*(flowExtT+flowExtB+1);
+ flowExtR++;
+ int s1=(flowExtR+flowExtL+1)*(flowExtT+flowExtB+1);
+ airSpeed=airSpeed*s0/s1;
+ }
+ else if(flowCanBeExtL>=3)
+ {
+ flowCanBeExtL=0;
+ this.aszlist.add(new AirSpeedZone(asg,
+ x0-mXL()*flowExtR-mXT()*flowExtB,
+ y0-mYL()*flowExtR-mYT()*flowExtB,
+ z0-mZL()*flowExtR-mZT()*flowExtB,
+ x-mX()+mXL()*flowExtL+mXT()*flowExtT,
+ y-mY()+mYL()*flowExtL+mYT()*flowExtT,
+ z-mZ()+mZL()*flowExtL+mZT()*flowExtT));
+ x0=x;
+ y0=y;
+ z0=z;
+ int s0=(flowExtR+flowExtL+1)*(flowExtT+flowExtB+1);
+ flowExtL++;
+ int s1=(flowExtR+flowExtL+1)*(flowExtT+flowExtB+1);
+ airSpeed=airSpeed*s0/s1;
+ }
+ else if(flowCanBeExtR>=3)
+ {
+ flowCanBeExtR=0;
+ this.aszlist.add(new AirSpeedZone(asg,
+ x0-mXL()*flowExtR-mXT()*flowExtB,
+ y0-mYL()*flowExtR-mYT()*flowExtB,
+ z0-mZL()*flowExtR-mZT()*flowExtB,
+ x-mX()+mXL()*flowExtL+mXT()*flowExtT,
+ y-mY()+mYL()*flowExtL+mYT()*flowExtT,
+ z-mZ()+mZL()*flowExtL+mZT()*flowExtT));
+ x0=x;
+ y0=y;
+ z0=z;
+ int s0=(flowExtR+flowExtL+1)*(flowExtT+flowExtB+1);
+ flowExtR++;
+ int s1=(flowExtR+flowExtL+1)*(flowExtT+flowExtB+1);
+ airSpeed=airSpeed*s0/s1;
+ }
+ else if(flowCanBeExtT>=3)
+ {
+ flowCanBeExtT=0;
+ this.aszlist.add(new AirSpeedZone(asg,
+ x0-mXL()*flowExtR-mXT()*flowExtB,
+ y0-mYL()*flowExtR-mYT()*flowExtB,
+ z0-mZL()*flowExtR-mZT()*flowExtB,
+ x-mX()+mXL()*flowExtL+mXT()*flowExtT,
+ y-mY()+mYL()*flowExtL+mYT()*flowExtT,
+ z-mZ()+mZL()*flowExtL+mZT()*flowExtT));
+ x0=x;
+ y0=y;
+ z0=z;
+ int s0=(flowExtR+flowExtL+1)*(flowExtT+flowExtB+1);
+ flowExtT++;
+ int s1=(flowExtR+flowExtL+1)*(flowExtT+flowExtB+1);
+ airSpeed=airSpeed*s0/s1;
+ }
+ else if(flowCanBeExtB>=3)
+ {
+ flowCanBeExtB=0;
+ this.aszlist.add(new AirSpeedZone(asg,
+ x0-mXL()*flowExtR-mXT()*flowExtB,
+ y0-mYL()*flowExtR-mYT()*flowExtB,
+ z0-mZL()*flowExtR-mZT()*flowExtB,
+ x-mX()+mXL()*flowExtL+mXT()*flowExtT,
+ y-mY()+mYL()*flowExtL+mYT()*flowExtT,
+ z-mZ()+mZL()*flowExtL+mZT()*flowExtT));
+ x0=x;
+ y0=y;
+ z0=z;
+ int s0=(flowExtR+flowExtL+1)*(flowExtT+flowExtB+1);
+ flowExtB++;
+ int s1=(flowExtR+flowExtL+1)*(flowExtT+flowExtB+1);
+ airSpeed=airSpeed*s0/s1;
+ }
+ for(int tb=-flowExtB;tb<=flowExtT;tb++)
+ {
+ for(int lr=-flowExtR;lr<=flowExtL;lr++)
+ {
+ if(!this.isAirPassable(x+mXL()*lr+mXT()*tb+mX(),y+mYL()*lr+mYT()*tb+mY(),z+mZL()*lr+mZT()*tb+mZ()))
+ {
+ if(lr==0 && tb==0)
+ {
+ //System.out.println("Flow breakened by wall check at step="+step);
+ this.operationRange=step;
+ break a;
+ }
+ else
+ {
+ this.aszlist.add(new AirSpeedZone(asg,
+ x0-mXL()*flowExtR-mXT()*flowExtB,
+ y0-mYL()*flowExtR-mYT()*flowExtB,
+ z0-mZL()*flowExtR-mZT()*flowExtB,
+ x-mX()+mXL()*flowExtL+mXT()*flowExtT,
+ y-mY()+mYL()*flowExtL+mYT()*flowExtT,
+ z-mZ()+mZL()*flowExtL+mZT()*flowExtT));
+ x0=x;
+ y0=y;
+ z0=z;
+ if(lr>0)
+ {
+ flowExtL=lr-1;
+ }
+ else if(lr<0)
+ {
+ flowExtR=-1-lr;
+ }
+ if(tb>0)
+ {
+ flowExtT=tb-1;
+ }
+ else if(tb<0)
+ {
+ flowExtB=-1-tb;
+ }
+ }
+ }
+ }
+ }
+ //System.out.println("Airspeed at step="+step+"equals="+airSpeed);
+ }
+ if(asg>0)
+ {
+ this.aszlist.add(new AirSpeedZone(asg,
+ x0-mXL()*flowExtR-mXT()*flowExtB,
+ y0-mYL()*flowExtR-mYT()*flowExtB,
+ z0-mZL()*flowExtR-mZT()*flowExtB,
+ x+mXL()*flowExtL+mXT()*flowExtT,
+ y+mYL()*flowExtL+mYT()*flowExtT,
+ z+mZL()*flowExtL+mZT()*flowExtT));
+ }
+ }
+
+
+ @Override
+ public boolean acceptsEnergyFrom(TileEntity emitter,
+ ForgeDirection direction) {
+ switch(direction)
+ {
+ case UP:
+ return mY()!=1;
+ case DOWN:
+ return mY()!=-1;
+ case NORTH:
+ return mZ()!=-1 && mZL()==0;
+ case EAST:
+ return mX()!=1 && mXL()==0;
+ case SOUTH:
+ return mZ()!=1 && mZL()==0;
+ case WEST:
+ return mX()!=-1 && mXL()==0;
+ default:
+ return false;
+ }
+ }
+
+ private boolean isCNE(int x,int y,int z,int x1,int y1,int z1)
+ {
+ return x!=x1||y!=y1||z!=z1;
+ }
+
+ private boolean isAirPassable(int x,int y,int z)
+ {
+ Block block = worldObj.getBlock(x,y,z);
+ if(block!=null && !block.isNormalCube(worldObj,x,y,z))
+ {
+ if(
+ !block.isCollidable() ||
+ block.isAir(worldObj,x, y, z) ||
+ block.getBlockBoundsMinX()>0.15D ||
+ block.getBlockBoundsMaxX()<0.85D ||
+ block.getBlockBoundsMinY()>0.15D ||
+ block.getBlockBoundsMaxY()<0.85D ||
+ block.getBlockBoundsMinZ()>0.15D ||
+ block.getBlockBoundsMaxZ()<0.85D
+ )
+ {
+ return true;
+ }
+ else
+ {
+ AxisAlignedBB cb = block.getCollisionBoundingBoxFromPool(worldObj, x, y, z);
+ if(cb!=null)
+ {
+ if(
+ cb.maxX<=1D &&
+ cb.maxX>=0D &&
+ cb.minX<=1D &&
+ cb.minX>=0D &&
+ cb.maxY<=1D &&
+ cb.maxY>=0D &&
+ cb.minY<=1D &&
+ cb.minY>=0D &&
+ cb.maxZ<=1D &&
+ cb.maxZ>=0D &&
+ cb.minZ<=1D &&
+ cb.minZ>=0D
+ )
+ {
+ if(
+ cb.maxX<0.85D||
+ cb.minX>0.15D||
+ cb.maxY<0.85D||
+ cb.minY>0.15D||
+ cb.maxZ<0.85D||
+ cb.minZ>0.15D
+ )
+ {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ private int getAirSpeedGrade(int airSpeed)
+ {
+ if(airSpeed<30)
+ {
+ return 0;
+ }
+ else if(airSpeed<100)
+ {
+ return 1;
+ }
+ else if(airSpeed<200)
+ {
+ return 2;
+ }
+ else if(airSpeed<300)
+ {
+ return 3;
+ }
+ else if(airSpeed<400)
+ {
+ return 4;
+ }
+ else if(airSpeed<500)
+ {
+ return 5;
+ }
+ else if(airSpeed<600)
+ {
+ return 6;
+ }
+ else
+ {
+ return 7;
+ }
+ }
+
+ private class AirSpeedZone
+ {
+ private int airSpeedGrade, x0, y0, z0, x1, y1, z1;
+ public AirSpeedZone(int airSpeedGrade1, int vx0, int vy0, int vz0, int vx1,int vy1,int vz1)
+ {
+ this.airSpeedGrade=airSpeedGrade1;
+ this.x0=vx0;
+ this.y0=vy0;
+ this.z0=vz0;
+ this.x1=vx1;
+ this.y1=vy1;
+ this.z1=vz1;
+ }
+
+ public AxisAlignedBB getAABB()
+ {
+ return AxisAlignedBB.getBoundingBox(Math.min(x0,x1), Math.min(y0,y1), Math.min(z0,z1), Math.max(x0,x1)+1D, Math.max(y0,y1)+1D, Math.max(z0,z1)+1D);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if(obj instanceof AirSpeedZone)
+ {
+ AirSpeedZone asz = (AirSpeedZone)obj;
+ return (
+ this.x0==asz.x0 &&
+ this.y0==asz.y0 &&
+ this.z0==asz.z0 &&
+ this.x1==asz.x1 &&
+ this.y1==asz.y1 &&
+ this.z1==asz.z1);
+ }
+ return false;
+ }
+
+ public boolean isEntityMoveable(Entity entity)
+ {
+ if(this.airSpeedGrade>=7)
+ {
+ return true;
+ }
+ else
+ {
+ return (entity.width+1F)*(entity.height+1F)<=this.airSpeedGrade*2;
+ }
+ }
+ }
+
+ private int mX()
+ {
+ switch(this.getFacing())
+ {
+ case 4:
+ return -1;
+ case 5:
+ return 1;
+ default:
+ return 0;
+ }
+ }
+
+ private int mY()
+ {
+ switch(this.getFacing())
+ {
+ case 0:
+ return -1;
+ case 1:
+ return 1;
+ default:
+ return 0;
+ }
+ }
+
+ private int mZ()
+ {
+ switch(this.getFacing())
+ {
+ case 2:
+ return -1;
+ case 3:
+ return 1;
+ default:
+ return 0;
+ }
+ }
+
+ private int mXL()
+ {
+ switch(this.getFacing())
+ {
+ case 0:
+ return -1;
+ case 1:
+ return 1;
+ case 2:
+ return -1;
+ case 3:
+ return 1;
+ default:
+ return 0;
+ }
+ }
+
+ private int mYL()
+ {
+ return 0;
+ }
+
+ private int mZL()
+ {
+ switch(this.getFacing())
+ {
+ case 4:
+ return 1;
+ case 5:
+ return -1;
+ default:
+ return 0;
+ }
+ }
+
+ private int mXT()
+ {
+ return 0;
+ }
+
+ private int mYT()
+ {
+ switch(this.getFacing())
+ {
+ case 2:
+ return 1;
+ case 3:
+ return 1;
+ case 4:
+ return 1;
+ case 5:
+ return 1;
+ default:
+ return 0;
+ }
+ }
+
+ private int mZT()
+ {
+ switch(this.getFacing())
+ {
+ case 0:
+ return 1;
+ case 1:
+ return -1;
+ default:
+ return 0;
+ }
+ }
+
+
+@Override
+ public String getInventoryName() {
+ return "blower";
+ }
+
+ public int getStored() {
+ return Math.round((float)this.energy);
+ }
+
+ public void setStored(int value) {
+ this.energy=value;
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public GuiScreen getGui(EntityPlayer arg0, boolean arg1) {
+ return new BlowerGui(new BlowerContainer(arg0, this));
+ }
+
+ public boolean getGui(EntityPlayer player)
+ {
+ return this instanceof IHasGui ? (IC2.platform.isSimulating() ? IC2.platform.launchGui(player, this) : true) : false;
+ }
+ @Override
+ public ContainerBase<?> getGuiContainer(EntityPlayer arg0) {
+ return new BlowerContainer(arg0, this);
+ }
+ @Override
+ public void onGuiClosed(EntityPlayer arg0) {}
+
+ public void setOverclockRates()
+ {
+ int speedUp=0;
+ int tierUp=0;
+ int capacityUp=0;
+ int checksum=0;
+ for(int i=0;i<this.upgradeSlot.size();i++)
+ {
+ if(this.upgradeSlot.get(i)!=null)
+ {
+ if(this.upgradeSlot.get(i).getItemDamage()==IC2Items.getItem("overclockerUpgrade").getItemDamage())
+ {
+ speedUp+=this.upgradeSlot.get(i).stackSize;
+ }
+ if(this.upgradeSlot.get(i).getItemDamage()==IC2Items.getItem("transformerUpgrade").getItemDamage())
+ {
+ tierUp+=this.upgradeSlot.get(i).stackSize;
+ }
+ if(this.upgradeSlot.get(i).getItemDamage()==IC2Items.getItem("energyStorageUpgrade").getItemDamage())
+ {
+ capacityUp+=this.upgradeSlot.get(i).stackSize;
+ }
+ }
+ }
+ checksum=speedUp*4096+tierUp*64+capacityUp;
+ if(this.updateChecksum!=checksum)
+ {
+
+ if(
+ this.isAirPassable(this.xCoord+mXL(),this.yCoord+mYL(),this.zCoord+mZL())&&
+ this.isAirPassable(this.xCoord-mXL(),this.yCoord-mYL(),this.zCoord-mZL()))
+ {
+ this.airSpeedBase=Math.min(3284,(int) (this.defaultAirSpeedBase*Math.pow(1.7D, speedUp)));
+ }
+ else if(
+ !this.isAirPassable(this.xCoord+mXL(),this.yCoord+mYL(),this.zCoord+mZL())&&
+ !this.isAirPassable(this.xCoord-mXL(),this.yCoord-mYL(),this.zCoord-mZL()))
+ {
+ this.airSpeedBase=0;
+ }
+ else
+ {
+ this.airSpeedBase=Math.min(3282,(int) (this.defaultAirSpeedBase*Math.pow(1.7D, speedUp)*0.5D));
+ }
+ this.maxStorage=this.defaultMaxStorage + capacityUp*10000;
+ IC2.network.get().updateTileEntityField(this, "maxStorage");
+ this.energyConsume=(int) Math.min(this.defaultEnergyConsume*Math.pow(1.6D, speedUp),this.maxStorage);
+ IC2.network.get().updateTileEntityField(this, "airSpeedBase");
+ this.tier=this.defaultTier+tierUp;
+ IC2.network.get().updateTileEntityField(this, "tier");
+ this.updateChecksum=checksum;
+ }
+ }
+
+ //1.7.10 API
+ @Override
+ public double getDemandedEnergy()
+ {
+ return this.maxStorage - this.energy;
+ }
+
+ @Override
+ public int getSinkTier()
+ {
+ return this.tier;
+ }
+
+ @Override
+ public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage)
+ {
+ if (this.energy >= this.maxStorage)
+ {
+ return amount;
+ }
+ else
+ {
+ this.energy += amount;
+ return 0.0D;
+ }
+ }
+
+ @Override
+ public double getEnergy() {
+ return this.energy;
+ }
+
+ @Override
+ public boolean useEnergy(double amount)
+ {
+ if (this.energy >= amount)
+ {
+ this.energy -= amount;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public int neighborBlowerOperationRange(int x,int y,int z)
+ {
+ if(this.worldObj.getTileEntity(x, y, z)!=null && this.worldObj.getTileEntity(x, y, z) instanceof BlowerTileEntity)
+ {
+ BlowerTileEntity bte = (BlowerTileEntity) this.worldObj.getTileEntity(x, y, z);
+ if(bte.getFacing()==this.getFacing())
+ {
+ return bte.operationRange;
+ }
+ }
+ return -1;
+ }
+
+ public ItemStack getOutput(int arg0)
+ {
+ return null;
+ }
+
+ public int getOutputSize() {
+ return 0;
+ }
+
+ public void setOutput(int arg0, ItemStack arg1) {
+ }
+
+ @Override
+ public Set<UpgradableProperty> getUpgradableProperties()
+ {
+ Set<UpgradableProperty> properties = new HashSet<UpgradableProperty>();
+ properties.add(UpgradableProperty.Processing);
+ properties.add(UpgradableProperty.EnergyStorage);
+ properties.add(UpgradableProperty.Transformer);
+ return properties;
+ }
+} \ No newline at end of file
diff --git a/ihl/crop_harvestors/RubberTreeBlock.java b/ihl/crop_harvestors/RubberTreeBlock.java
new file mode 100644
index 0000000..bb2128b
--- /dev/null
+++ b/ihl/crop_harvestors/RubberTreeBlock.java
@@ -0,0 +1,167 @@
+package ihl.crop_harvestors;
+
+import java.util.Random;
+
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import ic2.api.item.IC2Items;
+import ihl.IHLModInfo;
+import net.minecraft.block.Block;
+import net.minecraft.block.material.Material;
+import net.minecraft.client.renderer.texture.IIconRegister;
+import net.minecraft.init.Blocks;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.IIcon;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+import net.minecraftforge.common.util.ForgeDirection;
+
+public class RubberTreeBlock extends Block{
+
+ IIcon textureSide, textureTop;
+ TreeType type;
+
+ public RubberTreeBlock(TreeType type1)
+ {
+ super(Material.wood);
+ type=type1;
+ }
+
+ @Override
+ public Item getItemDropped(int var1, Random rnd, int var2)
+ {
+ switch(type)
+ {
+ case RUBBERTREE:
+ return IC2Items.getItem("rubberWood").getItem();
+ case SPRUCE:
+ return Blocks.log.getItemDropped(var1, rnd, var2);
+ default:
+ return IC2Items.getItem("rubberWood").getItem();
+ }
+
+ }
+
+ @Override
+ public boolean canSustainLeaves(IBlockAccess blockAccess, int x, int y, int z)
+ {
+ return true;
+ }
+
+ @Override
+ public void dropBlockAsItemWithChance(World world, int x, int y, int z, int meta, float chance, int flag)
+ {
+ ItemStack result;
+ switch(type)
+ {
+ case RUBBERTREE:
+ result = IC2Items.getItem("rubberWood").copy();
+ case SPRUCE:
+ result = new ItemStack(Blocks.log,1,1);
+ default:
+ result = IC2Items.getItem("rubberWood").copy();
+ }
+ this.dropBlockAsItem(world, x, y, z, result);
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public void registerBlockIcons(IIconRegister par1IconRegister)
+ {
+ ItemStack result;
+ switch(type)
+ {
+ case RUBBERTREE:
+ this.blockIcon = par1IconRegister.registerIcon(IHLModInfo.MODID + ":blockRubWoodFront");
+ this.textureTop = par1IconRegister.registerIcon(IHLModInfo.MODID + ":blockRubWoodTop");
+ this.textureSide = par1IconRegister.registerIcon(IHLModInfo.MODID + ":blockRubWoodSide");
+ case SPRUCE:
+ this.blockIcon = par1IconRegister.registerIcon(IHLModInfo.MODID + ":blockSpruceFront");
+ this.textureTop = par1IconRegister.registerIcon("minecraft:log_spruce_top");
+ this.textureSide = par1IconRegister.registerIcon("minecraft:log_spruce");
+ }
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side)
+ {
+ int facing=3;
+ int mask[] = {
+ 0,1,2,3,4,5,
+ 1,0,3,2,4,5,
+ 3,2,0,1,4,5,
+ 2,3,1,0,4,5,
+ 2,3,5,4,0,1,
+ 2,3,4,5,1,0
+ };
+ facing=world.getBlockMetadata(x, y, z);
+ switch (mask[facing*6+side])
+ {
+ case 0:
+ return this.textureSide;
+ case 1:
+ return this.blockIcon;
+ case 2:
+ return this.textureTop;
+ case 3:
+ return this.textureTop;
+ case 4:
+ return this.textureSide;
+ case 5:
+ return this.textureSide;
+ default:
+ return this.textureSide;
+ }
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public IIcon getIcon(int side, int meta)
+ {
+ IIcon sideIcon = this.blockIcon;
+ switch (side)
+ {
+ case 0:
+ return this.textureTop;
+ case 1:
+ return this.textureTop;
+ case 2:
+ return this.blockIcon;
+ case 3:
+ return this.textureSide;
+ case 4:
+ return this.textureSide;
+ case 5:
+ return this.textureSide;
+ default:
+ return this.textureSide;
+ }
+ }
+
+ public enum TreeType
+ {
+ RUBBERTREE,
+ SPRUCE
+ }
+
+ @Override
+ public boolean isWood(IBlockAccess world, int x, int y, int z)
+ {
+ return true;
+ }
+
+ @Override
+ public int getFireSpreadSpeed(IBlockAccess world, int x, int y, int z, ForgeDirection face)
+ {
+ return 4;
+ }
+
+ @Override
+ public int getFlammability(IBlockAccess world, int x, int y, int z, ForgeDirection face)
+ {
+ return 20;
+ }
+
+}
diff --git a/ihl/crop_harvestors/SackBlock.java b/ihl/crop_harvestors/SackBlock.java
new file mode 100644
index 0000000..78a5735
--- /dev/null
+++ b/ihl/crop_harvestors/SackBlock.java
@@ -0,0 +1,167 @@
+package ihl.crop_harvestors;
+
+import java.util.List;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+import ihl.IHLCreativeTab;
+import ihl.IHLModInfo;
+import net.minecraft.block.Block;
+import net.minecraft.block.ITileEntityProvider;
+import net.minecraft.block.material.Material;
+import net.minecraft.client.renderer.texture.IIconRegister;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.AxisAlignedBB;
+import net.minecraft.util.MathHelper;
+import net.minecraft.world.World;
+import net.minecraftforge.common.util.ForgeDirection;
+import net.minecraftforge.fluids.FluidContainerRegistry;
+import net.minecraftforge.fluids.FluidStack;
+import net.minecraftforge.fluids.IFluidContainerItem;
+
+public class SackBlock extends Block implements ITileEntityProvider{
+
+ public SackBlock(Material material)
+ {
+ super(material);
+ this.setCreativeTab(IHLCreativeTab.tab);
+ }
+
+ @Override
+ public TileEntity createNewTileEntity(World world, int var2) {
+ return new SackTileEntity();
+ }
+
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public void registerBlockIcons(IIconRegister par1IconRegister)
+ {
+ this.blockIcon = par1IconRegister.registerIcon(IHLModInfo.MODID + ":sackItem");
+ }
+
+ @Override
+ public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB aabb, List list, Entity entity)
+ {
+ this.setBlockBounds(0.2F, 0.0F, 0.2F, 0.8F, 0.1F, 0.8F);
+ super.addCollisionBoxesToList(world, x, y, z, aabb, list, entity);
+ this.setBlockBounds(0.2F, 0.0F, 0.2F, 0.21F, 1.0F, 0.8F);
+ super.addCollisionBoxesToList(world, x, y, z, aabb, list, entity);
+ this.setBlockBounds(0.2F, 0.0F, 0.2F, 0.8F, 1.0F, 0.21F);
+ super.addCollisionBoxesToList(world, x, y, z, aabb, list, entity);
+ this.setBlockBounds(0.79F, 0.0F, 0.0F, 0.8F, 1.0F, 0.8F);
+ super.addCollisionBoxesToList(world, x, y, z, aabb, list, entity);
+ this.setBlockBounds(0.0F, 0.0F, 0.79F, 0.8F, 1.0F, 0.8F);
+ super.addCollisionBoxesToList(world, x, y, z, aabb, list, entity);
+ this.setBlockBoundsForItemRender();
+ }
+
+ @Override
+ public void setBlockBoundsForItemRender()
+ {
+ this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
+ }
+
+ @Override
+ public boolean hasTileEntity(int metadata)
+ {
+ return true;
+ }
+
+ @Override
+ public boolean onBlockActivated(World world,int x,int y,int z,EntityPlayer entityPlayer,int i,float pos_x,float pos_y,float pos_z){
+ TileEntity te = world.getTileEntity(x,y,z);
+ if(!world.isRemote && te instanceof SackTileEntity)
+ {
+ SackTileEntity ste = (SackTileEntity)te;
+ if (ste == null || entityPlayer.isSneaking()) {
+ return false;
+ }
+ else
+ {
+ if(ste.fluidTank.getFluid()!=null)
+ {
+ if(entityPlayer.inventory.getCurrentItem()!=null)
+ {
+ if(entityPlayer.inventory.getCurrentItem().getItem() instanceof IFluidContainerItem)
+ {
+ return false;
+ }
+ FluidStack drainFS = ste.drain(ForgeDirection.UNKNOWN, ste.fluidTank.getCapacity(), false);
+ ItemStack stackToAdd = FluidContainerRegistry.fillFluidContainer(drainFS, entityPlayer.inventory.getCurrentItem());
+ if(stackToAdd!=null)
+ {
+ if (entityPlayer.inventory.addItemStackToInventory(stackToAdd))
+ {
+ entityPlayer.inventory.getCurrentItem().stackSize--;
+ entityPlayer.inventoryContainer.detectAndSendChanges();
+ ste.drain(ForgeDirection.UNKNOWN, FluidContainerRegistry.getContainerCapacity(stackToAdd),true);
+ }
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * The type of render function that is called for this block
+ */
+ @Override
+ public int getRenderType()
+ {
+ return -2;
+ }
+
+ /**
+ * Is this block (a) opaque and (B) a full 1m cube? This determines whether or not to render the shared face of two
+ * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
+ */
+ @Override
+ public boolean isOpaqueCube()
+ {
+ return false;
+ }
+
+ /**
+ * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
+ */
+ @Override
+ public boolean renderAsNormalBlock()
+ {
+ return false;
+ }
+
+ @Override
+ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack)
+ {
+ int var7 = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
+ TileEntity t = world.getTileEntity(x, y, z);
+ if(t!=null && t instanceof SackTileEntity)
+ {
+ SackTileEntity te = (SackTileEntity)t;
+ switch(var7)
+ {
+ case 0:
+ te.setFacing((short) 3);
+ break;
+ case 1:
+ te.setFacing((short) 4);
+ break;
+ case 2:
+ te.setFacing((short) 2);
+ break;
+ case 3:
+ te.setFacing((short) 5);
+ break;
+ default:
+ break;
+ }
+
+ }
+ }
+}
diff --git a/ihl/crop_harvestors/SackModel.java b/ihl/crop_harvestors/SackModel.java
new file mode 100644
index 0000000..a0fe780
--- /dev/null
+++ b/ihl/crop_harvestors/SackModel.java
@@ -0,0 +1,103 @@
+package ihl.crop_harvestors;
+
+import net.minecraft.client.model.ModelBase;
+import net.minecraft.client.model.ModelRenderer;
+import net.minecraft.entity.Entity;
+
+public class SackModel extends ModelBase {
+ //fields
+ ModelRenderer Base;
+ ModelRenderer Top;
+ ModelRenderer Liquid;
+ ModelRenderer Liquid_overflow;
+ ModelRenderer Liquid2;
+ ModelRenderer Liquid2_overflow;
+ ModelRenderer Rope1;
+ ModelRenderer Rope2;
+
+ public SackModel()
+ {
+ textureWidth = 64;
+ textureHeight = 64;
+ setTextureOffset("Base.Shape1", 0, 0);
+ setTextureOffset("Base.Shape2", 0, 0);
+ setTextureOffset("Base.Shape3", 0, 0);
+ setTextureOffset("Base.Shape4", 0, 0);
+ setTextureOffset("Base.Shape5", 0, 0);
+ setTextureOffset("Top.Shape6", 0, 0);
+ setTextureOffset("Top.Shape7", 0, 0);
+ setTextureOffset("Top.Shape8", 0, 0);
+ setTextureOffset("Liquid.Shape9", 20, 20);
+ setTextureOffset("Liquid_overflow.Shape12", 46, 25);
+ setTextureOffset("Rope1.Shape12", 56, 17);
+ setTextureOffset("Rope2.Shape13", 48, 17);
+
+ setTextureOffset("Liquid2.Shape14", 0, 32);
+ setTextureOffset("Liquid2_overflow.Shape15", 46, 57);
+
+ Base = new ModelRenderer(this, "Base");
+ Base.setRotationPoint(0F, 8F, 0F);
+ setRotation(Base, 0F, 0F, 0F);
+ Base.mirror = true;
+ Base.addBox("Shape1", -6F, 15F, -4F, 12, 1, 12);
+ Base.addBox("Shape2", -6F, 2F, -4F, 12, 13, 1);
+ Base.addBox("Shape3", -6F, 2F, -3F, 1, 13, 10);
+ Base.addBox("Shape4", 5F, 2F, -3F, 1, 13, 10);
+ Base.addBox("Shape5", -6F, 0F, 7F, 12, 15, 1);
+ Top = new ModelRenderer(this, "Top");
+ Top.setRotationPoint(0F, 9F, 0F);
+ setRotation(Top, 0.05F, 0F, 0F);
+ Top.mirror = true;
+ Top.addBox("Shape6", -6.2F, -0.5F, -4.4F, 1, 2, 12);
+ Top.addBox("Shape7", 5.2F, -0.5F, -4.4F, 1, 2, 12);
+ Top.addBox("Shape8", -6F, -0.4F, -4.5F, 12, 2, 1);
+ Liquid = new ModelRenderer(this, "Liquid");
+ Liquid.setRotationPoint(0F, 8F, 0F);
+ setRotation(Liquid, 0F, 0F, 0F);
+ Liquid.mirror = true;
+ Liquid.addBox("Shape9", -5.5F, 0.5F, -3.5F, 11, 1, 11);
+ Liquid_overflow = new ModelRenderer(this, "Liquid_overflow");
+ Liquid_overflow.setRotationPoint(0F, 8F, 0F);
+ setRotation(Liquid_overflow, 0.051F, 0F, 0.01F);
+ Liquid_overflow.mirror = true;
+ Liquid_overflow.addBox("Shape12", -4F, 0.55F, -4.4F, 8, 2, 2);
+
+ Liquid2 = new ModelRenderer(this, "Liquid2");
+ Liquid2.setRotationPoint(0F, 8F, 0F);
+ setRotation(Liquid2, 0F, 0F, 0F);
+ Liquid2.mirror = true;
+ Liquid2.addBox("Shape14", -5.5F, 0.5F, -3.5F, 11, 1, 11);
+ Liquid2_overflow = new ModelRenderer(this, "Liquid2_overflow");
+ Liquid2_overflow.setRotationPoint(0F, 8F, 0F);
+ setRotation(Liquid2_overflow, 0.051F, 0F, 0.01F);
+ Liquid2_overflow.mirror = true;
+ Liquid2_overflow.addBox("Shape15", -4F, 0.55F, -4.4F, 8, 2, 2);
+
+
+ Rope1 = new ModelRenderer(this, "Rope1");
+ Rope1.setRotationPoint(0F, 8F, 0F);
+ setRotation(Rope1, 0F, 0F, -0.2F);
+ Rope1.mirror = true;
+ Rope1.addBox("Shape12", 5F, 0.7F, 7.9F, 3, 1, 1);
+ Rope2 = new ModelRenderer(this, "Rope2");
+ Rope2.setRotationPoint(0F, 8F, 0F);
+ setRotation(Rope2, 0F, 0F, 0.2F);
+ Rope2.mirror = true;
+ Rope2.addBox("Shape13", -8F, 0.7F, 7.9F, 3, 1, 1);
+ }
+
+ private void setRotation(ModelRenderer model, float x, float y, float z)
+ {
+ model.rotateAngleX = x;
+ model.rotateAngleY = y;
+ model.rotateAngleZ = z;
+ }
+
+ @Override
+ public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)
+ {
+ super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
+ }
+}
+
+
diff --git a/ihl/crop_harvestors/SackRender.java b/ihl/crop_harvestors/SackRender.java
new file mode 100644
index 0000000..e359e3a
--- /dev/null
+++ b/ihl/crop_harvestors/SackRender.java
@@ -0,0 +1,95 @@
+package ihl.crop_harvestors;
+import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.ResourceLocation;
+import net.minecraftforge.fluids.FluidRegistry;
+
+import org.lwjgl.opengl.GL11;
+import ihl.IHLModInfo;
+
+public class SackRender extends TileEntitySpecialRenderer{
+private SackModel model = new SackModel();
+private ResourceLocation tex = new ResourceLocation(IHLModInfo.MODID+":textures/blocks/sack.png");
+private final float maxRenderLiquidLevel=0.5F;
+private final float minRenderLiquidLevel=14.5F;
+private final float scale=1F/16F;
+private float overflow=0F;
+
+
+public SackRender(){}
+
+public void renderAModelAt(SackTileEntity tile, double d, double d1, double d2, float f) {
+int rotation = 0;
+if(tile.getWorldObj() != null)
+{
+ switch (tile.getFacing())
+ {
+ case 2:
+ rotation = 0;
+ break;
+ case 5:
+ rotation = 1;
+ break;
+ case 3:
+ rotation = 2;
+ break;
+ case 4:
+ rotation = 3;
+ break;
+ default:
+ rotation = 0;
+ }
+}
+bindTexture(tex); //texture
+GL11.glPushMatrix();
+GL11.glTranslatef((float)d + 0.5F, (float)d1 + 1.5F, (float)d2 + 0.5F);
+GL11.glScalef(1.0F, -1F, -1F);
+GL11.glRotatef(rotation*90, 0.0F, 1.0F, 0.0F);
+model.Base.render(scale);
+model.Top.render(scale);
+model.Rope1.render(scale);
+model.Rope2.render(scale);
+GL11.glEnable(GL11.GL_BLEND);
+GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
+GL11.glColor4f(1f,1f,1f,1f);
+model.Liquid2.offsetY=model.Liquid.offsetY=(minRenderLiquidLevel-(minRenderLiquidLevel-maxRenderLiquidLevel)*tile.getRenderLiquidLevel())*scale;
+if(tile.getRenderLiquidLevel()>0)
+{
+ if(tile.visibleFluidId!=-1)
+ {
+ if(tile.visibleFluidId==FluidRegistry.getFluid("fluidrubbertreesap").getID())
+ {
+ model.Liquid.render(scale);
+ }
+ else if(tile.visibleFluidId==FluidRegistry.getFluid("spruceresin").getID())
+ {
+ model.Liquid2.render(scale);
+ }
+ }
+}
+if(tile.getRenderLiquidLevel()>0.98F)
+{
+ if(overflow<0.5F)overflow+=0.001F;
+ model.Liquid2_overflow.offsetZ=model.Liquid_overflow.offsetZ=-overflow*scale;
+ if(tile.visibleFluidId!=-1)
+ {
+ if(tile.visibleFluidId==FluidRegistry.getFluid("fluidrubbertreesap").getID())
+ {
+ model.Liquid_overflow.render(scale);
+ }
+ else if(tile.visibleFluidId==FluidRegistry.getFluid("spruceresin").getID())
+ {
+ model.Liquid2_overflow.render(scale);
+ }
+ }
+}
+GL11.glDisable(GL11.GL_BLEND);
+GL11.glPopMatrix(); //end
+}
+
+ @Override
+ public void renderTileEntityAt(TileEntity par1TileEntity, double par2, double par4, double par6, float par8)
+ {
+ this.renderAModelAt((SackTileEntity)par1TileEntity, par2, par4, par6, par8);
+ }
+} \ No newline at end of file
diff --git a/ihl/crop_harvestors/SackTileEntity.java b/ihl/crop_harvestors/SackTileEntity.java
new file mode 100644
index 0000000..9704b7f
--- /dev/null
+++ b/ihl/crop_harvestors/SackTileEntity.java
@@ -0,0 +1,569 @@
+package ihl.crop_harvestors;
+
+import java.util.List;
+import java.util.Random;
+
+import net.minecraft.block.Block;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.init.Blocks;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraftforge.common.util.ForgeDirection;
+import net.minecraftforge.fluids.Fluid;
+import net.minecraftforge.fluids.FluidRegistry;
+import net.minecraftforge.fluids.FluidStack;
+import net.minecraftforge.fluids.FluidTankInfo;
+import net.minecraftforge.fluids.IFluidHandler;
+import ic2.core.IC2;
+import ic2.core.block.TileEntityInventory;
+import ic2.core.network.NetworkManager;
+import ihl.IHLMod;
+import ihl.utils.IHLFluidTank;
+
+public class SackTileEntity extends TileEntityInventory implements IFluidHandler
+{
+ private final int maxLeavesHeight=12;
+ private final int maxLeavesWidth=5;
+ public float leavesCounter=0F;
+ private int updateCounter=1100;
+ private Random rand=new Random();
+ private int blobTimer=20;
+ public byte currentTree = RUBBERTREE;
+ public final int blobCapacity = 1;
+ private final static byte RUBBERTREE=0;
+ private final static byte SPRUCE=1;
+ public final IHLFluidTank fluidTank = new IHLFluidTank(8000);
+ public int visibleFluidId = -1;
+ public int visibleFluidAmount = 1;
+
+ public SackTileEntity() {
+ super();
+ }
+
+ @Override
+ public List<String> getNetworkedFields()
+ {
+ List<String> fields = super.getNetworkedFields();
+ fields.add("visibleFluidId");
+ fields.add("visibleFluidAmount");
+ fields.add("leavesCounter");
+ fields.add("currentTree");
+ return fields;
+ }
+
+ @Override
+ public void readFromNBT(NBTTagCompound nbttagcompound)
+ {
+ super.readFromNBT(nbttagcompound);
+ this.fluidTank.readFromNBT(nbttagcompound.getCompoundTag("fluidTank"));
+ }
+
+ @Override
+ public void writeToNBT(NBTTagCompound nbttagcompound)
+ {
+ super.writeToNBT(nbttagcompound);
+ NBTTagCompound fluidTankTag = new NBTTagCompound();
+ this.fluidTank.writeToNBT(fluidTankTag);
+ nbttagcompound.setTag("fluidTank", fluidTankTag);
+ }
+
+ @Override
+ public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
+ return false;
+ }
+
+ @Override
+ public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
+ return new ItemStack(IHLMod.sackBlock,1);
+ }
+
+ public boolean enableUpdateEntity()
+ {
+ return true;
+ }
+
+
+ @Override
+ public void updateEntityClient()
+ {
+ super.updateEntityClient();
+ if(IHLMod.ic2Leaves!=null && IHLMod.ic2Wood!=null)
+ {
+ if(this.blobTimer<=0)
+ {
+ if(IC2.platform.isRendering())
+ {
+ switch(this.currentTree)
+ {
+ case RUBBERTREE:
+ IHLMod.proxy.spawnParticle(1,worldObj, xCoord+0.5D+mX()*0.5D,yCoord+1.05D,zCoord+0.5D+mZ()*0.5D,-(double)mX()*0.1D,-0.03D,-(double)mZ()*0.1D,0.1F);
+ break;
+ case SPRUCE:
+ IHLMod.proxy.spawnParticle(2,worldObj, xCoord+0.5D+mX()*0.5D,yCoord+1.05D,zCoord+0.5D+mZ()*0.5D,-(double)mX()*0.1D,-0.03D,-(double)mZ()*0.1D,0.1F);
+ break;
+ }
+ }
+ if(this.fluidTank.getFluidAmount()>=this.fluidTank.getCapacity())
+ {
+ if(IC2.platform.isRendering())
+ {
+ switch(this.currentTree)
+ {
+ case RUBBERTREE:
+ IHLMod.proxy.spawnParticle(1,worldObj, xCoord+0.5D-mX()*0.3D+(rand.nextDouble()-0.5D)*mZ()*0.6D,yCoord+0.8D,zCoord+0.5D-mZ()*0.3D+(rand.nextDouble()-0.5D)*mX()*0.6D,0D,-0.05D,0D,0.1F);
+ break;
+ case SPRUCE:
+ IHLMod.proxy.spawnParticle(2,worldObj, xCoord+0.5D-mX()*0.3D+(rand.nextDouble()-0.5D)*mZ()*0.6D,yCoord+0.8D,zCoord+0.5D-mZ()*0.3D+(rand.nextDouble()-0.5D)*mX()*0.6D,0D,-0.05D,0D,0.1F);
+ break;
+ }
+ }
+ }
+ if(this.leavesCounter>1F)
+ {
+ this.blobTimer=Math.round(4000F/this.leavesCounter);
+ }
+ else
+ {
+ this.blobTimer=200;
+ }
+ }
+ else
+ {
+ if(this.leavesCounter>1F)
+ {
+ this.blobTimer--;
+ }
+ }
+ if(this.updateCounter<1200)
+ {
+ this.updateCounter++;
+ }
+ }
+
+ }
+
+
+ @Override
+ public void updateEntityServer()
+ {
+ super.updateEntityServer();
+ if(IHLMod.ic2Leaves!=null && IHLMod.ic2Wood!=null)
+ {
+ if(this.blobTimer<=0)
+ {
+ {
+ if(IC2.platform.isSimulating())
+ {
+ switch(this.currentTree)
+ {
+ case RUBBERTREE:
+ this.fluidTank.fill(new FluidStack(FluidRegistry.getFluid("fluidrubbertreesap"), blobCapacity), true);
+ break;
+ case SPRUCE:
+ this.fluidTank.fill(new FluidStack(FluidRegistry.getFluid("spruceresin"), blobCapacity), true);
+ break;
+ }
+ }
+ }
+ if(this.leavesCounter>1F)
+ {
+ this.blobTimer=Math.round(4000F/this.leavesCounter);
+ }
+ else
+ {
+ this.blobTimer=200;
+ }
+ }
+ else
+ {
+ if(this.leavesCounter>1F)
+ {
+ this.blobTimer--;
+ }
+ }
+ if(this.updateCounter<1200)
+ {
+ this.updateCounter++;
+ }
+ else
+ {
+ if(IC2.platform.isSimulating())
+ {
+ this.updateCounter=rand.nextInt(600);
+ if(checkCorrectPlacing())
+ {
+ countRubberTreeLeaves();
+ }
+ else
+ {
+ leavesCounter=0F;
+ }
+ IC2.network.get().updateTileEntityField(this, "currentTree");
+ IC2.network.get().updateTileEntityField(this, "leavesCounter");
+ if(this.fluidTank.getFluid()!=null)
+ {
+
+ TileEntity te = worldObj.getTileEntity(xCoord, yCoord-1, zCoord);
+ if(te!=null && te instanceof IFluidHandler)
+ {
+ IFluidHandler fte = (IFluidHandler) te;
+ FluidStack fStack = this.fluidTank.drain(Integer.MAX_VALUE, false);
+ if(fte.canFill(ForgeDirection.UP, fStack.getFluid()))
+ {
+ if(fte.fill(ForgeDirection.UP, fStack, false)>0)
+ {
+ int amount = fte.fill(ForgeDirection.UP, fStack, true);
+ this.fluidTank.drain(amount, true);
+ }
+ }
+ }
+ }
+ }
+ }
+ if(this.fluidTank.getFluid()!=null && (visibleFluidId!=this.fluidTank.getFluid().getFluid().getID() || Math.abs(visibleFluidAmount-this.fluidTank.getFluidAmount())>20))
+ {
+ visibleFluidId = this.fluidTank.getFluid().getFluid().getID();
+ visibleFluidAmount = this.fluidTank.getFluidAmount();
+ IC2.network.get().updateTileEntityField(this, "visibleFluidId");
+ IC2.network.get().updateTileEntityField(this, "visibleFluidAmount");
+ }
+ else if(this.fluidTank.getFluid()==null && visibleFluidId!=-1)
+ {
+ visibleFluidId=-1;
+ IC2.network.get().updateTileEntityField(this, "visibleFluidId");
+ }
+ }
+ }
+
+ private boolean checkCorrectPlacing()
+ {
+ int xz[]={0,1,0,-1,0};
+ Block block, block2;
+ int meta,meta2;
+ for(int i =0;i<=3;i++)
+ {
+ block=worldObj.getBlock(xCoord+xz[i], yCoord, zCoord+xz[i+1]);
+ meta=worldObj.getBlockMetadata(xCoord+xz[i], yCoord, zCoord+xz[i+1]);
+ block2=worldObj.getBlock(xCoord+xz[i], yCoord+1, zCoord+xz[i+1]);
+ meta2=worldObj.getBlockMetadata(xCoord+xz[i], yCoord+1, zCoord+xz[i+1]);
+ if(
+ meta>0 &&
+ meta2>0 &&
+ (block==IHLMod.ic2Wood||block==IHLMod.rubberTreeBlock) &&
+ (block2==IHLMod.ic2Wood||block2==IHLMod.rubberTreeBlock)
+ )
+ {
+ short newFacing = this.getFacingFromXZ(xz[i], xz[i+1]);
+ this.setFacing(newFacing);
+ if(block2==IHLMod.ic2Wood)
+ {
+ worldObj.setBlock(xCoord+xz[i], yCoord+1, zCoord+xz[i+1],IHLMod.rubberTreeBlock,newFacing,3);
+ }
+ else
+ {
+ if(newFacing!=meta2)
+ {
+ return false;
+ }
+ }
+ this.currentTree=RUBBERTREE;
+ return checkGround();
+ }
+ else if(
+ ((block==Blocks.log && meta==1) ||
+ (block==IHLMod.spruceTreeBlock && meta>0)) &&
+ ((block2==Blocks.log && meta2==1) ||
+ (block2==IHLMod.spruceTreeBlock && meta2>0))
+ )
+ {
+ short newFacing = this.getFacingFromXZ(xz[i], xz[i+1]);
+ this.setFacing(newFacing);
+ if(block2==Blocks.log)
+ {
+ worldObj.setBlock(xCoord+xz[i], yCoord+1, zCoord+xz[i+1],IHLMod.spruceTreeBlock,newFacing,3);
+ }
+ else
+ {
+ if(newFacing!=meta2)
+ {
+ return false;
+ }
+ }
+ this.currentTree=SPRUCE;
+ return checkGround();
+ }
+ }
+ return false;
+ }
+
+ private boolean checkGround()
+ {
+ Block block;
+ int meta;
+ for(int h=0; h<=this.maxLeavesHeight; h++)
+ {
+ block=worldObj.getBlock(xCoord+mX(), yCoord-h, zCoord+mZ());
+ meta=worldObj.getBlockMetadata(xCoord+mX(), yCoord-h, zCoord+mZ());
+ if(!isLogBlock(block, meta))
+ {
+ if(block==Blocks.dirt)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else if(meta<=0)
+ {
+ return false;
+ }
+ }
+ return false;
+ }
+
+ private boolean isLogBlock(Block block, int meta)
+ {
+ switch(this.currentTree)
+ {
+ case RUBBERTREE:
+ return block==IHLMod.ic2Wood || block==IHLMod.rubberTreeBlock;
+ case SPRUCE:
+ return (block==Blocks.log && meta==1) || (block==IHLMod.spruceTreeBlock && meta>0);
+ }
+ return false;
+ }
+
+ private boolean isLeavesBlock(Block block)
+ {
+ switch(this.currentTree)
+ {
+ case RUBBERTREE:
+ return block==IHLMod.ic2Leaves;
+ case SPRUCE:
+ return block==Blocks.leaves;
+ }
+ return false;
+ }
+
+ private boolean isIncisedLog(Block block)
+ {
+ switch(this.currentTree)
+ {
+ case RUBBERTREE:
+ return block==IHLMod.rubberTreeBlock;
+ case SPRUCE:
+ return block==IHLMod.spruceTreeBlock;
+ }
+ return false;
+ }
+
+ private void countRubberTreeLeaves()
+ {
+ this.leavesCounter=0;
+ int[][][] leavesMatrix=new int[this.maxLeavesWidth][this.maxLeavesWidth][this.maxLeavesHeight];
+ for(int iy=1;iy<this.maxLeavesHeight;iy++)
+ {
+ Block block=worldObj.getBlock(xCoord+mX(), yCoord+iy, zCoord+mZ());
+ int meta=worldObj.getBlockMetadata(xCoord+mX(), yCoord+iy, zCoord+mZ());
+ if(isLogBlock(block, meta)||isLeavesBlock(block))
+ {
+ if(isLeavesBlock(block))
+ {
+ this.leavesCounter+=worldObj.getLightBrightness(xCoord+mX(), yCoord+iy, zCoord+mZ());
+ }
+ else if(isIncisedLog(block) && iy>=2)
+ {
+ break;
+ }
+ for(int sign=1;sign>=-1;sign-=2)
+ {
+ for(int ix=1;ix<=2;ix++)
+ {
+
+ block=worldObj.getBlock(xCoord+mX()+ix*sign, yCoord+iy, zCoord+mZ());
+ if(isLeavesBlock(block))
+ {
+ this.leavesCounter+=worldObj.getLightBrightness(xCoord+mX()+ix*sign, yCoord+iy, zCoord+mZ());
+ leavesMatrix[2+ix*sign][2][iy-1]=1;
+ }
+ else
+ {
+ break;
+ }
+ }
+ for(int iz=1;iz<=2;iz++)
+ {
+ block=worldObj.getBlock(xCoord+mX(), yCoord+iy, zCoord+mZ()+iz*sign);
+ if(isLeavesBlock(block))
+ {
+ this.leavesCounter+=worldObj.getLightBrightness(xCoord+mX(), yCoord+iy, zCoord+mZ()+iz*sign);
+ leavesMatrix[2][2+iz*sign][iy-1]=1;
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ for(int signx=1;signx>=-1;signx-=2)
+ {
+ for(int signz=1;signz>=-1;signz-=2)
+ {
+ if(leavesMatrix[2][2+signz][iy-1]==1||leavesMatrix[2+signx][2][iy-1]==1)
+ {
+ block=worldObj.getBlock(xCoord+mX()+signx, yCoord+iy, zCoord+mZ()+signz);
+ if(isLeavesBlock(block))
+ {
+ this.leavesCounter+=worldObj.getLightBrightness(xCoord+mX()+signx, yCoord+iy, zCoord+mZ()+signz);
+ leavesMatrix[2+signx][2+signz][iy-1]=1;
+ }
+ }
+ if(leavesMatrix[2+signx*2][2][iy-1]==1||leavesMatrix[2+signx][2+signz][iy-1]==1)
+ {
+ block=worldObj.getBlock(xCoord+mX()+signx*2, yCoord+iy, zCoord+mZ()+signz);
+ if(block==IHLMod.ic2Leaves)
+ {
+ this.leavesCounter+=worldObj.getLightBrightness(xCoord+mX()+signx*2, yCoord+iy, zCoord+mZ()+signz);
+ leavesMatrix[2+signx*2][2+signz][iy-1]=1;
+ }
+ }
+ if(leavesMatrix[2][2+signz*2][iy-1]==1||leavesMatrix[2+signx][2+signz][iy-1]==1)
+ {
+ block=worldObj.getBlock(xCoord+mX()+signx, yCoord+iy, zCoord+mZ()+signz*2);
+ if(isLeavesBlock(block))
+ {
+ this.leavesCounter+=worldObj.getLightBrightness(xCoord+mX()+signx, yCoord+iy, zCoord+mZ()+signz*2);
+ leavesMatrix[2+signx][2+signz*2][iy-1]=1;
+ }
+ }
+ if(leavesMatrix[2+signx*2][2+signz][iy-1]==1||leavesMatrix[2+signx][2+signz*2][iy-1]==1)
+ {
+ block=worldObj.getBlock(xCoord+mX()+signx*2, yCoord+iy, zCoord+mZ()+signz*2);
+ if(isLeavesBlock(block))
+ {
+ this.leavesCounter+=worldObj.getLightBrightness(xCoord+mX()+signx*2, yCoord+iy, zCoord+mZ()+signz*2);
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+
+ //1.7.10 API
+ @Override
+ public boolean canDrain(ForgeDirection arg0, Fluid arg1) {
+ return true;
+ }
+
+ @Override
+ public boolean canFill(ForgeDirection arg0, Fluid arg1) {
+ return false;
+ }
+
+ @Override
+ public String getInventoryName() {
+ return "sack";
+ }
+
+ private int mX()
+ {
+ switch(this.getFacing())
+ {
+ case 4:
+ return -1;
+ case 5:
+ return 1;
+ default:
+ return 0;
+ }
+ }
+
+ private int mZ()
+ {
+ switch(this.getFacing())
+ {
+ case 3:
+ return 1;
+ case 2:
+ return -1;
+ case 4:
+ return 0;
+ case 5:
+ return 0;
+ default:
+ return -1;
+ }
+ }
+
+ private short getFacingFromXZ(int x, int z)
+ {
+ switch(x)
+ {
+ case -1:
+ return (short)4;
+ case 1:
+ return (short)5;
+ default:
+ switch(z)
+ {
+ case 1:
+ return (short)3;
+ case -1:
+ return (short)2;
+ default:
+ return (short)2;
+ }
+ }
+ }
+
+ public float getRenderLiquidLevel()
+ {
+ return (float)this.visibleFluidAmount/(float)this.fluidTank.getCapacity();
+ }
+
+ @Override
+ public boolean shouldRenderInPass(int pass)
+ {
+ return pass==0;
+ }
+
+ @Override
+ public FluidStack drain(ForgeDirection arg0, FluidStack arg1, boolean arg2)
+ {
+ if(this.canDrain(arg0, arg1.getFluid()))
+ {
+ FluidStack fStack = fluidTank.drain(arg1, arg2);
+ return fStack;
+ }
+ return null;
+ }
+
+ @Override
+ public FluidStack drain(ForgeDirection arg0, int arg1, boolean arg2)
+ {
+ if(this.canDrain(arg0, null))
+ {
+ FluidStack fStack = fluidTank.drain(arg1, arg2);
+ return fStack;
+ }
+ return null;
+ }
+
+ @Override
+ public int fill(ForgeDirection arg0, FluidStack arg1, boolean arg2) {
+ return 0;
+ }
+
+ @Override
+ public FluidTankInfo[] getTankInfo(ForgeDirection arg0) {
+ return new FluidTankInfo[]{this.fluidTank.getInfo()};
+ }
+} \ No newline at end of file