moved some prefabs to the core lib

This commit is contained in:
DarkGuardsman 2013-12-19 21:07:21 -05:00
parent fbe8f627bd
commit a6a500ddca
36 changed files with 24 additions and 2434 deletions

View file

@ -1,18 +0,0 @@
package dark.api;
/** This class should be applied to all tile entities (mainly machines) that can be disabled (by
* things like EMP, short circuit etc.).
*
* @author Calclavia */
public interface IDisableable
{
/** This is called when the tile entity is to be disabled.
*
* @param duration - The duration of the disable in ticks. */
public void onDisable(int duration);
/** Called to see if this tile entity is disabled.
*
* @return True if the tile entity is disabled. */
public boolean isDisabled();
}

View file

@ -1,25 +0,0 @@
package dark.api;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import com.dark.access.ISpecialAccess;
import dark.core.interfaces.IScroll;
/** Basic methods to make it easier to construct or interact with a terminal based tile. Recommend to
* be used by tiles that want to mimic computer command line like interfaces. As well to restrict
* access to the tile in the same way a computer would
*
* @author DarkGuardsmsan */
public interface ITerminal extends ISpecialAccess, IScroll
{
/** Gets an output of the string stored in the console. */
public List<String> getTerminalOuput();
/** Adds a string to the console. Server side only. */
public boolean addToConsole(String msg);
public boolean canUse(String node, EntityPlayer player);
}

View file

@ -1,30 +0,0 @@
package dark.api;
import java.util.Set;
import net.minecraft.entity.player.EntityPlayer;
/** Prefab for creating commands that most terminal entities can use
*
* @author DarkGuardsman */
public interface ITerminalCommand
{
/** The command has been called by a player in a terminal.
*
* @return false if the call was not supported rather than failed. Used too allow several
* commands with the same name to exist but each has its own sub calls */
public boolean called(EntityPlayer player, ITerminal terminal, String[] args);
/** Can the machine use the command. Used to prevent commands from being called on machines that
* can't support it */
public boolean canSupport(ITerminal terminal);
/** What the command starts with like /time */
public String getCommandName();
/** Used to restrict sub commands like /time day, or /time night. Will be added to the name of
* the command so a command called time will have a sub comamnd day its node will equal time.day */
public Set<String> getPermissionNodes();
public String getNode(String[] args);
}

View file

@ -1,13 +0,0 @@
package dark.core.interfaces;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.ForgeDirection;
public interface IExternalInv
{
public IInvBox getInventory();
public boolean canStore(ItemStack stack, int slot, ForgeDirection side);
public boolean canRemove(ItemStack stack, int slot, ForgeDirection side);
}

View file

@ -1,27 +0,0 @@
package dark.core.interfaces;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
/** External inventory management container for an object. Allows for most if not all inventory code
* to be removed from the tile. That is some methods will still need to remain in order to work with
* automation. As well this is not designed to replace the need for IInventory support of a tile but
* to make it easier to manage. Suggested use it to create a prefab manager for several tiles. Then
* have those tiles use the prefab as an extermal inventory manager to reduce code size per class.
*
* @author DarkGuardsman */
public interface IInvBox extends ISidedInventory
{
/** Gets the inventory array. ForgeDirection.UNKOWN must return all sides */
public ItemStack[] getContainedItems();
/** Called to save the inventory array */
public NBTTagCompound saveInv(NBTTagCompound tag);
/** Called to load the inventory array */
public void loadInv(NBTTagCompound tag);
/** Dels all the items in the inventory */
public void clear();
}

View file

@ -1,12 +0,0 @@
package dark.core.interfaces;
public interface IScroll
{
/** Scrolls the text field up or down. Client side only. Positive value will scroll the text down
* while a negative value will scroll it up. */
public void scroll(int amount);
public void setScroll(int length);
public int getScroll();
}

View file

@ -1,30 +0,0 @@
package dark.core.prefab.invgui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.tileentity.TileEntity;
/** Allows the use of a tile inv without the need for a container class
*
* @author DarkGuardsman */
public class ContainerFake extends Container
{
TileEntity entity = null;
public ContainerFake(TileEntity entity)
{
this.entity = entity;
}
@Override
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
if (entity instanceof IInventory)
{
return ((IInventory) this.entity).isUseableByPlayer(par1EntityPlayer);
}
return true;
}
}

View file

@ -1,82 +0,0 @@
package dark.core.prefab.invgui;
import java.awt.Color;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import universalelectricity.core.vector.Vector2;
import com.dark.DarkCore;
import dark.machines.CoreMachine;
/** When done should be a prefab that can be used to render a power bar on the screen
*
* @author DarkGuardsman */
public class GuiBar extends Gui
{
public static final ResourceLocation TEXTURE = new ResourceLocation(CoreMachine.getInstance().DOMAIN, DarkCore.GUI_DIRECTORY + "bar.png");
protected float currentLevel = 0;
protected float maxLevel = 10;
protected float scale = 1.0f;
protected Vector2 position;
protected Color color = Color.red;
protected boolean horizontal = true;
private final int desiredH = 240;
private final int desiredW = 427;
public GuiBar(int xx, int yy, float scale, boolean horizontal)
{
this.position = new Vector2(xx, yy);
this.scale = scale;
this.horizontal = horizontal;
}
public GuiBar setColor(Color color)
{
this.color = color;
return this;
}
/** Sets the parms for the bar that determ the length of the bar
*
* @param current - current level of the reading
* @param max - max level of the reading; */
public GuiBar setMeter(float current, float max)
{
this.currentLevel = current;
this.maxLevel = max;
return this;
}
public void draw(Minecraft minecraft)
{
GL11.glPushMatrix();
if (scale != 1.0f)
{
//With everything scaled the gui will not align like a normal one so use a scaled distance from the main GUI
ScaledResolution scaledresolution = new ScaledResolution(minecraft.gameSettings, minecraft.displayWidth, minecraft.displayHeight);
int scaleH = scaledresolution.getScaledHeight();
int scaleW = scaledresolution.getScaledWidth();
//this.drawCenteredString(minecraft.fontRenderer, "Scale - " + scaleW + "x " + scaleH + "y", 100, 100, color);
float sh = (scaleH / desiredH) / scale;
float sW = (scaleW / desiredW) / scale;
//Start drawing after everying is scaled down
GL11.glScalef(scale, scale, scale);
this.drawCenteredString(minecraft.fontRenderer, "Scale - " + scaleW + "x " + scaleH + "y", 100, 100, Color.blue.getRGB());
}
Gui.drawRect(this.position.intX(), this.position.intY(), this.position.intX() + (horizontal ? 10 : 3), this.position.intY() + (!horizontal ? 10 : 3), Color.black.getRGB());
}
}

View file

@ -1,167 +0,0 @@
package dark.core.prefab.invgui;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import universalelectricity.core.vector.Vector2;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public abstract class GuiBase extends GuiScreen
{
protected Vector2 c;
protected Vector2 guiSize = new Vector2(176, 166);
/** Adds the buttons (and other controls) to the screen in question. */
@Override
public void initGui()
{
super.initGui();
c = new Vector2((this.width - this.guiSize.intX()) / 2, (this.height - this.guiSize.intY()) / 2);
}
/** Draws the screen and all the components in it. */
@Override
public void drawScreen(int par1, int par2, float par3)
{
this.drawDefaultBackground();
int var4 = (int) this.c.x;
int var5 = (int) this.c.y;
this.drawBackgroundLayer(par1, par2, par3);
GL11.glPushMatrix();
GL11.glTranslatef(var4, var5, 0.0F);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
short var7 = 240;
short var8 = 240;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, var7 / 1.0F, var8 / 1.0F);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawForegroundLayer(par1, par2, par3);
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glPopMatrix();
super.drawScreen(par1, par2, par3);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
}
/** Draws the foreground layer for the GUI */
protected abstract void drawForegroundLayer(int var2, int var3, float var1);
/** Draws the background layer for the GUI */
protected abstract void drawBackgroundLayer(int var2, int var3, float var1);
/** Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e). */
@Override
protected void keyTyped(char x, int y)
{
if (y == 1 || y == this.mc.gameSettings.keyBindInventory.keyCode)
{
this.mc.thePlayer.closeScreen();
}
}
/** Returns true if this GUI should pause the game when it is displayed in single-player */
@Override
public boolean doesGuiPauseGame()
{
return false;
}
/** Called from the main game loop to update the screen. */
@Override
public void updateScreen()
{
super.updateScreen();
if (!this.mc.thePlayer.isEntityAlive() || this.mc.thePlayer.isDead)
{
this.mc.thePlayer.closeScreen();
}
}
public void drawTooltip(int x, int y, String... toolTips)
{
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
if (toolTips != null)
{
int var5 = 0;
int var6;
int var7;
for (var6 = 0; var6 < toolTips.length; ++var6)
{
var7 = this.fontRenderer.getStringWidth(toolTips[var6]);
if (var7 > var5)
{
var5 = var7;
}
}
var6 = x + 12;
var7 = y - 12;
int var9 = 8;
if (toolTips.length > 1)
{
var9 += 2 + (toolTips.length - 1) * 10;
}
if (this.c.intY() + var7 + var9 + 6 > this.height)
{
var7 = this.height - var9 - this.c.intY() - 6;
}
this.zLevel = 300.0F;
int var10 = -267386864;
this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10);
this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10);
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10);
this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10);
this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10);
int var11 = 1347420415;
int var12 = (var11 & 16711422) >> 1 | var11 & -16777216;
this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12);
this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12);
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11);
this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12);
for (int var13 = 0; var13 < toolTips.length; ++var13)
{
String var14 = toolTips[var13];
this.fontRenderer.drawStringWithShadow(var14, var6, var7, -1);
if (var13 == 0)
{
var7 += 2;
}
var7 += 10;
}
this.zLevel = 0.0F;
}
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_LIGHTING);
RenderHelper.enableGUIStandardItemLighting();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
}
}

View file

@ -1,89 +0,0 @@
package dark.core.prefab.invgui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import com.dark.DarkCore;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.machines.CoreMachine;
@SideOnly(Side.CLIENT)
public class GuiButtonImage extends GuiButton
{
public static final ResourceLocation TEXTURE = new ResourceLocation(CoreMachine.getInstance().DOMAIN, DarkCore.GUI_DIRECTORY + "gui_button.png");
private ButtonIcon buttonIcon = ButtonIcon.BLANK;
public GuiButtonImage(int buttonID, int xx, int yy, ButtonIcon icon)
{
super(buttonID, xx, yy, 20, 20, "");
this.buttonIcon = icon;
this.width = icon.sizeX;
this.height = icon.sizeY;
}
/** Draws this button to the screen. */
@Override
public void drawButton(Minecraft mc, int width, int hight)
{
if (this.drawButton)
{
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
boolean hovering = width >= this.xPosition && hight >= this.yPosition && width < this.xPosition + this.width && hight < this.yPosition + this.height;
int vv = buttonIcon.vv;
int uu = buttonIcon.uu;
if (hovering)
{
vv += this.height;
}
this.drawTexturedModalRect(this.xPosition, this.yPosition, this.buttonIcon.uu, this.buttonIcon.vv, this.width, this.height);
}
}
/** Checks to see if the x and y coords are intersecting with the button. */
public boolean isIntersect(int x, int y)
{
return x >= this.xPosition && y >= this.yPosition && x < this.xPosition + this.width && y < this.yPosition + this.height;
}
public static enum ButtonIcon
{
PERSON(0, 0),
ARROW_LEFT(30, 0, 10, 10),
ARROW_RIGHT(20, 0, 10, 10),
ARROW_DOWN(30, 20, 10, 10),
ARROW_UP(20, 20, 10, 10),
CHEST(60, 0),
LOCKED(80, 0),
UNLOCKED(100, 0),
BLANK(120, 0),
RED_ON(140, 0),
RED_OFF(160, 0),
FURNACE_OFF(180, 0),
FURNACE_ON(200, 0);
int vv, uu;
int sizeX = 20, sizeY = 20;
private ButtonIcon(int xx, int yy)
{
this.vv = yy;
this.uu = xx;
}
private ButtonIcon(int xx, int yy, int cx, int cy)
{
this(xx, yy);
this.sizeX = cx;
this.sizeY = cy;
}
}
}

View file

@ -1,111 +0,0 @@
package dark.core.prefab.invgui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import com.dark.DarkCore;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import dark.machines.CoreMachine;
public class GuiMessageBox extends GuiBase
{
public static final ResourceLocation TEXTURE = new ResourceLocation(CoreMachine.getInstance().DOMAIN, DarkCore.GUI_DIRECTORY + "gui_message_box.png");
GuiBase returnGuiYes, returnGuiNo;
int id;
String title;
String message;
public GuiMessageBox(GuiBase returnGui, int id, String title, String message)
{
this.guiSize.y = 380 / 2;
this.returnGuiYes = returnGui;
this.returnGuiNo = returnGui;
this.id = id;
this.title = title;
this.message = message;
}
public GuiMessageBox(GuiBase returnGui, GuiBase returnGuiNo, int id, String title, String message)
{
this(returnGui, id, title, message);
this.returnGuiNo = returnGuiNo;
}
@SuppressWarnings("unchecked")
@Override
public void initGui()
{
super.initGui();
this.buttonList.clear();
this.buttonList.add(new GuiButton(0, (this.width - this.guiSize.intX()) / 2 + 25, (this.height - this.guiSize.intY()) / 2 + 35, 50, 20, "Yes"));
this.buttonList.add(new GuiButton(1, (this.width - this.guiSize.intX()) / 2 + 80, (this.height - this.guiSize.intY()) / 2 + 35, 50, 20, "no"));
}
@Override
public void onGuiClosed()
{
super.onGuiClosed();
}
@Override
protected void actionPerformed(GuiButton button)
{
super.actionPerformed(button);
switch (button.id)
{
case 0:
this.exit(true);
break;
case 1:
this.exit(false);
break;
}
}
@Override
protected void drawForegroundLayer(int var2, int var3, float var1)
{
this.fontRenderer.drawString("" + this.title, (this.guiSize.intX() / 2 - 30), 5, 4210752);
this.fontRenderer.drawString("\u00a77" + this.message, ((this.guiSize.intX() / 2) - 50), 20, 4210752);
}
@Override
protected void drawBackgroundLayer(int var2, int var3, float var1)
{
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int containerWidth = (this.width - this.guiSize.intX()) / 2;
int containerHeight = (this.height - this.guiSize.intY()) / 2;
this.drawTexturedModalRect(containerWidth, containerHeight, 0, 0, this.guiSize.intX(), this.guiSize.intY());
}
public void show()
{
FMLCommonHandler.instance().showGuiScreen(this);
}
public void exit(boolean yes)
{
if (yes)
{
FMLCommonHandler.instance().showGuiScreen(this.returnGuiYes);
}
else
{
FMLCommonHandler.instance().showGuiScreen(this.returnGuiNo);
}
if (this.returnGuiYes instanceof IMessageBoxDialog)
{
((IMessageBoxDialog) this.returnGuiYes).onMessageBoxClosed(this.id, yes);
}
}
}

View file

@ -1,6 +0,0 @@
package dark.core.prefab.invgui;
public interface IMessageBoxDialog
{
public void onMessageBoxClosed(int id, boolean yes);
}

View file

@ -1,15 +0,0 @@
package dark.core.prefab.invgui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
/** TileEntities that wish to do something if an item is removed from a slot */
public interface ISlotPickResult
{
/** If the slot in the gui does something if the item is removed
*
* @param entityPlayer - player who removed the item, will pass null from automation
* @param slot - slot in the container class the item came from
* @param itemStack - item stack pulled from the slot */
public void onPickUpFromSlot(EntityPlayer entityPlayer, int slot, ItemStack itemStack);
}

View file

@ -1,8 +0,0 @@
package dark.core.prefab.invgui;
/** Add this to a container class if using WatchedSlot to trigger the container on slot change */
public interface ISlotWatcher
{
/** Will trigger if the watched slot has changed */
public void slotContentsChanged(int slot);
}

View file

@ -1,256 +0,0 @@
package dark.core.prefab.invgui;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import dark.core.interfaces.IExternalInv;
import dark.core.interfaces.IInvBox;
public class InvChest implements IInvBox
{
/** Access able slots side all */
protected int[] openSlots;
/** Items contained in this inv */
protected ItemStack[] containedItems;
/** Host tileEntity */
protected TileEntity hostTile;
/** Host tileEntity as external inv */
protected IExternalInv inv;
/** Default slot max count */
protected final int slots;
public InvChest(TileEntity chest, IExternalInv inv, int slots)
{
this.hostTile = chest;
this.slots = slots;
this.inv = inv;
}
public InvChest(TileEntity chest, int slots)
{
this(chest, ((IExternalInv) chest), slots);
}
public InvChest(Entity entity, int i)
{
this.slots = i;
this.inv = (IExternalInv) entity;
}
@Override
public int getSizeInventory()
{
return slots;
}
@Override
public ItemStack getStackInSlot(int slot)
{
return this.getContainedItems()[slot];
}
@Override
public ItemStack decrStackSize(int slot, int ammount)
{
if (this.getContainedItems()[slot] != null)
{
ItemStack var3;
if (this.getContainedItems()[slot].stackSize <= ammount)
{
var3 = this.getContainedItems()[slot];
this.getContainedItems()[slot] = null;
this.onInventoryChanged();
return var3;
}
else
{
var3 = this.getContainedItems()[slot].splitStack(ammount);
if (this.getContainedItems()[slot].stackSize == 0)
{
this.getContainedItems()[slot] = null;
}
this.onInventoryChanged();
return var3;
}
}
else
{
return null;
}
}
@Override
public ItemStack getStackInSlotOnClosing(int par1)
{
if (this.getContainedItems()[par1] != null)
{
ItemStack var2 = this.getContainedItems()[par1];
this.getContainedItems()[par1] = null;
return var2;
}
else
{
return null;
}
}
@Override
public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
{
this.getContainedItems()[par1] = par2ItemStack;
if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
{
par2ItemStack.stackSize = this.getInventoryStackLimit();
}
this.onInventoryChanged();
}
@Override
public String getInvName()
{
return "container.chest";
}
@Override
public void openChest()
{
}
@Override
public void closeChest()
{
}
@Override
public boolean isInvNameLocalized()
{
return false;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
if (i >= this.getSizeInventory())
{
return false;
}
return true;
}
@Override
public int[] getAccessibleSlotsFromSide(int var1)
{
if (openSlots == null || openSlots.length != this.getSizeInventory())
{
this.openSlots = new int[this.getSizeInventory()];
for (int i = 0; i < this.openSlots.length; i++)
{
openSlots[i] = i;
}
}
return this.openSlots;
}
@Override
public boolean canInsertItem(int i, ItemStack itemstack, int j)
{
return this.isItemValidForSlot(i, itemstack) && this.inv.canStore(itemstack, i, ForgeDirection.getOrientation(j));
}
@Override
public boolean canExtractItem(int i, ItemStack itemstack, int j)
{
return this.inv.canRemove(itemstack, i, ForgeDirection.getOrientation(j));
}
@Override
public int getInventoryStackLimit()
{
return 64;
}
@Override
public void onInventoryChanged()
{
if (this.hostTile != null)
{
this.hostTile.onInventoryChanged();
}
}
@Override
public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
{
if (this.hostTile != null)
{
return this.hostTile.worldObj.getBlockTileEntity(this.hostTile.xCoord, this.hostTile.yCoord, this.hostTile.zCoord) != this.hostTile ? false : par1EntityPlayer.getDistanceSq(this.hostTile.xCoord + 0.5D, this.hostTile.yCoord + 0.5D, this.hostTile.zCoord + 0.5D) <= 64.0D;
}
return true;
}
@Override
public ItemStack[] getContainedItems()
{
if (this.containedItems == null)
{
this.containedItems = new ItemStack[this.getSizeInventory()];
}
return this.containedItems;
}
@Override
public NBTTagCompound saveInv(NBTTagCompound nbt)
{
NBTTagList itemList = new NBTTagList();
for (int s = 0; s < this.getContainedItems().length; ++s)
{
if (this.getContainedItems()[s] != null)
{
NBTTagCompound tag = new NBTTagCompound();
tag.setByte("Slot", (byte) s);
this.getContainedItems()[s].writeToNBT(tag);
itemList.appendTag(tag);
}
}
nbt.setTag("Items", itemList);
return nbt;
}
@Override
public void loadInv(NBTTagCompound nbt)
{
// chest inv reading
NBTTagList itemList = nbt.getTagList("Items");
for (int s = 0; s < itemList.tagCount(); ++s)
{
NBTTagCompound tag = (NBTTagCompound) itemList.tagAt(s);
int slotID = tag.getByte("Slot") & 255;
if (slotID >= 0 && slotID < this.getContainedItems().length)
{
this.getContainedItems()[slotID] = ItemStack.loadItemStackFromNBT(tag);
}
}
}
@Override
public void clear()
{
this.containedItems = null;
this.getContainedItems();
}
}

View file

@ -1,37 +0,0 @@
package dark.core.prefab.invgui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
/** Easy class to create a slot that is used for an event trigger or crafting based event */
public class SlotCraftingResult extends WatchedSlot
{
private ISlotPickResult tile;
public SlotCraftingResult(ISlotPickResult tile, ISlotWatcher container, IInventory inventory, int par2, int par3, int par4)
{
super(inventory, par2, par3, par4, container);
this.tile = tile;
}
@Override
public boolean isItemValid(ItemStack itemStack)
{
return false;
}
@Override
public boolean canTakeStack(EntityPlayer player)
{
return true;
}
/** When the slot has changed it calls @ISlotPickResult 's method */
@Override
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack)
{
this.tile.onPickUpFromSlot(entityPlayer, this.slotNumber, itemStack);
super.onPickupFromSlot(entityPlayer, itemStack);
}
}

View file

@ -1,37 +0,0 @@
package dark.core.prefab.invgui;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
/** Slot that can only allow one itemStack into it
*
* @author DarkGuardsman */
public class SlotRestricted extends Slot
{
private ItemStack[] itemStacks;
public SlotRestricted(IInventory par1iInventory, int par2, int par3, int par4, ItemStack... itemStacks)
{
super(par1iInventory, par2, par3, par4);
this.itemStacks = itemStacks;
}
@Override
public boolean isItemValid(ItemStack itemStack)
{
if (itemStack != null && this.itemStacks != null)
{
for (int i = 0; i < itemStacks.length; i++)
{
ItemStack stack = itemStacks[i];
if (stack != null && itemStack.isItemEqual(stack))
{
return true;
}
}
}
return false;
}
}

View file

@ -1,26 +0,0 @@
package dark.core.prefab.invgui;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
/** A slot that triggers the container class if changed */
public class WatchedSlot extends Slot
{
private ISlotWatcher slotWatcher;
public WatchedSlot(IInventory inventory, int id, int xPosition, int yPosition, ISlotWatcher slotWatcher)
{
super(inventory, id, xPosition, yPosition);
this.slotWatcher = slotWatcher;
}
@Override
public void onSlotChanged()
{
if (this.slotWatcher != null)
{
this.slotWatcher.slotContentsChanged(this.slotNumber);
}
}
}

View file

@ -1,5 +1,7 @@
package dark.core.prefab.machine;
import com.dark.prefab.TileEntityEnergyMachine;
import ic2.api.item.IElectricItemManager;
import ic2.api.item.ISpecialElectricItem;
import net.minecraft.item.ItemStack;

View file

@ -1,395 +0,0 @@
package dark.core.prefab.machine;
import java.util.EnumSet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.oredict.OreDictionary;
import universalelectricity.core.block.IElectrical;
import universalelectricity.core.block.IElectricalStorage;
import universalelectricity.core.electricity.ElectricityHelper;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.grid.IElectricityNetwork;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
import com.dark.interfaces.IPowerLess;
/** Basic energy tile that can consume power
*
* Based off both UE universal electrical tile, and electrical tile prefabs
*
* @author DarkGuardsman */
public abstract class TileEntityEnergyMachine extends TileEntityMachine implements IElectrical, IElectricalStorage, IPowerLess
{
/** Forge Ore Directory name of the item to toggle infinite power mode */
public static String powerToggleItemID = "battery";
/** Demand per tick in watts */
protected float JOULES_PER_TICK;
/** Max limit of the internal battery/buffer of the machine */
protected float MAX_JOULES_STORED;
/** Current energy stored in the machine's battery/buffer */
protected float energyStored = 0;
/** Should we run without power */
private boolean runWithoutPower = true;
/** Point by which this machines suffers low voltage damage */
protected float brownOutVoltage = -1;
/** Point by which this machines suffers over voltage damage */
protected float shortOutVoltage = -1;
/** Voltage by which the machine was designed and rated for */
protected float ratedVoltage = 240;
public TileEntityEnergyMachine()
{
this.brownOutVoltage = this.getVoltage() / 2;
this.shortOutVoltage = (float) ((Math.sqrt(2) * this.getVoltage()) + 0.05 * this.getVoltage());
}
public TileEntityEnergyMachine(float wattsPerTick)
{
this();
this.JOULES_PER_TICK = wattsPerTick;
this.MAX_JOULES_STORED = wattsPerTick * 20;
}
public TileEntityEnergyMachine(float wattsPerTick, float maxEnergy)
{
this(wattsPerTick);
this.MAX_JOULES_STORED = maxEnergy;
}
@Override
public void updateEntity()
{
super.updateEntity();
if (!this.worldObj.isRemote && this.isFunctioning())
{
this.consumePower(this.JOULES_PER_TICK, true);
}
}
/** Does this tile have power to run and do work */
@Override
public boolean canFunction()
{
return super.canFunction() && (this.runPowerLess() || this.consumePower(this.JOULES_PER_TICK, false));
}
/** Called when a player activates the tile's block */
public boolean onPlayerActivated(EntityPlayer player)
{
if (player != null && player.capabilities.isCreativeMode)
{
ItemStack itemStack = player.getHeldItem();
if (itemStack != null)
{
for (ItemStack stack : OreDictionary.getOres(powerToggleItemID))
{
if (stack.isItemEqual(itemStack))
{
this.togglePowerMode();
return true;
}
}
}
}
return false;
}
/* ********************************************
* Electricity reception logic
***********************************************/
@Override
public float receiveElectricity(ForgeDirection from, ElectricityPack receive, boolean doReceive)
{
if (!this.runPowerLess() && receive != null && this.canConnect(from))
{
if (receive != null && receive.voltage > this.shortOutVoltage)
{
if (doReceive)
{
this.onDisable(20 + this.worldObj.rand.nextInt(100));
}
return 0;
}
return this.receiveElectricity(receive.getWatts(), doReceive);
}
return 0;
}
/** A non-side specific version of receiveElectricity for you to optionally use it internally. */
public float receiveElectricity(ElectricityPack receive, boolean doReceive)
{
if (receive != null)
{
float prevEnergyStored = this.getEnergyStored();
float newStoredEnergy = Math.min(this.getEnergyStored() + receive.getWatts(), this.getMaxEnergyStored());
if (doReceive)
{
this.setEnergyStored(newStoredEnergy);
}
return Math.max(newStoredEnergy - prevEnergyStored, 0);
}
return 0;
}
public float receiveElectricity(float energy, boolean doReceive)
{
return this.receiveElectricity(ElectricityPack.getFromWatts(energy, this.getVoltage()), doReceive);
}
/* ********************************************
* Electricity transmition logic
***********************************************/
/** Called to consume power from the internal storage */
public boolean consumePower(float watts, boolean doDrain)
{
if (watts <= 0)
{
return true;
}
if (!this.runPowerLess() && this.getEnergyStored() >= watts)
{
if (doDrain)
{
this.setEnergyStored(this.getEnergyStored() - watts);
}
return true;
}
return this.runPowerLess();
}
@Override
public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide)
{
if (this.getOutputDirections().contains(from))
{
return this.provideElectricity(request, doProvide);
}
return new ElectricityPack();
}
/** A non-side specific version of provideElectricity for you to optionally use it internally. */
public ElectricityPack provideElectricity(ElectricityPack request, boolean doProvide)
{
if (request != null)
{
float requestedEnergy = Math.min(request.getWatts(), this.energyStored);
if (doProvide)
{
this.setEnergyStored(this.energyStored - requestedEnergy);
}
return ElectricityPack.getFromWatts(requestedEnergy, this.getVoltage());
}
return new ElectricityPack();
}
public ElectricityPack provideElectricity(float energy, boolean doProvide)
{
return this.provideElectricity(ElectricityPack.getFromWatts(energy, this.getVoltage()), doProvide);
}
/** Produces energy on all sides */
public void produceAllSides()
{
if (!this.worldObj.isRemote)
{
for (ForgeDirection outputDirection : this.getOutputDirections())
{
if (this.getOutputDirections().contains(outputDirection))
{
this.produceDirection(outputDirection);
}
}
}
}
/** Produces energy only on the given side */
public void produceDirection(ForgeDirection outputDirection)
{
//TODO detect machines and power them if they are directly next to this machine
if (!this.worldObj.isRemote && outputDirection != null && outputDirection != ForgeDirection.UNKNOWN)
{
float provide = this.getProvide(outputDirection);
if (provide > 0)
{
TileEntity outputTile = VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), outputDirection);
IElectricityNetwork outputNetwork = ElectricityHelper.getNetworkFromTileEntity(outputTile, outputDirection);
if (outputNetwork != null)
{
ElectricityPack powerRequest = outputNetwork.getRequest(this);
if (powerRequest.getWatts() > 0)
{
ElectricityPack sendPack = ElectricityPack.min(ElectricityPack.getFromWatts(this.getEnergyStored(), this.getVoltage()), ElectricityPack.getFromWatts(provide, this.getVoltage()));
float rejectedPower = outputNetwork.produce(sendPack, this);
this.provideElectricity(sendPack.getWatts() - rejectedPower, true);
}
}
}
}
}
/* ********************************************
* Electricity connection logic
***********************************************/
@Override
public boolean canConnect(ForgeDirection direction)
{
if (direction == null || direction.equals(ForgeDirection.UNKNOWN))
{
return false;
}
return this.getInputDirections().contains(direction) || this.getOutputDirections().contains(direction);
}
/** The electrical input direction.
*
* @return The direction that electricity is entered into the tile. Return null for no input. By
* default you can accept power from all sides. */
public EnumSet<ForgeDirection> getInputDirections()
{
return EnumSet.allOf(ForgeDirection.class);
}
/** The electrical output direction.
*
* @return The direction that electricity is output from the tile. Return null for no output. By
* default it will return an empty EnumSet. */
public EnumSet<ForgeDirection> getOutputDirections()
{
return EnumSet.noneOf(ForgeDirection.class);
}
/* ********************************************
* Machine energy parms
***********************************************/
@Override
public float getVoltage()
{
return this.ratedVoltage;
}
public TileEntityEnergyMachine setVoltage(float volts)
{
this.ratedVoltage = volts;
return this;
}
@Override
public float getMaxEnergyStored()
{
return this.MAX_JOULES_STORED;
}
public void setMaxEnergyStored(float energy)
{
this.MAX_JOULES_STORED = energy;
}
@Override
public void setEnergyStored(float energy)
{
this.energyStored = Math.max(Math.min(energy, this.getMaxEnergyStored()), 0);
}
@Override
public float getEnergyStored()
{
return this.energyStored;
}
@Override
public float getRequest(ForgeDirection direction)
{
return Math.max(this.getMaxEnergyStored() - this.getEnergyStored(), 0);
}
@Override
public float getProvide(ForgeDirection direction)
{
return 0;
}
@Override
public boolean runPowerLess()
{
return !runWithoutPower;
}
@Override
public void setPowerLess(boolean bool)
{
runWithoutPower = !bool;
}
public void togglePowerMode()
{
this.setPowerLess(!this.runPowerLess());
}
public TileEntityEnergyMachine setJoulesPerTick(float energy)
{
this.JOULES_PER_TICK = energy;
return this;
}
public TileEntityEnergyMachine setJoulesPerSecound(float energy)
{
this.JOULES_PER_TICK = energy / 20;
return this;
}
public TileEntityEnergyMachine setJoulesPerHour(float energy)
{
this.JOULES_PER_TICK = energy / 1200;
return this;
}
/* ********************************************
* DATA/SAVE/LOAD
***********************************************/
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.energyStored = nbt.getFloat("energyStored");
runWithoutPower = !nbt.getBoolean("shouldPower");
this.functioning = nbt.getBoolean("isRunning");
if (nbt.hasKey("wattsReceived"))
{
this.energyStored = (float) nbt.getDouble("wattsReceived");
}
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setBoolean("shouldPower", !runWithoutPower);
nbt.setFloat("energyStored", this.energyStored);
nbt.setBoolean("isRunning", this.functioning);
}
}

View file

@ -1,5 +1,7 @@
package dark.core.prefab.machine;
import com.dark.prefab.TileEntityEnergyMachine;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.electricity.ElectricityPack;

View file

@ -1,341 +0,0 @@
package dark.core.prefab.machine;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.tile.TileEntityAdvanced;
import com.dark.access.AccessGroup;
import com.dark.access.AccessUser;
import com.dark.access.GroupRegistry;
import com.dark.access.ISpecialAccess;
import com.dark.access.Nodes;
import com.dark.tilenetwork.prefab.NetworkTileEntities;
import dark.core.interfaces.IExternalInv;
import dark.core.interfaces.IInvBox;
import dark.core.prefab.invgui.InvChest;
/** Prefab for simple object who only need basic inv support and nothing more
*
* @author Darkguardsman */
public class TileEntityInv extends TileEntityAdvanced implements IExternalInv, ISidedInventory, ISpecialAccess
{
protected IInvBox inventory;
protected boolean lockInv;
protected int invSlots = 1;
private Vector3 thisPos;
/** A list of user access data. */
protected List<AccessGroup> groups = new ArrayList<AccessGroup>();
@Override
public void initiate()
{
thisPos = new Vector3(this);
}
public Vector3 getThisPos()
{
if (this.thisPos == null || this.thisPos.intX() != xCoord || this.thisPos.intY() != yCoord || this.thisPos.intZ() != zCoord)
{
this.thisPos = new Vector3(this);
}
return this.thisPos;
}
@Override
public void invalidate()
{
super.invalidate();
NetworkTileEntities.invalidate(this);
}
@Override
public IInvBox getInventory()
{
if (inventory == null)
{
inventory = new InvChest(this, this.invSlots);
}
return inventory;
}
/** Gets the container class that goes with this tileEntity when creating a gui */
public Class<? extends Container> getContainer()
{
return null;
}
@Override
public int getSizeInventory()
{
return this.getInventory().getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int i)
{
return this.getInventory().getStackInSlot(i);
}
@Override
public ItemStack decrStackSize(int i, int j)
{
return this.getInventory().decrStackSize(i, j);
}
@Override
public ItemStack getStackInSlotOnClosing(int i)
{
return this.getInventory().getStackInSlotOnClosing(i);
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack)
{
this.getInventory().setInventorySlotContents(i, itemstack);
}
@Override
public String getInvName()
{
return this.getInventory().getInvName();
}
@Override
public boolean isInvNameLocalized()
{
return this.getInventory().isInvNameLocalized();
}
@Override
public int getInventoryStackLimit()
{
return this.getInventory().getInventoryStackLimit();
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
return this.getInventory().isUseableByPlayer(entityplayer);
}
@Override
public void openChest()
{
this.getInventory().openChest();
}
@Override
public void closeChest()
{
this.getInventory().closeChest();
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
return this.getInventory().isItemValidForSlot(i, itemstack);
}
@Override
public int[] getAccessibleSlotsFromSide(int var1)
{
return this.getInventory().getAccessibleSlotsFromSide(var1);
}
@Override
public boolean canInsertItem(int i, ItemStack itemstack, int j)
{
return this.getInventory().canInsertItem(i, itemstack, j);
}
@Override
public boolean canExtractItem(int i, ItemStack itemstack, int j)
{
return this.getInventory().canExtractItem(i, itemstack, j);
}
@Override
public boolean canStore(ItemStack stack, int slot, ForgeDirection side)
{
return false;
}
@Override
public boolean canRemove(ItemStack stack, int slot, ForgeDirection side)
{
if (slot >= this.getSizeInventory())
{
return false;
}
return true;
}
/*
* User access
*/
public boolean canOpen(String username)
{
return this.getUserAccess(username) != null && this.getUserAccess(username).hasNode(Nodes.INV_OPEN_NODE) || this.getOwnerGroup().getMembers().size() <= 0;
}
@Override
public AccessUser getUserAccess(String username)
{
for (AccessGroup group : this.groups)
{
AccessUser user = group.getMember(username);
if (user != null)
{
return user;
}
}
return new AccessUser(username);
}
@Override
public List<AccessUser> getUsers()
{
List<AccessUser> users = new ArrayList<AccessUser>();
for (AccessGroup group : this.groups)
{
users.addAll(group.getMembers());
}
return users;
}
@Override
public boolean setUserAccess(String player, AccessGroup g, boolean save)
{
return setUserAccess(new AccessUser(player).setTempary(save), g);
}
@Override
public boolean setUserAccess(AccessUser user, AccessGroup group)
{
boolean bool = false;
if (user != null && user.getName() != null)
{
bool = this.removeUserAccess(user.getName()) && group == null;
if (group != null)
{
bool = group.addMemeber(user);
}
if (bool)
{
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
}
return bool;
}
public boolean removeUserAccess(String player)
{
boolean re = false;
for (AccessGroup group : this.groups)
{
AccessUser user = group.getMember(player);
if (user != null && group.removeMemeber(user))
{
re = true;
}
}
if (re)
{
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
return re;
}
@Override
public AccessGroup getGroup(String name)
{
for (AccessGroup group : this.getGroups())
{
if (group.getName().equalsIgnoreCase(name))
{
return group;
}
}
return null;
}
@Override
public boolean addGroup(AccessGroup group)
{
if (!this.groups.contains(group))
{
for (AccessGroup g : this.groups)
{
if (group.getName().equalsIgnoreCase(g.getName()))
{
return false;
}
}
return this.groups.add(group);
}
return false;
}
@Override
public AccessGroup getOwnerGroup()
{
return this.getGroup("owner");
}
@Override
public List<AccessGroup> getGroups()
{
if (this.groups == null || this.groups.isEmpty())
{
GroupRegistry.loadNewGroupSet(this);
}
return this.groups;
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.getInventory().loadInv(nbt);
NBTTagList userList = nbt.getTagList("groups");
if (userList != null && userList.tagCount() > 0)
{
this.groups.clear();
for (int i = 0; i < userList.tagCount(); i++)
{
AccessGroup group = new AccessGroup("");
group.load((NBTTagCompound) userList.tagAt(i));
this.groups.add(group);
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
this.getInventory().saveInv(nbt);
NBTTagList usersTag = new NBTTagList();
for (AccessGroup group : this.getGroups())
{
usersTag.appendTag(group.save(new NBTTagCompound()));
}
nbt.setTag("groups", usersTag);
}
}

View file

@ -1,295 +0,0 @@
package dark.core.prefab.machine;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.tile.IRotatable;
import com.dark.IExtraInfo.IExtraTileEntityInfo;
import com.dark.network.ISimplePacketReceiver;
import com.dark.network.PacketHandler;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;
import dark.api.IDisableable;
import dark.core.interfaces.IExternalInv;
import dark.core.interfaces.IInvBox;
import dark.machines.CoreMachine;
public abstract class TileEntityMachine extends TileEntityInv implements ISidedInventory, IExternalInv, IDisableable, ISimplePacketReceiver, IRotatable, IExtraTileEntityInfo
{
/** Tick by which this machine stops working */
protected int disabledTicks = 0;
/** Number of players with the machine's gui container open */
protected int playersUsingMachine = 0;
/** Is the machine functioning normally */
protected boolean functioning = false;
/** Prev state of function of last update */
protected boolean prevFunctioning = false;
/** Does the machine have a gui */
protected boolean hasGUI = false;
/** Does teh machine rotate in meta groups of four */
protected boolean rotateByMetaGroup = false;
/** Can the machine be temp disabled */
protected boolean canBeDisabled = false;
/** Is the machine enabled by the player */
protected boolean enabled = true;
/** Is the machine locked by the player */
protected boolean locked = false;
/** Inventory manager used by this machine */
protected IInvBox inventory;
/** Default generic packet types used by all machines */
public static enum SimplePacketTypes
{
/** Normal packet data of any kind */
GENERIC("generic"),
/** Power updates */
RUNNING("isRunning"),
/** GUI display data update */
GUI("guiGeneral"),
/** Full tile read/write data from tile NBT */
NBT("nbtAll"),
GUI_EVENT("clientGui"),
GUI_COMMAND("clientCommand"),
TERMINAL_OUTPUT("serverTerminal");
public String name;
private SimplePacketTypes(String name)
{
this.name = name;
}
}
@Override
public void updateEntity()
{
super.updateEntity();
if (!this.worldObj.isRemote)
{
this.prevFunctioning = this.functioning;
this.functioning = this.isFunctioning();
if (prevFunctioning != this.functioning)
{
this.sendPowerUpdate();
}
this.sendGUIPacket();
}
if (this.disabledTicks > 0)
{
this.disabledTicks--;
this.whileDisable();
}
}
/** Can this tile function, or run threw normal processes */
public boolean canFunction()
{
return !this.isDisabled() && this.enabled;
}
public boolean isFunctioning()
{
if (this.worldObj.isRemote)
{
return this.functioning;
}
else
{
return this.canFunction();
}
}
public void doRunningDebug()
{
System.out.println("\n CanRun: " + this.canFunction());
System.out.println(" RedPower: " + this.worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord));
System.out.println(" IsDisabled: " + this.isDisabled());//TODO i'm going to kick myself if this is it, yep disabled
System.out.println(" IsRunning: " + this.functioning);
}
/** Called every tick while this tile entity is disabled. */
protected void whileDisable()
{
}
@Override
public ForgeDirection getDirection()
{
if (this.rotateByMetaGroup)
{
switch (this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) % 4)
{
case 0:
return ForgeDirection.NORTH;
case 1:
return ForgeDirection.SOUTH;
case 2:
return ForgeDirection.SOUTH;
default:
return ForgeDirection.WEST;
}
}
return ForgeDirection.UNKNOWN;
}
@Override
public void setDirection(ForgeDirection direction)
{
if (this.rotateByMetaGroup)
{
switch (direction)
{
case NORTH:
this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) / 4, 3);
case WEST:
this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, (this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) / 4) + 1, 3);
case SOUTH:
this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, (this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) / 4) + 2, 3);
default:
this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, (this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) / 4) + 3, 3);
}
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.disabledTicks = nbt.getInteger("disabledTicks");
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("disabledTicks", this.disabledTicks);
}
@Override
public boolean simplePacket(String id, ByteArrayDataInput dis, Player player)
{
try
{
if (this.worldObj.isRemote)
{
if (id.equalsIgnoreCase(SimplePacketTypes.RUNNING.name))
{
this.functioning = dis.readBoolean();
return true;
}
if (id.equalsIgnoreCase(SimplePacketTypes.NBT.name))
{
this.readFromNBT(PacketHandler.instance().readNBTTagCompound(dis));
return true;
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
return false;
}
/** Sends the tileEntity save data to the client */
public void sendNBTPacket()
{
if (!this.worldObj.isRemote)
{
NBTTagCompound tag = new NBTTagCompound();
this.writeToNBT(tag);
PacketHandler.instance().sendPacketToClients(PacketHandler.instance().getTilePacket(this.getChannel(), this, SimplePacketTypes.NBT.name, tag), worldObj, new Vector3(this), 64);
}
}
/** Sends a simple true/false am running power update */
public void sendPowerUpdate()
{
if (!this.worldObj.isRemote)
{
PacketHandler.instance().sendPacketToClients(PacketHandler.instance().getTilePacket(this.getChannel(), this, SimplePacketTypes.RUNNING.name, this.functioning), worldObj, new Vector3(this), 64);
}
}
/** Sends a gui packet only to the given player */
public Packet getGUIPacket()
{
return null;
}
public void sendGUIPacket()
{
Packet packet = this.getGUIPacket();
if (this.hasGUI && this.getContainer() != null && packet != null)
{
this.playersUsingMachine = 0;
for (Object entity : this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1).expand(10, 10, 10)))
{
if (entity instanceof EntityPlayer && ((EntityPlayer) entity).openContainer != null)
{
if (((EntityPlayer) entity).openContainer.getClass().isAssignableFrom(this.getContainer()))
{
this.playersUsingMachine += 1;
PacketDispatcher.sendPacketToPlayer(packet, (Player) entity);
}
}
}
}
}
@Override
public Packet getDescriptionPacket()
{
return PacketHandler.instance().getTilePacket(this.getChannel(), this, SimplePacketTypes.RUNNING.name, this.functioning);
}
/** NetworkMod channel name */
public String getChannel()
{
return CoreMachine.CHANNEL;
}
@Override
public void onDisable(int duration)
{
if (this.canBeDisabled)
{
this.disabledTicks = duration;
}
}
@Override
public boolean isDisabled()
{
return !this.canBeDisabled && this.disabledTicks > 0;
}
@Override
public boolean hasExtraConfigs()
{
// TODO Auto-generated method stub
return false;
}
@Override
public void loadExtraConfigs(Configuration config)
{
// TODO Auto-generated method stub
}
}

