Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.vognersmods.fleshworks;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Random;
- import org.apache.logging.log4j.Level;
- import org.apache.logging.log4j.LogManager;
- import org.apache.logging.log4j.Logger;
- import cpw.mods.fml.common.FMLLog;
- import cpw.mods.fml.common.registry.GameRegistry;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import net.minecraft.block.Block;
- import net.minecraft.block.material.Material;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.effect.EntityLightningBolt;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.init.Items;
- import net.minecraft.inventory.ISidedInventory;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemBlock;
- import net.minecraft.item.ItemHoe;
- import net.minecraft.item.ItemStack;
- import net.minecraft.item.ItemSword;
- import net.minecraft.item.ItemTool;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.nbt.NBTTagList;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.AxisAlignedBB;
- import net.minecraft.world.World;
- public class TileEntityBolus extends TileEntity implements ISidedInventory {
- public Logger logger = LogManager.getLogger();
- public ItemStack[] bolusItemStacks = new ItemStack[18];
- public int furnaceBurnTime;
- /** The number of ticks that a fresh copy of the currently-burning item would keep the furnace burning for */
- public int currentItemBurnTime = 300;
- /** The number of ticks that the current item has been cooking for */
- public int furnaceCookTime;
- public int field_145926_a;
- public float field_145933_i;
- public float field_145931_j;
- public float field_145932_k;
- public float field_145929_l;
- public float field_145930_m;
- public float field_145927_n;
- public float field_145928_o;
- public float field_145925_p;
- public float field_145924_q;
- private static Random rand = new Random();//field_145923_r
- EntityPlayer entityplayer;
- public boolean atRest;
- int ticker = 0;//used to time texture animation
- boolean canGrumble;
- public TileEntityBolus(World world, int meta){
- this.blockMetadata = meta;
- this.worldObj = world;
- if(world.isRemote){
- switch(meta){
- case 2: {
- this.field_145924_q = -1.57F;//CORRECT-ISH
- //System.out.println("-1.57, " + meta);
- break;
- }
- case 3:{
- this.field_145924_q = 1.57F;//CORRECT-ISH
- //System.out.println("1.57, " + meta);
- break;
- }
- case 4: {
- this.field_145924_q = 3.14F;//CORRECT-ISH
- //System.out.println("3.14, " + meta);
- break;
- }
- case 5: {
- this.field_145924_q = 0.0F; //CORRECT, with the other values it jerks from 0.0 to the value I specified
- //System.out.println("0.0, " + meta);
- break;
- }
- default:
- System.out.println("TEBolus: Unexpeected metadata, " + meta);
- break;
- }
- }
- //remove lightning rod
- this.worldObj.setBlockToAir(xCoord, yCoord+1, zCoord);
- this.worldObj.setBlockToAir(xCoord, yCoord+2, zCoord);
- }
- public TileEntityBolus(){
- //nullary constructor necessary for FML reflection
- }
- @Override
- public void updateEntity(){
- super.updateEntity();
- /*for(int i = 0; i < bolusItemStacks.length; i++){
- System.out.print("slot " + i + ", ");
- if(i == 17){
- System.out.print("\n");
- }
- if(bolusItemStacks[i] != null){
- System.out.println("\n\n\n\nNon-null item stack found: \n\n\n\n" + bolusItemStacks[i].getDisplayName());
- }
- }*/
- this.field_145927_n = this.field_145930_m;
- this.field_145925_p = this.field_145928_o;
- entityplayer = this.worldObj.getClosestPlayer((double)((float)this.xCoord + 0.5F), (double)((float)this.yCoord + 0.5F), (double)((float)this.zCoord + 0.5F), 6.0D);
- if (entityplayer != null) {
- if(canGrumble){
- grumble();
- canGrumble = false;
- }
- atRest = false;
- double d0 = entityplayer.posX - (double)((float)this.xCoord + 0.5F);//difference between
- double d1 = entityplayer.posZ - (double)((float)this.zCoord + 0.5F);
- this.field_145924_q = (float)Math.atan2(d1, d0);//probable rotation angle
- } else {
- if(!canGrumble)
- canGrumble = true;
- atRest = true;
- if(worldObj.isRemote){
- switch(getBlockMetadata()){
- case 2: {
- field_145924_q = -1.57F;
- break;
- }
- case 3: {
- field_145924_q = 1.57F;
- break;
- }
- case 4: {
- field_145924_q = 3.14F;
- break;
- }
- case 5: {
- field_145924_q = 0.0F;
- break;
- }
- default:
- System.out.println("Unexpected metadata: " + getBlockMetadata());
- break;
- }
- }
- }
- if(atRest){ //close eye
- if(ticker >= 0){
- ticker--;
- }
- } else { //open eye
- if(ticker <= 2){
- ticker++;
- }
- }
- //begin wrap-arounds
- while (this.field_145928_o >= (float)Math.PI)
- {
- this.field_145928_o -= ((float)Math.PI * 2F);
- }
- while (this.field_145928_o < -(float)Math.PI)
- {
- this.field_145928_o += ((float)Math.PI * 2F);
- }
- while (this.field_145924_q >= (float)Math.PI)
- {
- this.field_145924_q -= ((float)Math.PI * 2F);
- }
- while (this.field_145924_q < -(float)Math.PI)
- {
- this.field_145924_q += ((float)Math.PI * 2F);
- }
- //end wrap-arounds
- float f2;
- for (f2 = this.field_145924_q - this.field_145928_o; f2 >= (float)Math.PI; f2 -= ((float)Math.PI * 2F))
- {
- ;
- }
- while (f2 < -(float)Math.PI)
- {
- f2 += ((float)Math.PI * 2F);
- }
- this.field_145928_o += f2 * 0.4F;
- ++this.field_145926_a;
- this.field_145931_j = this.field_145933_i;
- float f = (this.field_145932_k - this.field_145933_i) * 0.4F;
- float f3 = 0.2F;
- if (f < -f3)
- {
- f = -f3;
- }
- if (f > f3)
- {
- f = f3;
- }
- this.field_145929_l += (f - this.field_145929_l) * 0.9F;
- this.field_145933_i += this.field_145929_l;
- //START FURNACE-EY SHIT
- boolean flag = this.furnaceBurnTime > 0;
- boolean flag1 = false;
- if (this.furnaceBurnTime > 0)
- {
- --this.furnaceBurnTime;
- }
- if (!this.worldObj.isRemote)
- {
- if (this.furnaceBurnTime != 0 || this.bolusItemStacks[1] != null && this.bolusItemStacks[0] != null)
- {
- if (this.furnaceBurnTime == 0)
- {
- this.currentItemBurnTime = this.furnaceBurnTime = getItemBurnTime(this.bolusItemStacks[1]);
- if (this.furnaceBurnTime > 0)
- {
- flag1 = true;
- if (this.bolusItemStacks[1] != null)
- {
- --this.bolusItemStacks[1].stackSize;
- if (this.bolusItemStacks[1].stackSize == 0)
- {
- this.bolusItemStacks[1] = bolusItemStacks[1].getItem().getContainerItem(bolusItemStacks[1]);
- }
- }
- }
- }
- if (this.isBurning())
- {
- ++this.furnaceCookTime;
- if (this.furnaceCookTime == 200)
- {
- this.furnaceCookTime = 0;
- this.smeltItem();
- flag1 = true;
- }
- }
- else
- {
- this.furnaceCookTime = 0;
- }
- }
- }
- this.markDirty();
- worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
- }
- @Override
- public AxisAlignedBB getRenderBoundingBox()
- {
- AxisAlignedBB bb = INFINITE_EXTENT_AABB;
- bb = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1.6, zCoord + 1);
- return bb;
- }
- public void grumble(){
- //randomize pitch a bit at some point
- worldObj.playSound((double)xCoord, (double)yCoord, (double)zCoord, "fw:grumble", 0.2F, 1.3F, false);
- }
- // -=-=Begin furnace-like stuff//-=-=
- /**
- * Returns an integer between 0 and the passed value representing how close the current item is to being completely
- * cooked
- */
- @SideOnly(Side.CLIENT)
- public int getCookProgressScaled(int p_145953_1_)
- {
- return this.furnaceCookTime * p_145953_1_ / 200;
- }
- /**
- * Returns an integer between 0 and the passed value representing how much burn time is left on the current fuel
- * item, where 0 means that the item is exhausted and the passed value means that the item is fresh
- */
- @SideOnly(Side.CLIENT)
- public int getBurnTimeRemainingScaled(int p_145955_1_)
- {
- if (this.currentItemBurnTime == 0)
- {
- this.currentItemBurnTime = 200;
- }
- return this.furnaceBurnTime * p_145955_1_ / this.currentItemBurnTime;
- }
- /**
- * Furnace isBurning
- */
- public boolean isBurning()
- {
- return this.furnaceBurnTime > 0;
- }
- //IF OUTPUT SLOTS ARE FULL, THROW RESULT ON GROUND
- public ItemStack smeltItem(){
- System.out.println("\nSMELTING RESULT CHECKING IN\n");
- return null;
- }
- /**
- * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't
- * fuel
- *
- * In short, any kind of meaty mob drop will work.
- *
- * Flesh blocks only burn for 1/4 of the time as one of these items as the bolus has already eaten them once.
- * Cooked meat is only half as effective.
- *
- *
- */
- public static int getItemBurnTime(ItemStack itemStack)
- {
- if (itemStack == null)
- {
- return 0;
- }
- else
- {
- Item item = itemStack.getItem();
- if (item instanceof ItemBlock && Block.getBlockFromItem(item) != FleshWorks.blockFlesh || item instanceof ItemBlock && Block.getBlockFromItem(item) != FleshWorks.blockBolus )
- {
- return 75;
- }
- //raw: , spider eye, raw pork, raw beef, raw fish, raw chicken, slimeball RETURN 300
- if (item == Items.rotten_flesh) return 300;
- if (item == Items.spider_eye) return 300;
- if (item == Items.porkchop) return 300;
- if (item == Items.beef) return 300;
- if (item == Items.fish) return 300;
- if (item == Items.chicken) return 300;
- if (item == Items.slime_ball) return 300;
- //cooked: chicken, fish, steak RETURN 150
- if (item == Items.cooked_beef) return 150;
- if (item == Items.cooked_chicken) return 150;
- if (item == Items.cooked_fished) return 150;
- if (item == Items.cooked_porkchop) return 150;
- return 0;
- }
- }
- public void readFromNBT(NBTTagCompound saveData)
- {
- super.readFromNBT(saveData);
- System.out.println("\n\t\tREAD CHECKING IN\n");
- NBTTagList nbttaglist = saveData.getTagList("Items", 10);
- this.bolusItemStacks = new ItemStack[this.getSizeInventory()];
- for (int i = 0; i < nbttaglist.tagCount(); ++i)
- {
- NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
- byte b0 = nbttagcompound1.getByte("Slot");
- if (b0 >= 0 && b0 < this.bolusItemStacks.length)
- {
- this.bolusItemStacks[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
- if(bolusItemStacks[b0] == null){
- System.out.println("Reading NULL item stack " + b0 + ",\t");
- } else {
- System.out.println("Reading item stack " + b0 + ", " + bolusItemStacks[b0].getDisplayName() + ",\t");
- }
- }
- }
- this.furnaceBurnTime = saveData.getShort("BurnTime");
- this.furnaceCookTime = saveData.getShort("CookTime");
- }
- public void writeToNBT(NBTTagCompound saveData)
- {
- super.writeToNBT(saveData);
- System.out.println("\n\t\tWRITE CHECKING IN\n");
- saveData.setShort("BurnTime", (short)this.furnaceBurnTime);
- saveData.setShort("CookTime", (short)this.furnaceCookTime);
- NBTTagList nbttaglist = new NBTTagList();
- for (int i = 0; i < this.bolusItemStacks.length; ++i)
- {
- if(bolusItemStacks[i] == null){
- System.out.println("Saving NULL item stack " + i + ",\t");
- } else {
- System.out.println("Saving item stack " + i + ", " + bolusItemStacks[i].getDisplayName() + ",\t");
- }
- if (this.bolusItemStacks[i] != null)
- {
- System.out.println("Saving " + this.bolusItemStacks[i].getDisplayName());
- NBTTagCompound nbttagcompound1 = new NBTTagCompound();
- nbttagcompound1.setByte("Slot", (byte)i);
- this.bolusItemStacks[i].writeToNBT(nbttagcompound1);
- nbttaglist.appendTag(nbttagcompound1);
- }
- }
- saveData.setTag("Items", nbttaglist);
- }
- public static boolean isItemFuel(ItemStack p_145954_0_)
- {
- /**
- * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't
- * fuel
- */
- return getItemBurnTime(p_145954_0_) > 0;
- }
- /*
- * ISidedInventory start
- *
- * I've disabled all automation-related things. Most automation (aside from feeding it) is simply not practical
- * due to the effect it has on its surroundings.
- *
- * */
- @Override
- public int getSizeInventory() {
- return this.bolusItemStacks.length;
- }
- @Override
- public ItemStack getStackInSlot(int p_70301_1_) {
- return this.bolusItemStacks[p_70301_1_];
- }
- @Override
- /**
- * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a
- * new stack.
- */
- public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_)
- {
- if (this.bolusItemStacks[p_70298_1_] != null)
- {
- ItemStack itemstack;
- if (this.bolusItemStacks[p_70298_1_].stackSize <= p_70298_2_)
- {
- itemstack = this.bolusItemStacks[p_70298_1_];
- this.bolusItemStacks[p_70298_1_] = null;
- return itemstack;
- }
- else
- {
- itemstack = this.bolusItemStacks[p_70298_1_].splitStack(p_70298_2_);
- if (this.bolusItemStacks[p_70298_1_].stackSize == 0)
- {
- this.bolusItemStacks[p_70298_1_] = null;
- }
- return itemstack;
- }
- }
- else
- {
- return null;
- }
- }
- @Override
- public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
- if (this.bolusItemStacks[p_70304_1_] != null)
- {
- ItemStack itemstack = this.bolusItemStacks[p_70304_1_];
- //this.bolusItemStacks[p_70304_1_] = null;
- return itemstack;
- }
- else
- {
- return null;
- }
- }
- @Override
- /**
- * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
- */
- public void setInventorySlotContents(int slotIndex, ItemStack itemStack)
- {
- this.bolusItemStacks[slotIndex] = itemStack;
- if (itemStack != null)
- {
- System.out.println("\n\tSlot " + slotIndex + " getting filled with " + itemStack.getDisplayName() + "; double check: this.bolusItemStacks[slotIndex].getDisplayName()..." + this.bolusItemStacks[slotIndex].getDisplayName());
- } else {
- System.out.println("SETTING NULL ITEM TO SLOT " + slotIndex);
- }
- if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit())
- {
- itemStack.stackSize = this.getInventoryStackLimit();
- }
- markDirty();
- worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
- }
- @Override
- public String getInventoryName() {
- return null;
- }
- @Override
- public boolean hasCustomInventoryName() {
- return false;
- }
- @Override
- public int getInventoryStackLimit() {
- return 64;
- }
- @Override
- public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
- return true;
- }
- @Override
- public void openInventory() {}
- @Override
- public void closeInventory() {}
- @Override// hm...
- public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
- return true;
- }
- @Override
- public int[] getAccessibleSlotsFromSide(int p_94128_1_) {
- return null;
- }
- @Override
- public boolean canInsertItem(int p_102007_1_, ItemStack p_102007_2_, int p_102007_3_) {
- return false;
- }
- @Override
- public boolean canExtractItem(int p_102008_1_, ItemStack p_102008_2_, int p_102008_3_) {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement