From 0427ab89f1753a44b30cbc35ce021cbbdc845109 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Thu, 10 Aug 2017 18:52:45 +0300 Subject: fix missing source folder --- .../java/ihl/crop_harvestors/BlobEntityFX.java | 84 +++ .../java/ihl/crop_harvestors/BlobRenderFX.java | 64 +++ .../java/ihl/crop_harvestors/RubberTreeBlock.java | 165 ++++++ src/main/java/ihl/crop_harvestors/SackBlock.java | 169 ++++++ src/main/java/ihl/crop_harvestors/SackModel.java | 103 ++++ src/main/java/ihl/crop_harvestors/SackRender.java | 95 ++++ .../java/ihl/crop_harvestors/SackTileEntity.java | 569 +++++++++++++++++++++ 7 files changed, 1249 insertions(+) create mode 100644 src/main/java/ihl/crop_harvestors/BlobEntityFX.java create mode 100644 src/main/java/ihl/crop_harvestors/BlobRenderFX.java create mode 100644 src/main/java/ihl/crop_harvestors/RubberTreeBlock.java create mode 100644 src/main/java/ihl/crop_harvestors/SackBlock.java create mode 100644 src/main/java/ihl/crop_harvestors/SackModel.java create mode 100644 src/main/java/ihl/crop_harvestors/SackRender.java create mode 100644 src/main/java/ihl/crop_harvestors/SackTileEntity.java (limited to 'src/main/java/ihl/crop_harvestors') diff --git a/src/main/java/ihl/crop_harvestors/BlobEntityFX.java b/src/main/java/ihl/crop_harvestors/BlobEntityFX.java new file mode 100644 index 0000000..60a3ad9 --- /dev/null +++ b/src/main/java/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/src/main/java/ihl/crop_harvestors/BlobRenderFX.java b/src/main/java/ihl/crop_harvestors/BlobRenderFX.java new file mode 100644 index 0000000..ed54869 --- /dev/null +++ b/src/main/java/ihl/crop_harvestors/BlobRenderFX.java @@ -0,0 +1,64 @@ +package ihl.crop_harvestors; + +import org.lwjgl.opengl.GL11; + +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; + +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/src/main/java/ihl/crop_harvestors/RubberTreeBlock.java b/src/main/java/ihl/crop_harvestors/RubberTreeBlock.java new file mode 100644 index 0000000..9cfdea1 --- /dev/null +++ b/src/main/java/ihl/crop_harvestors/RubberTreeBlock.java @@ -0,0 +1,165 @@ +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) + { + 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) + { + 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/src/main/java/ihl/crop_harvestors/SackBlock.java b/src/main/java/ihl/crop_harvestors/SackBlock.java new file mode 100644 index 0000000..7972dc1 --- /dev/null +++ b/src/main/java/ihl/crop_harvestors/SackBlock.java @@ -0,0 +1,169 @@ +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"); + } + + @SuppressWarnings("rawtypes") + @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/src/main/java/ihl/crop_harvestors/SackModel.java b/src/main/java/ihl/crop_harvestors/SackModel.java new file mode 100644 index 0000000..a0fe780 --- /dev/null +++ b/src/main/java/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/src/main/java/ihl/crop_harvestors/SackRender.java b/src/main/java/ihl/crop_harvestors/SackRender.java new file mode 100644 index 0000000..31798b4 --- /dev/null +++ b/src/main/java/ihl/crop_harvestors/SackRender.java @@ -0,0 +1,95 @@ +package ihl.crop_harvestors; +import org.lwjgl.opengl.GL11; + +import ihl.IHLModInfo; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fluids.FluidRegistry; + +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/src/main/java/ihl/crop_harvestors/SackTileEntity.java b/src/main/java/ihl/crop_harvestors/SackTileEntity.java new file mode 100644 index 0000000..800b2c5 --- /dev/null +++ b/src/main/java/ihl/crop_harvestors/SackTileEntity.java @@ -0,0 +1,569 @@ +package ihl.crop_harvestors; + +import java.util.List; +import java.util.Random; + +import ic2.core.IC2; +import ic2.core.block.TileEntityInventory; +import ihl.IHLMod; +import ihl.utils.IHLFluidTank; +import ihl.utils.IHLUtils; +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; + +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 getNetworkedFields() + { + List 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(IHLUtils.isBlockRegisteredInOreDictionaryAs(block, "blockDirt")) + { + 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=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 -- cgit v1.2.3