View file

@ -1,6 +1,6 @@
package dark.core.prefab.sentry;
import dark.core.prefab.terminal.TileEntityTerminal;
import com.dark.terminal.TileEntityTerminal;
public class TileEntityGunPlatform extends TileEntityTerminal
{

View file

@ -15,12 +15,12 @@ import universalelectricity.core.vector.Vector3;
import com.dark.helpers.MathHelper;
import com.dark.helpers.RayTraceHelper;
import com.dark.network.PacketHandler;
import com.dark.prefab.TileEntityMachine;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.Player;
import dark.api.ISentryGun;
import dark.core.prefab.entities.EntityTileDamage;
import dark.core.prefab.machine.TileEntityMachine;
import dark.machines.CoreMachine;
/** Prefab tileEntity for creating senty guns that can be of type aimed, mounted, or automated.

View file

@ -1,73 +0,0 @@
package dark.core.prefab.terminal;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import com.dark.access.GroupRegistry;
import dark.api.ITerminal;
import dark.api.ITerminalCommand;
public class CommandRegistry
{
public static final List<ITerminalCommand> COMMANDS = new ArrayList<ITerminalCommand>();
/** @param prefix - what the command starts with for example /time
* @param cmd - Cmd instance that will execute the command */
public static void register(ITerminalCommand cmd, String group)
{
if (!COMMANDS.contains(cmd))
{
COMMANDS.add(cmd);
if (group != null)
{
if (GroupRegistry.groupDefaultNodes.containsKey(group))
{
List<String> stra = new ArrayList<String>();
stra.add(cmd.getCommandName());
}
}
}
}
/** When a player uses a command in any CMD machine it pass threw here first
*
* @param terminal - The terminal, can be cast to TileEntity. */
public static boolean onCommand(EntityPlayer player, ITerminal terminal, String cmd)
{
if (cmd != null && cmd != "")
{
String[] args = cmd.split(" ");
if (args[0] != null)
{
for (ITerminalCommand command : COMMANDS)
{
if (command.getCommandName().equalsIgnoreCase(args[0]))
{
if (command.canSupport(terminal) && command.getNode(args) != null)
{
if (!terminal.canUse(command.getNode(args), player))
{
terminal.addToConsole("Access Denied.");
return false;
}
else
{
if (command.called(player, terminal, args))
{
return true;
}
}
}
}
}
}
terminal.addToConsole("Unknown Command.");
}
return false;
}
}

