Added drop inv to BlockMachine

And somehow all the API files decided they wanted to binary change
This commit is contained in:
DarkGuardsman 2013-08-14 13:28:37 -04:00
parent f23060f0c1
commit bbf5b92bec
4 changed files with 96 additions and 35 deletions

View file

@ -1,8 +1,14 @@
package dark.core.blocks;
import java.util.Random;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
@ -17,7 +23,7 @@ import dark.core.DarkMain;
/** Basic TileEntity Container class designed to be used by generic machines. It is suggested that
* each mod using this create there own basic block extending this to reduce need to input config
* file each time
*
*
* @author Rseifert */
public abstract class BlockMachine extends BlockAdvanced implements ITileEntityProvider
{
@ -96,8 +102,53 @@ public abstract class BlockMachine extends BlockAdvanced implements ITileEntityP
return tileentity != null ? tileentity.receiveClientEvent(blockID, eventID) : false;
}
public void dropEntireInventory(World par1World, int x, int y, int z, int par5, int par6)
public void dropEntireInventory(World world, int x, int y, int z, int par5, int par6)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity != null)
{
if (tileEntity instanceof IInventory)
{
IInventory inventory = (IInventory) tileEntity;
for (int slot = 0; slot < inventory.getSizeInventory(); ++slot)
{
ItemStack itemStack = inventory.getStackInSlot(slot);
if (itemStack != null)
{
float deltaX = world.rand.nextFloat() * 0.8F + 0.1F;
float deltaY = world.rand.nextFloat() * 0.8F + 0.1F;
float deltaZ = world.rand.nextFloat() * 0.8F + 0.1F;
while (itemStack.stackSize > 0)
{
int stackSplit = world.rand.nextInt(21) + 10;
if (stackSplit > itemStack.stackSize)
{
stackSplit = itemStack.stackSize;
}
itemStack.stackSize -= stackSplit;
EntityItem entityItem = new EntityItem(world, (x + deltaX), (y + deltaY), (z + deltaZ), new ItemStack(itemStack.itemID, stackSplit, itemStack.getItemDamage()));
if (itemStack.hasTagCompound())
{
entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
}
float var13 = 0.05F;
entityItem.motionX = ((float) world.rand.nextGaussian() * var13);
entityItem.motionY = ((float) world.rand.nextGaussian() * var13 + 0.2F);
entityItem.motionZ = ((float) world.rand.nextGaussian() * var13);
world.spawnEntityInWorld(entityItem);
}
}
}
}
}
}
}

View file

