created an extends version of UniversalyRunnable

This commit is contained in:
Robert Seifert 2013-05-08 08:12:30 -04:00
parent 7f34d242cd
commit 1f2bcec549
4 changed files with 38 additions and 284 deletions

View file

@ -1,159 +0,0 @@
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

@ -1,106 +0,0 @@
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[] getAccessibleSlotsFromSide(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 canInsertItem(int par1, ItemStack par2ItemStack, int par3)
{
return this.isStackValidForSlot(par1, par2ItemStack);
}
@Override
public boolean canExtractItem(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;
}
}

View file

@ -0,0 +1,35 @@
package dark.library.machine;
import net.minecraft.nbt.NBTTagCompound;
import calclavia.lib.TileEntityUniversalRunnable;
import dark.library.PowerSystems;
public class TileEntityRunnableMachine extends TileEntityUniversalRunnable
{
/** The amount of players using the console. */
public int playersUsing = 0;
@Override
public void updateEntity()
{
if (this.wattsReceived < this.getWattBuffer() && PowerSystems.runPowerLess(PowerSystems.INDUSTRIALCRAFT, PowerSystems.BUILDCRAFT, PowerSystems.MEKANISM))
{
this.wattsReceived += Math.max(this.getWattBuffer() - this.wattsReceived, 0);
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.wattsReceived = nbt.getDouble("wattsReceived");
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setDouble("wattsReceived", this.wattsReceived);
}
}

View file

@ -24,6 +24,7 @@ import dark.library.access.AccessLevel;
import dark.library.access.UserAccess;
import dark.library.access.interfaces.ISpecialAccess;
import dark.library.access.interfaces.ITerminal;
import dark.library.machine.TileEntityRunnableMachine;
import dark.library.terminal.commands.CommandRegistry;
/**
@ -31,7 +32,7 @@ import dark.library.terminal.commands.CommandRegistry;
* @author Calclavia, DarkGuardsman
*
*/
public abstract class TileEntityTerminal extends TileEntityUniversalRunnable implements ISpecialAccess, IPacketReceiver, ITerminal
public abstract class TileEntityTerminal extends TileEntityRunnableMachine implements ISpecialAccess, IPacketReceiver, ITerminal
{
public enum PacketType
{
@ -44,29 +45,16 @@ public abstract class TileEntityTerminal extends TileEntityUniversalRunnable imp
/** A list of user access data. */
private final List<UserAccess> users = new ArrayList<UserAccess>();
/** The amount of players using the console. */
public int playersUsing = 0;
/** The amount of lines the terminal can store. */
public static final int SCROLL_SIZE = 15;
/** Used on client side to determine the scroll of the terminal. */
private int scroll = 0;
@Override
public void initiate()
{
super.initiate();
}
@Override
public void updateEntity()
{
super.updateEntity();
if (PowerSystems.runPowerLess(PowerSystems.INDUSTRIALCRAFT, PowerSystems.BUILDCRAFT, PowerSystems.MEKANISM))
{
this.wattsReceived += this.getRequest().getWatts();
}
super.updateEntity();
if (!this.worldObj.isRemote)
{
@ -315,8 +303,6 @@ public abstract class TileEntityTerminal extends TileEntityUniversalRunnable imp
{
super.readFromNBT(nbt);
this.wattsReceived = nbt.getDouble("wattsReceived");
// Read user list
this.users.clear();
@ -334,8 +320,6 @@ public abstract class TileEntityTerminal extends TileEntityUniversalRunnable imp
{
super.writeToNBT(nbt);
nbt.setDouble("wattsReceived", this.wattsReceived);
// Write user list
NBTTagList usersTag = new NBTTagList();
for (int player = 0; player < this.users.size(); ++player)