View file

@ -1,137 +0,0 @@
package dark.core.prefab.terminal;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.entity.player.EntityPlayer;
import com.dark.access.ISpecialAccess;
import dark.api.ITerminal;
import dark.api.ITerminalCommand;
public class CommandUser implements ITerminalCommand
{
@Override
public String getCommandName()
{
return "users";
}
@Override
public boolean called(EntityPlayer player, ITerminal terminal, String[] args)
{
if (args[0].equalsIgnoreCase("users") && args.length > 1 && args[1] != null && terminal instanceof ISpecialAccess)
{
ISpecialAccess turret = terminal;
// ILockable
if (args[1].equalsIgnoreCase("List"))
{
terminal.addToConsole("");
terminal.addToConsole("Listing Users");
for (int i = 0; i < turret.getUsers().size(); i++)
{
terminal.addToConsole(" " + i + ") " + turret.getUsers().get(i).getName());
}
return true;
}
if (args[1].equalsIgnoreCase("remove") && args.length > 2)
{
if (args[2] != null)
{
if (turret.setUserAccess(args[2], null, false))
{
terminal.addToConsole("Removed: " + args[2]);
return true;
}
else
{
terminal.addToConsole(" User not found.");
return true;
}
}
else
{
terminal.addToConsole("Invalid username.");
return true;
}
}
if (args[1].equalsIgnoreCase("add") && args.length > 2)
{
if (args[2] != null && terminal.getGroup(args[2]) != null)
{
if (args.length > 3)
{
if (terminal.getGroup(args[2]).isMemeber(args[3]))
{
terminal.addToConsole("User already exists.");
return true;
}
else if (turret.setUserAccess(args[3], terminal.getGroup(args[2]), true))
{
terminal.addToConsole("Added: " + args[3] + " to group " + args[2]);
return true;
}
else
{
terminal.addToConsole("Invalid username.");
return true;
}
}
}
else
{
terminal.addToConsole("Invalid group.");
return true;
}
}
return false;
}
return false;
}
@Override
public boolean canSupport(ITerminal mm)
{
return mm != null;
}
@Override
public Set<String> getPermissionNodes()
{
Set<String> nodes = new HashSet<String>();
nodes.add("add");
nodes.add("remove");
nodes.add("list");
return nodes;
}
@Override
public String getNode(String[] args)
{
if (args != null && args.length >= 1)
{
if (args[0] != null && args[0].equalsIgnoreCase(this.getCommandName()))
{
if (args.length >= 2)
{
if (args[1] != null && args[1].equalsIgnoreCase("add"))
{
return "users.add";
}
if (args[1] != null && args[1].equalsIgnoreCase("remove"))
{
return "users.remove";
}
if (args[1] != null && args[1].equalsIgnoreCase("list"))
{
return "users.list";
}
}
return "users";
}
}
return null;
}
}

View file