@ -14,7 +14,7 @@ public class InvChest implements IInvBox
/** Access able slots side all */
protected int[] openSlots;
/** Items contained in this inv */
protected ItemStack[] items;
protected ItemStack[] containedItems;
/** Host tileEntity */
protected TileEntity hostTile;
/** Host tileEntity as external inv */
@ -43,30 +43,30 @@ public class InvChest implements IInvBox
@Override
public ItemStack getStackInSlot(int slot)
{
return this.items[slot];
return this.getContainedItems()[slot];
}
@Override
public ItemStack decrStackSize(int slot, int ammount)
{
if (this.items[slot] != null)
if (this.getContainedItems()[slot] != null)
{
ItemStack var3;
if (this.items[slot].stackSize <= ammount)
if (this.getContainedItems()[slot].stackSize <= ammount)
{
var3 = this.items[slot];
this.items[slot] = null;
var3 = this.getContainedItems()[slot];
this.getContainedItems()[slot] = null;
this.onInventoryChanged();
return var3;
}
else
{
var3 = this.items[slot].splitStack(ammount);
var3 = this.getContainedItems()[slot].splitStack(ammount);
if (this.items[slot].stackSize == 0)
if (this.getContainedItems()[slot].stackSize == 0)
{
this.items[slot] = null;
this.getContainedItems()[slot] = null;
}
this.onInventoryChanged();
@ -82,10 +82,10 @@ public class InvChest implements IInvBox
@Override
public ItemStack getStackInSlotOnClosing(int par1)
{
if (this.items[par1] != null)
if (this.getContainedItems()[par1] != null)
{
ItemStack var2 = this.items[par1];
this.items[par1] = null;
ItemStack var2 = this.getContainedItems()[par1];
this.getContainedItems()[par1] = null;
return var2;
}
else
@ -97,7 +97,7 @@ public class InvChest implements IInvBox
@Override
public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
{
this.items[par1] = par2ItemStack;
this.getContainedItems()[par1] = par2ItemStack;
if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
{
@ -188,45 +188,44 @@ public class InvChest implements IInvBox
@Override
public ItemStack[] getContainedItems()
{
if (this.items == null)
if (this.containedItems == null)
{
this.items = new ItemStack[this.getSizeInventory()];
this.containedItems = new ItemStack[this.getSizeInventory()];
}
return this.items;
return this.containedItems;
}
@Override
public void saveInv(NBTTagCompound nbt)
{
NBTTagList var2 = new NBTTagList();
for (int var3 = 0; var3 < this.items.length; ++var3)
NBTTagList itemList = new NBTTagList();
for (int s = 0; s < this.getContainedItems().length; ++s)
{
if (this.items[var3] != null)
if (this.getContainedItems()[s] != null)
{
NBTTagCompound var4 = new NBTTagCompound();
var4.setByte("Slot", (byte) var3);
this.items[var3].writeToNBT(var4);
var2.appendTag(var4);
NBTTagCompound tag = new NBTTagCompound();
tag.setByte("Slot", (byte) s);
this.getContainedItems()[s].writeToNBT(tag);
itemList.appendTag(tag);
}
}
nbt.setTag("Items", var2);
nbt.setTag("Items", itemList);
}
@Override
public void loadInv(NBTTagCompound nbt)
{
// chest inv reading
NBTTagList var2 = nbt.getTagList("Items");
this.items = new ItemStack[this.getSizeInventory()];
NBTTagList itemList = nbt.getTagList("Items");
for (int var3 = 0; var3 < var2.tagCount(); ++var3)
for (int s = 0; s < itemList.tagCount(); ++s)
{
NBTTagCompound var4 = (NBTTagCompound) var2.tagAt(var3);
int var5 = var4.getByte("Slot") & 255;
NBTTagCompound tag = (NBTTagCompound) itemList.tagAt(s);
int slotID = tag.getByte("Slot") & 255;
if (var5 >= 0 && var5 < this.items.length)
if (slotID >= 0 && slotID < this.getContainedItems().length)
{
this.items[var5] = ItemStack.loadItemStackFromNBT(var4);
this.getContainedItems()[slotID] = ItemStack.loadItemStackFromNBT(tag);
}
}

View file

@ -15,13 +15,13 @@ public class ItemBasic extends Item
public ItemBasic(int itemID, String name, Configuration config)
{
super(config.getItem(name, itemID).getInt());
this.setUnlocalizedName(DarkMain.getInstance().PREFIX + name);
this.setUnlocalizedName(name);
}
@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IconRegister iconRegister)
{
this.itemIcon = iconRegister.registerIcon(this.getUnlocalizedName().replace("item.", ""));
this.itemIcon = iconRegister.registerIcon(DarkMain.getInstance().PREFIX + this.getUnlocalizedName().replace("item.", ""));
}
}

View file

@ -1,6 +1,10 @@
package dark.core.items;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.core.DarkMain;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -18,6 +22,13 @@ public class ItemWrench extends ItemBasic implements IToolWrench
this.setCreativeTab(CreativeTabs.tabTools);
}
@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IconRegister iconRegister)
{
this.itemIcon = iconRegister.registerIcon(DarkMain.getInstance().PREFIX + "wrench");
}
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer entityPlayer, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
{