added pre-fab machines

This commit is contained in:
Robert Seifert 2013-04-30 15:51:12 -04:00
parent 7b8fa4258c
commit 2994c5240b
2 changed files with 265 additions and 0 deletions

View file

@ -0,0 +1,159 @@
package dark.library.machine;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import universalelectricity.prefab.tile.TileEntityElectricityRunnable;
public abstract class TileEntityBasicMachine extends TileEntityElectricityRunnable implements ISidedInventory, net.minecraftforge.common.ISidedInventory
{
int players = 0;
int invSize = 1;
ItemStack[] containingItems = new ItemStack[invSize];
@Override
public int getSizeInventory()
{
return this.containingItems.length;
}
@Override
public ItemStack getStackInSlot(int slot)
{
return this.containingItems[slot];
}
@Override
public ItemStack decrStackSize(int slot, int ammount)
{
if (this.containingItems[slot] != null)
{
ItemStack itemstack;
if (this.containingItems[slot].stackSize <= ammount)
{
itemstack = this.containingItems[slot];
this.containingItems[slot] = null;
return itemstack;
}
else
{
itemstack = this.containingItems[slot].splitStack(ammount);
if (this.containingItems[slot].stackSize == 0)
{
this.containingItems[slot] = null;
}
return itemstack;
}
}
else
{
return null;
}
}
@Override
public ItemStack getStackInSlotOnClosing(int slot)
{
if (this.containingItems[slot] != null)
{
ItemStack itemstack = this.containingItems[slot];
this.containingItems[slot] = null;
return itemstack;
}
else
{
return null;
}
}
@Override
public void setInventorySlotContents(int slot, ItemStack itemstack)
{
this.containingItems[slot] = itemstack;
if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit())
{
itemstack.stackSize = this.getInventoryStackLimit();
}
}
@Override
public String getInvName()
{
return "container.machine";
}
@Override
public boolean isInvNameLocalized()
{
return false;
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
NBTTagList nbttaglist = nbt.getTagList("Items");
this.containingItems = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i);
byte b0 = nbttagcompound1.getByte("Slot");
if (b0 >= 0 && b0 < this.containingItems.length)
{
this.containingItems[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.containingItems.length; ++i)
{
if (this.containingItems[i] != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte) i);
this.containingItems[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
}
nbt.setTag("Items", nbttaglist);
}
@Override
public int getInventoryStackLimit()
{
return 64;
}
/**
* Do not make give this method the name canInteractWith because it clashes with Container
*/
public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
{
return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 64.0D;
}
public void openChest()
{
this.players++;
}
public void closeChest()
{
this.players--;
}
}

View file

@ -0,0 +1,106 @@
package dark.library.machine;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.ForgeDummyContainer;
public abstract class TileEntityProcessMachine extends TileEntityBasicMachine
{
int[] TOP_SLOTS = { 0 };
int[] WEST_SLOTS = { 1 };
int[] EAST_SLOTS = { 1 };
int[] NORTH_SLOTS = { 1 };
int[] SOUTH_SLOTS = { 1 };
int[] BOTTOM_SLOTS = { 2 };
@Override
public int[] getSizeInventorySide(int side)
{
ForgeDirection direction = ForgeDirection.getOrientation(side);
switch (direction)
{
case UP:
return TOP_SLOTS;
case NORTH:
return NORTH_SLOTS;
case SOUTH:
return SOUTH_SLOTS;
case EAST:
return EAST_SLOTS;
case WEST:
return WEST_SLOTS;
case DOWN:
return BOTTOM_SLOTS;
}
return null;
}
@Override
public boolean func_102007_a(int par1, ItemStack par2ItemStack, int par3)
{
return this.isStackValidForSlot(par1, par2ItemStack);
}
@Override
public boolean func_102008_b(int i, ItemStack itemstack, int j)
{
return this.isStackValidForSlot(i, itemstack);
}
@Override
public boolean isStackValidForSlot(int side, ItemStack itemstack)
{
return side == 2 ? false : (side == 1 ? isItemFuel(itemstack) : true);
}
@Override
public int getStartInventorySide(ForgeDirection side)
{
if (ForgeDummyContainer.legacyFurnaceSides)
{
if (side == ForgeDirection.DOWN)
return 1;
if (side == ForgeDirection.UP)
return 0;
return 2;
}
else
{
if (side == ForgeDirection.DOWN)
return 2;
if (side == ForgeDirection.UP)
return 0;
return 1;
}
}
@Override
public int getSizeInventorySide(ForgeDirection side)
{
switch (side)
{
case UP:
return TOP_SLOTS != null ? TOP_SLOTS.length : 0;
case NORTH:
return NORTH_SLOTS != null ? NORTH_SLOTS.length : 0;
case SOUTH:
return SOUTH_SLOTS != null ? SOUTH_SLOTS.length : 0;
case EAST:
return EAST_SLOTS != null ? EAST_SLOTS.length : 0;
case WEST:
return WEST_SLOTS != null ? WEST_SLOTS.length : 0;
case DOWN:
return BOTTOM_SLOTS != null ? BOTTOM_SLOTS.length : 0;
}
return 0;
}
/**
* Return true if item is a fuel source (getItemBurnTime() > 0).
*/
public static boolean isItemFuel(ItemStack itemstack)
{
return TileEntityFurnace.getItemBurnTime(itemstack) > 0;
}
}