@ -1,189 +0,0 @@
package dark.core.prefab.terminal;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.util.AxisAlignedBB;
import com.dark.network.PacketHandler;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player;
import dark.api.ITerminal;
import dark.core.prefab.machine.TileEntityEnergyMachine;
/** @author Calclavia, DarkGuardsman */
public abstract class TileEntityTerminal extends TileEntityEnergyMachine implements ITerminal
{
/** A list of everything typed inside the terminal */
private final List<String> terminalOutput = new ArrayList<String>();
/** 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;
public TileEntityTerminal()
{
super(0, 0);
}
public TileEntityTerminal(float wattsPerTick)
{
super(wattsPerTick);
}
public TileEntityTerminal(float wattsPerTick, float maxEnergy)
{
super(wattsPerTick, maxEnergy);
}
@Override
public Packet getGUIPacket()
{
return this.getDescriptionPacket();
}
/** Sends all NBT data. Server -> Client */
@Override
public Packet getDescriptionPacket()
{
NBTTagCompound nbt = new NBTTagCompound();
this.writeToNBT(nbt);
return PacketHandler.instance().getTilePacket(this.getChannel(), this, SimplePacketTypes.NBT.name, nbt);
}
/** Sends all Terminal data Server -> Client */
public void sendTerminalOutputToClients()
{
List data = new ArrayList();
data.add(SimplePacketTypes.TERMINAL_OUTPUT.name);
data.add(this.getTerminalOuput().size());
data.addAll(this.getTerminalOuput());
Packet packet = PacketHandler.instance().getTilePacket(this.getChannel(), this, data.toArray());
for (Object entity : this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord - 10, yCoord - 10, zCoord - 10, xCoord + 10, yCoord + 10, zCoord + 10)))
{
if (entity instanceof EntityPlayer && ((EntityPlayer) entity).openContainer.getClass().equals(this.getContainer()))
{
PacketDispatcher.sendPacketToPlayer(packet, (Player) entity);
}
}
}
/** Send a terminal command Client -> server */
public void sendCommandToServer(EntityPlayer entityPlayer, String cmdInput)
{
if (this.worldObj.isRemote)
{
Packet packet = PacketHandler.instance().getTilePacket(this.getChannel(), this, SimplePacketTypes.GUI_COMMAND.name, entityPlayer.username, cmdInput);
PacketDispatcher.sendPacketToServer(packet);
}
}
@Override
public boolean simplePacket(String id, ByteArrayDataInput dis, Player player)
{
try
{
if (!super.simplePacket(id, dis, player))
{
if (this.worldObj.isRemote)
{
if (id.equalsIgnoreCase(SimplePacketTypes.TERMINAL_OUTPUT.name))
{
int size = dis.readInt();
List<String> oldTerminalOutput = new ArrayList(this.terminalOutput);
this.terminalOutput.clear();
for (int i = 0; i < size; i++)
{
this.terminalOutput.add(dis.readUTF());
}
if (!this.terminalOutput.equals(oldTerminalOutput) && this.terminalOutput.size() != oldTerminalOutput.size())
{
this.setScroll(this.getTerminalOuput().size() - SCROLL_SIZE);
}
return true;
}
}
else
{
if (id.equalsIgnoreCase(SimplePacketTypes.GUI_COMMAND.name))
{
CommandRegistry.onCommand(this.worldObj.getPlayerEntityByName(dis.readUTF()), this, dis.readUTF());
this.sendTerminalOutputToClients();
return true;
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
return false;
}
@Override
public List<String> getTerminalOuput()
{
return this.terminalOutput;
}
@Override
public boolean addToConsole(String msg)
{
if (!this.worldObj.isRemote)
{
int usedLines = 0;
msg.trim();
if (msg.length() > 23)
{
msg = msg.substring(0, 22);
}
this.getTerminalOuput().add(msg);
this.sendTerminalOutputToClients();
return true;
}
return false;
}
@Override
public void scroll(int amount)
{
this.setScroll(this.scroll + amount);
}
@Override
public void setScroll(int length)
{
this.scroll = Math.max(Math.min(length, this.getTerminalOuput().size()), 0);
}
@Override
public int getScroll()
{
return this.scroll;
}
@Override
public boolean canUse(String node, EntityPlayer player)
{
// TODO Auto-generated method stub
return false;
}
}

View file

@ -9,12 +9,12 @@ import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import com.dark.DarkCore;
import com.dark.prefab.TileEntityMachine;
import com.dark.prefab.invgui.GuiBase;
import com.dark.prefab.invgui.GuiButtonImage;
import com.dark.prefab.invgui.GuiButtonImage.ButtonIcon;
import cpw.mods.fml.client.FMLClientHandler;
import dark.core.prefab.invgui.GuiBase;
import dark.core.prefab.invgui.GuiButtonImage;
import dark.core.prefab.invgui.GuiButtonImage.ButtonIcon;
import dark.core.prefab.machine.TileEntityMachine;
import dark.machines.CoreMachine;
/** To be used with all machine that have a gui to allow generic settings and feature all all devices

View file

@ -11,12 +11,13 @@ import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import com.dark.prefab.TileEntityMachine;
import com.dark.prefab.invgui.GuiButtonImage;
import com.dark.prefab.invgui.GuiButtonImage.ButtonIcon;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.core.prefab.invgui.GuiButtonImage;
import dark.core.prefab.invgui.GuiButtonImage.ButtonIcon;
import dark.core.prefab.machine.TileEntityMachine;
@SideOnly(Side.CLIENT)
public abstract class GuiMachineContainer extends GuiContainer

View file

@ -7,10 +7,10 @@ import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import com.dark.DarkCore;
import com.dark.prefab.TileEntityMachine;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.core.prefab.machine.TileEntityMachine;
import dark.machines.CoreMachine;
import dark.machines.client.models.ModelMachine;
import dark.machines.client.models.ModelSteamGen;

View file

@ -1,5 +1,7 @@
package dark.machines.generators;
import com.dark.prefab.TileEntityMachine;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
@ -9,7 +11,6 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import dark.core.prefab.machine.TileEntityMachine;
/** Simple steam gen designed to burn items to create steam to power a steam device directly above
* it. Doesn't actually make steam fluid but rather simple functions. The machines above it will

View file

@ -2,9 +2,10 @@ package dark.machines.generators;
import java.util.EnumSet;
import com.dark.prefab.TileEntityEnergyMachine;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import dark.core.prefab.machine.TileEntityEnergyMachine;
public class TileEntitySteamPiston extends TileEntityEnergyMachine
{

View file

@ -14,12 +14,12 @@ import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
import com.dark.network.PacketHandler;
import com.dark.prefab.TileEntityEnergyMachine;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.Player;
import cpw.mods.fml.common.registry.LanguageRegistry;
import dark.core.prefab.machine.EnergyHelper;
import dark.core.prefab.machine.TileEntityEnergyMachine;
/** Simple in out battery box
*

View file

@ -1,7 +1,8 @@
package dark.machines.machines;
import com.dark.prefab.TileEntityEnergyMachine;
import net.minecraftforge.common.ForgeDirection;
import dark.core.prefab.machine.TileEntityEnergyMachine;
public class TileEntityInfLoad extends TileEntityEnergyMachine
{

View file

@ -2,8 +2,9 @@ package dark.machines.machines;
import java.util.EnumSet;
import com.dark.prefab.TileEntityEnergyMachine;
import net.minecraftforge.common.ForgeDirection;
import dark.core.prefab.machine.TileEntityEnergyMachine;
public class TileEntityInfSupply extends TileEntityEnergyMachine
{