Cleaned up and started on crafters

I removed some commented out areas from the other files.
Also started on autocrafter at the moment nothing is done just creating
init files, methods, and trying to layout the ground work. Let see if i
can code these cleaner than i usually do he he :)

Also looks like some other things are getting uploaded in this. Might be
a slight version diff in the UE and Buildcraft api version i have. As
well i added the textures to the src folder. Not sure how you mod with
them in the resource folder.
This commit is contained in:
Rseifert 2012-10-29 13:47:33 -04:00
parent bc73c978c5
commit 27e43ebfa7
54 changed files with 2253 additions and 127 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 957 B

View file

@ -29,24 +29,6 @@ public abstract class TileEntityBase extends TileEntityAdvanced implements IPack
* The owner of this tile entity.
*/
protected String owner = "";
/*
* { if (count++ >=
* 10) { count = 0; if (!worldObj.isRemote &&
* this.sendDataA() != null) { Packet packet =
* PacketManager.getPacket("asmLine", this,
* this.buildData(1));
* PacketManager.sendPacketToClients(packet,
* worldObj, Vector3.get(this), 40); } if
* (!worldObj.isRemote && this.sendDataG() !=
* null && this.isOpen) { Packet packet =
* PacketManager.getPacket("asmLine", this,
* this.buildData(0));
* PacketManager.sendPacketToClients(packet,
* worldObj, Vector3.get(this), 10); } } if
* (ticks++ % tickRate() >= 0 &&
* !isDisabled()) { this.tickedUpdate(); } }
*/
/**
* Inventory functions.
@ -186,93 +168,5 @@ public abstract class TileEntityBase extends TileEntityAdvanced implements IPack
}
nbt.setTag("Items", var2);
}
/*
@Override
public void handlePacketData(NetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
if (worldObj.isRemote)
{
try
{
int ID = dataStream.readInt();
if (ID == 0)
{
this.guiPacket(network, packetType, packet, player, dataStream);
}
else if (ID == 1)
{
this.animationPacket(network, packetType, packet, player, dataStream);
}
else
{
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
/**
* Used to read GUI only data sent to the TE
public abstract void guiPacket(NetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream);
/**
* Used to read animation data for things that
* can be seen on a TE
public abstract void animationPacket(NetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream);
/**
* Used to read data for none animation or gui
* server sent packets
*
public abstract void otherPacket(NetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream);
public Object[] buildData(int packetID)
{
Object[] data = new Object[1];
if (packetID == 0)
{
data = new Object[this.sendDataG().length + 1];
data[0] = packetID;
for (int i = 0; i < this.sendDataG().length; i++)
{
data[i + 1] = this.sendDataG()[i];
}
}
else if (packetID == 1)
{
data = new Object[this.sendDataA().length + 1];
data[0] = packetID;
for (int i = 0; i < this.sendDataA().length; i++)
{
data[i + 1] = this.sendDataA()[i];
}
}
return data;
}
/**
* Array of data too be sent for animation
* updates
*
* @return
*
public abstract Object[] sendDataA();
/**
* Array of data too be sent if the TE's GUI
* is open at the time
*
* @return
*
public abstract Object[] sendDataG();
*/
}

View file

@ -88,7 +88,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
{
super.updateEntity();
if (this.ticks % 20 == 0)
if (this.ticks % 10 == 0)
{
if (!worldObj.isRemote)
{
@ -300,7 +300,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
* Used to tell the belt not to apply velocity
* to some Entity in case they are being
* handled by another block. For example
* ejector
* Rejector
*
* @param entity
*/

View file

@ -0,0 +1,98 @@
package assemblyline.machines.crafter;
import net.minecraft.src.Container;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.InventoryPlayer;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Slot;
public class ContainerCrafter extends Container
{
private TileEntityAutoCrafter tileEntity;
public ContainerCrafter(InventoryPlayer par1InventoryPlayer, TileEntityAutoCrafter tileEntity)
{
this.tileEntity = tileEntity;
for(int r = 0; r < 3; r++)
{
for(int i = 0; i < 3; i++)
{
this.addSlotToContainer(new Slot(tileEntity, i+ r*3, 33 + i*18, 34 + r * 18));
}
}
int var3;
for (var3 = 0; var3 < 3; ++var3)
{
for (int var4 = 0; var4 < 9; ++var4)
{
this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
}
}
for (var3 = 0; var3 < 9; ++var3)
{
this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142));
}
}
@Override
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
return this.tileEntity.isUseableByPlayer(par1EntityPlayer);
}
/**
* Called to transfer a stack from one inventory to the other eg. when shift clicking.
*/
@Override
public ItemStack func_82846_b(EntityPlayer par1EntityPlayer, int par1)
{
ItemStack itemStack3 = null;
Slot itemStack = (Slot)this.inventorySlots.get(par1);
if (itemStack != null && itemStack.getHasStack())
{
ItemStack itemStack2 = itemStack.getStack();
itemStack3 = itemStack2.copy();
if (par1 != 0)
{
if (itemStack2.itemID == Item.coal.shiftedIndex)
{
if (!this.mergeItemStack(itemStack2, 0, 1, false))
{
return null;
}
}
else if (par1 >= 30 && par1 < 37 && !this.mergeItemStack(itemStack2, 3, 30, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemStack2, 3, 37, false))
{
return null;
}
if (itemStack2.stackSize == 0)
{
itemStack.putStack((ItemStack)null);
}
else
{
itemStack.onSlotChanged();
}
if (itemStack2.stackSize == itemStack3.stackSize)
{
return null;
}
itemStack.func_82870_a(par1EntityPlayer, itemStack2);
}
return itemStack3;
}
}

View file

@ -1,11 +1,39 @@
package assemblyline.machines.crafter;
import universalelectricity.core.Vector3;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityItem;
import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.World;
public class EntityCraftingArm extends Entity {
/**
* Used to ID the type of arm
*/
static enum armType
{
ARM,SOLDER,DRILL,BREAKER
}
/**
* type of arm this robotic arm currently is
*/
public armType arm = armType.ARM;
/**
* stack this arm is holding if any
*/
public ItemStack stack = null;
/**
* TileEntity this arm is working with
*/
public TileEntityCraftingArm blockArm = null;
/**
* position that the arms claw should be at
*/
public Vector3 clawPos = new Vector3();
public boolean isWorking = false;
public EntityCraftingArm(World par1World) {
super(par1World);
}
@ -17,14 +45,23 @@ public class EntityCraftingArm extends Entity {
}
@Override
protected void readEntityFromNBT(NBTTagCompound var1) {
// TODO Auto-generated method stub
protected void readEntityFromNBT(NBTTagCompound nbt) {
this.arm = armType.values()[nbt.getInteger("type")];
}
@Override
protected void writeEntityToNBT(NBTTagCompound var1) {
// TODO Auto-generated method stub
protected void writeEntityToNBT(NBTTagCompound nbt) {
nbt.setInteger("type", arm.ordinal());
}
public boolean grabItem(EntityItem item)
{
if(this.stack == null)
{
//TODO set current stack to item as soon as it reaches coords
}
return false;
}
}

View file

@ -0,0 +1,12 @@
package assemblyline.machines.crafter;
import net.minecraft.src.Item;
public class ItemCrafterArm extends Item {
protected ItemCrafterArm(int par1) {
super(par1);
this.setHasSubtypes(true);
}
}

View file

@ -9,7 +9,7 @@ import assemblyline.TileEntityBase;
import com.google.common.io.ByteArrayDataInput;
public class TileEntityAutoCrafter extends TileEntityBase implements ISidedInventory
public class TileEntityAutoCrafter extends TileEntityBase
{
@Override
public String getInvName()
@ -28,16 +28,4 @@ public class TileEntityAutoCrafter extends TileEntityBase implements ISidedInven
{
}
@Override
public int getStartInventorySide(ForgeDirection side)
{
return 0;
}
@Override
public int getSizeInventorySide(ForgeDirection side)
{
return 0;
}
}

View file

@ -1,7 +1,137 @@
package assemblyline.machines.crafter;
import com.google.common.io.ByteArrayDataInput;
import assemblyline.TileEntityBase;
import universalelectricity.implement.IElectricityReceiver;
import universalelectricity.prefab.TileEntityElectricityReceiver;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.INetworkManager;
import net.minecraft.src.Packet250CustomPayload;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;
public class TileEntityCraftingArm extends TileEntity {
public class TileEntityCraftingArm extends TileEntityBase implements IElectricityReceiver {
public enum armTasks
{
NONE,COLLECT,MINE,PLACE,SORT,CRAFT
}
/**
* Entity robotic arm to be used with this tileEntity
*/
public EntityCraftingArm EntityArm = null;
public double wattUsed = 20;
public double jouleReceived = 0;
public double maxJoules = 100;
/**
* does this arm have a task to do
*/
public boolean hasTask = true;
/**
* what kind of task this arm should do
*/
public armTasks task = armTasks.NONE;
public void updateEntity()
{
super.updateEntity();
if(this.ticks % 5 == 0 && !this.isDisabled() && this.hasTask && EntityArm != null)
{
this.jouleReceived -= this.wattUsed;
this.doWork();
}
}
/**
* controls the robotic arm into doing a set task
*/
public void doWork()
{
}
/**
* UE methods
*/
@Override
public void onReceive(TileEntity sender, double amps, double voltage,
ForgeDirection side) {
this.jouleReceived = Math.max(jouleReceived + (amps * voltage),
maxJoules);
}
@Override
public double wattRequest() {
return maxJoules - jouleReceived;
}
@Override
public boolean canReceiveFromSide(ForgeDirection side) {
if (side != ForgeDirection.UP) {
return true;
}
return false;
}
@Override
public void onDisable(int duration) {
// TODO Auto-generated method stub
}
@Override
public boolean isDisabled() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean canConnect(ForgeDirection side) {
if(side != ForgeDirection.UP)
{
return true;
}
return false;
}
@Override
public double getVoltage() {
// TODO Auto-generated method stub
return 120;
}
/**
* Data
*/
@Override
public void handlePacketData(INetworkManager network, int packetType,
Packet250CustomPayload packet, EntityPlayer player,
ByteArrayDataInput dataStream) {
// TODO Auto-generated method stub
}
/**
* inventory
*/
@Override
public int getSizeInventory() {
// TODO Auto-generated method stub
return 1;
}
@Override
public String getInvName() {
// TODO Auto-generated method stub
return "RoboticArm";
}
}

View file

@ -0,0 +1,80 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.core;
import net.minecraftforge.common.ForgeDirection;
public enum Orientations {
YNeg, // 0
YPos, // 1
ZNeg, // 2
ZPos, // 3
XNeg, // 4
XPos, // 5
Unknown;
public Orientations reverse() {
switch (this) {
case YPos:
return Orientations.YNeg;
case YNeg:
return Orientations.YPos;
case ZPos:
return Orientations.ZNeg;
case ZNeg:
return Orientations.ZPos;
case XPos:
return Orientations.XNeg;
case XNeg:
return Orientations.XPos;
default:
return Orientations.Unknown;
}
}
public ForgeDirection toDirection(){
switch(this){
case YNeg:
return ForgeDirection.DOWN;
case YPos:
return ForgeDirection.UP;
case ZNeg:
return ForgeDirection.NORTH;
case ZPos:
return ForgeDirection.SOUTH;
case XNeg:
return ForgeDirection.WEST;
case XPos:
return ForgeDirection.EAST;
default:
return ForgeDirection.UNKNOWN;
}
}
public Orientations rotateLeft() {
switch (this) {
case XPos:
return ZPos;
case ZNeg:
return XPos;
case XNeg:
return ZNeg;
case ZPos:
return XNeg;
default:
return this;
}
}
public static Orientations[] dirs() {
return new Orientations[] { YNeg, YPos, ZNeg, ZPos, XNeg, XPos };
}
}

View file

@ -0,0 +1,141 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.core;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.TileEntity;
public class Position {
public double x, y, z;
public Orientations orientation;
public Position(double ci, double cj, double ck) {
x = ci;
y = cj;
z = ck;
orientation = Orientations.Unknown;
}
public Position(double ci, double cj, double ck, Orientations corientation) {
x = ci;
y = cj;
z = ck;
orientation = corientation;
}
public Position(Position p) {
x = p.x;
y = p.y;
z = p.z;
orientation = p.orientation;
}
public Position(NBTTagCompound nbttagcompound) {
x = nbttagcompound.getDouble("i");
y = nbttagcompound.getDouble("j");
z = nbttagcompound.getDouble("k");
orientation = Orientations.Unknown;
}
public Position(TileEntity tile) {
x = tile.xCoord;
y = tile.yCoord;
z = tile.zCoord;
}
public void moveRight(double step) {
switch (orientation) {
case ZPos:
x = x - step;
break;
case ZNeg:
x = x + step;
break;
case XPos:
z = z + step;
break;
case XNeg:
z = z - step;
break;
default:
}
}
public void moveLeft(double step) {
moveRight(-step);
}
public void moveForwards(double step) {
switch (orientation) {
case YPos:
y = y + step;
break;
case YNeg:
y = y - step;
break;
case ZPos:
z = z + step;
break;
case ZNeg:
z = z - step;
break;
case XPos:
x = x + step;
break;
case XNeg:
x = x - step;
break;
default:
}
}
public void moveBackwards(double step) {
moveForwards(-step);
}
public void moveUp(double step) {
switch (orientation) {
case ZPos:
case ZNeg:
case XPos:
case XNeg:
y = y + step;
break;
default:
}
}
public void moveDown(double step) {
moveUp(-step);
}
public void writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setDouble("i", x);
nbttagcompound.setDouble("j", y);
nbttagcompound.setDouble("k", z);
}
@Override
public String toString() {
return "{" + x + ", " + y + ", " + z + "}";
}
public Position min(Position p) {
return new Position(p.x > x ? x : p.x, p.y > y ? y : p.y, p.z > z ? z : p.z);
}
public Position max(Position p) {
return new Position(p.x < x ? x : p.x, p.y < y ? y : p.y, p.z < z ? z : p.z);
}
}

View file

@ -0,0 +1,44 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.core;
import net.minecraft.src.World;
public class SafeTimeTracker {
private long lastMark = 0;
/**
* Return true if a given delay has passed since last time marked was called
* successfully.
*/
public boolean markTimeIfDelay(World world, long delay) {
if (world == null) {
return false;
}
long currentTime = world.getWorldTime();
if (currentTime < lastMark) {
lastMark = currentTime;
return false;
} else if (lastMark + delay <= currentTime) {
lastMark = world.getWorldTime();
return true;
} else {
return false;
}
}
public void markTime(World world) {
lastMark = world.getWorldTime();
}
}

View file

@ -0,0 +1,20 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.liquids;
public interface ILiquid {
public int stillLiquidId();
public boolean isMetaSensitive();
public int stillLiquidMeta();
}

View file

@ -0,0 +1,27 @@
package buildcraft.api.liquids;
public interface ILiquidTank {
/**
* @return LiquidStack representing the liquid contained in the tank, null if empty.
*/
LiquidStack getLiquid();
void setLiquid(LiquidStack liquid);
void setCapacity(int capacity);
int getCapacity();
/**
*
* @param resource
* @param doFill
* @return Amount of liquid used for filling.
*/
int fill(LiquidStack resource, boolean doFill);
/**
*
* @param maxDrain
* @param doDrain
* @return Null if nothing was drained, otherwise a LiquidStack containing the drained.
*/
LiquidStack drain(int maxDrain, boolean doDrain);
}

View file

@ -0,0 +1,46 @@
package buildcraft.api.liquids;
import buildcraft.api.core.Orientations;
public interface ITankContainer {
/**
* Fills liquid into internal tanks, distribution is left to the ITankContainer.
* @param from Orientation the liquid is pumped in from.
* @param resource LiquidStack representing the maximum amount of liquid filled into the ITankContainer
* @param doFill If false filling will only be simulated.
* @return Amount of resource that was filled into internal tanks.
*/
int fill(Orientations from, LiquidStack resource, boolean doFill);
/**
* Fills liquid into the specified internal tank.
* @param from Orientation the liquid is pumped in from.
* @param resource LiquidStack representing the maximum amount of liquid filled into the ITankContainer
* @param doFill If false filling will only be simulated.
* @return Amount of resource that was filled into internal tanks.
*/
int fill(int tankIndex, LiquidStack resource, boolean doFill);
/**
* Drains liquid out of internal tanks, distribution is left to the ITankContainer.
* @param from Orientation the liquid is drained to.
* @param maxDrain Maximum amount of liquid to drain.
* @param doDrain If false draining will only be simulated.
* @return LiquidStack representing the liquid and amount actually drained from the ITankContainer
*/
LiquidStack drain(Orientations from, int maxDrain, boolean doDrain);
/**
* Drains liquid out of the specified internal tank.
* @param from Orientation the liquid is drained to.
* @param maxDrain Maximum amount of liquid to drain.
* @param doDrain If false draining will only be simulated.
* @return LiquidStack representing the liquid and amount actually drained from the ITankContainer
*/
LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain);
/**
* @return Array of {@link LiquidTank}s contained in this ITankContainer
*/
ILiquidTank[] getTanks();
}

View file

@ -0,0 +1,45 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.liquids;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
public class LiquidData {
public final LiquidStack stillLiquid;
public final LiquidStack movingLiquid;
public final ItemStack filled;
public final ItemStack container;
public LiquidData(int stillLiquidId, int movingLiquidId, Item filled) {
this(new LiquidStack(stillLiquidId, LiquidManager.BUCKET_VOLUME), new LiquidStack(movingLiquidId, LiquidManager.BUCKET_VOLUME), new ItemStack(filled, 1), new ItemStack(Item.bucketEmpty));
}
public LiquidData(int stillLiquidId, int movingLiquidId, ItemStack filled) {
this(new LiquidStack(stillLiquidId, LiquidManager.BUCKET_VOLUME), new LiquidStack(movingLiquidId, LiquidManager.BUCKET_VOLUME), filled, new ItemStack(Item.bucketEmpty));
}
public LiquidData(LiquidStack stillLiquid, ItemStack filled, ItemStack container) {
this(stillLiquid, stillLiquid, filled, container);
}
public LiquidData(LiquidStack stillLiquid, LiquidStack movingLiquid, ItemStack filled, ItemStack container) {
this.stillLiquid = stillLiquid;
this.movingLiquid = movingLiquid;
this.filled = filled;
this.container = container;
if(stillLiquid == null || filled == null || container == null)
throw new RuntimeException("stillLiquid, filled, or container is null, this is an error");
}
}

View file

@ -0,0 +1,57 @@
package buildcraft.api.liquids;
import java.util.HashMap;
import java.util.Map;
/**
* When creating liquids you should register them with this class.
*
* @author CovertJaguar <railcraft.wikispaces.com>
*/
public abstract class LiquidDictionary
{
private static Map<String, LiquidStack> liquids = new HashMap<String, LiquidStack>();
/**
* When creating liquids you should call this function.
*
* Upon passing it a name and liquid item it will return either
* a preexisting implementation of that liquid or the liquid passed in.
*
*
* @param name the name of the liquid
* @param liquid the liquid to use if one doesn't exist
* @return
*/
public static LiquidStack getOrCreateLiquid(String name, LiquidStack liquid)
{
LiquidStack existing = liquids.get(name);
if(existing != null) {
return existing.copy();
}
liquids.put(name, liquid.copy());
return liquid;
}
/**
* Returns the liquid matching the name,
* if such a liquid exists.
*
* Can return null.
*
* @param name the name of the liquid
* @param amount the amout of liquid
* @return
*/
public static LiquidStack getLiquid(String name, int amount)
{
LiquidStack liquid = liquids.get(name);
if(liquid == null)
return null;
liquid = liquid.copy();
liquid.amount = amount;
return liquid;
}
}

View file

@ -0,0 +1,64 @@
package buildcraft.api.liquids;
import java.util.LinkedList;
import net.minecraft.src.ItemStack;
public class LiquidManager {
public static final int BUCKET_VOLUME = 1000;
public static LinkedList<LiquidData> liquids = new LinkedList<LiquidData>();
public static LiquidStack getLiquidForFilledItem(ItemStack filledItem) {
if (filledItem == null)
return null;
for (LiquidData liquid : liquids)
if (liquid.filled.isItemEqual(filledItem))
return liquid.stillLiquid;
return null;
}
public static int getLiquidIDForFilledItem(ItemStack filledItem) {
LiquidStack liquidForFilledItem = getLiquidForFilledItem(filledItem);
if (liquidForFilledItem == null)
return 0;
return liquidForFilledItem.itemID;
}
public static ItemStack getFilledItemForLiquid(LiquidStack liquid) {
for (LiquidData data : liquids)
if(data.stillLiquid.isLiquidEqual(liquid))
return data.filled.copy();
return null;
}
public static ItemStack fillLiquidContainer(int liquidId, int quantity, ItemStack emptyContainer) {
return fillLiquidContainer(new LiquidStack(liquidId, quantity, 0), emptyContainer);
}
public static ItemStack fillLiquidContainer(LiquidStack liquid, ItemStack emptyContainer) {
for(LiquidData data : liquids)
if(liquid.containsLiquid(data.stillLiquid)
&& data.container.isItemEqual(emptyContainer))
return data.filled.copy();
return null;
}
public static boolean isLiquid(ItemStack block) {
if (block.itemID == 0)
return false;
for (LiquidData liquid : liquids)
if (liquid.stillLiquid.isLiquidEqual(block) || liquid.movingLiquid.isLiquidEqual(block))
return true;
return false;
}
}

View file

@ -0,0 +1,109 @@
package buildcraft.api.liquids;
import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
/**
* ItemStack substitute for liquids
* @author SirSengir
*/
public class LiquidStack {
public int itemID;
public int amount;
public int itemMeta;
private LiquidStack() {
}
public LiquidStack(int itemID, int amount) {
this(itemID, amount, 0);
}
public LiquidStack(Item item, int amount) {
this(item.shiftedIndex, amount, 0);
}
public LiquidStack(Block block, int amount) {
this(block.blockID, amount, 0);
}
public LiquidStack(int itemID, int amount, int itemDamage) {
this.itemID = itemID;
this.amount = amount;
this.itemMeta = itemDamage;
}
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setShort("Id", (short) itemID);
nbttagcompound.setInteger("Amount", amount);
nbttagcompound.setShort("Meta", (short) itemMeta);
return nbttagcompound;
}
public void readFromNBT(NBTTagCompound nbttagcompound) {
itemID = nbttagcompound.getShort("Id");
amount = nbttagcompound.getInteger("Amount");
itemMeta = nbttagcompound.getShort("Meta");
}
/**
* @return A copy of this LiquidStack
*/
public LiquidStack copy() {
return new LiquidStack(itemID, amount, itemMeta);
}
/**
* @param other
* @return true if this LiquidStack contains the same liquid as the one passed in.
*/
public boolean isLiquidEqual(LiquidStack other) {
if(other == null)
return false;
return itemID == other.itemID && itemMeta == other.itemMeta;
}
/**
* @param other
* @return true if this LiquidStack contains the other liquid (liquids are equal and amount >= other.amount).
*/
public boolean containsLiquid(LiquidStack other) {
if(!isLiquidEqual(other))
return false;
return amount >= other.amount;
}
/**
* @param other ItemStack containing liquids.
* @return true if this LiquidStack contains the same liquid as the one passed in.
*/
public boolean isLiquidEqual(ItemStack other) {
if(other == null)
return false;
return itemID == other.itemID && itemMeta == other.getItemDamage();
}
/**
* @return ItemStack representation of this LiquidStack
*/
public ItemStack asItemStack() {
return new ItemStack(itemID, 1, itemMeta);
}
/**
* Reads a liquid stack from the passed nbttagcompound and returns it.
*
* @param nbttagcompound
* @return
*/
public static LiquidStack loadLiquidStackFromNBT(NBTTagCompound nbttagcompound) {
LiquidStack liquidstack = new LiquidStack();
liquidstack.readFromNBT(nbttagcompound);
return liquidstack.itemID == 0 ? null : liquidstack;
}
}

View file

@ -0,0 +1,100 @@
package buildcraft.api.liquids;
/**
* Reference implementation of ILiquidTank. Use this or implement your own.
*/
public class LiquidTank implements ILiquidTank {
private LiquidStack liquid;
private int capacity;
public LiquidTank(int capacity) {
this(null, capacity);
}
public LiquidTank(int liquidId, int quantity, int capacity) {
this(new LiquidStack(liquidId, quantity), capacity);
}
public LiquidTank(LiquidStack liquid, int capacity) {
this.liquid = liquid;
this.capacity = capacity;
}
@Override
public LiquidStack getLiquid() {
return this.liquid;
}
@Override
public void setLiquid(LiquidStack liquid) {
this.liquid = liquid;
}
@Override
public void setCapacity(int capacity) {
this.capacity = capacity;
}
@Override
public int getCapacity() {
return this.capacity;
}
@Override
public int fill(LiquidStack resource, boolean doFill) {
if(resource == null || resource.itemID <= 0)
return 0;
if(liquid == null || liquid.itemID <= 0) {
if(resource.amount <= capacity) {
if(doFill)
this.liquid = resource.copy();
return resource.amount;
} else {
if(doFill) {
this.liquid = resource.copy();
this.liquid.amount = capacity;
}
return capacity;
}
}
if(!liquid.isLiquidEqual(resource))
return 0;
int space = capacity - liquid.amount;
if(resource.amount <= space) {
if(doFill)
this.liquid.amount += resource.amount;
return resource.amount;
} else {
if(doFill)
this.liquid.amount = capacity;
return space;
}
}
@Override
public LiquidStack drain(int maxDrain, boolean doDrain) {
if(liquid == null || liquid.itemID <= 0)
return null;
if(liquid.amount <= 0)
return null;
int used = maxDrain;
if(liquid.amount < used)
used = liquid.amount;
if(doDrain) {
liquid.amount -= used;
}
LiquidStack drained = new LiquidStack(liquid.itemID, used, liquid.itemMeta);
// Reset liquid if emptied
if(liquid.amount <= 0)
liquid = null;
return drained;
}
}

View file

@ -0,0 +1,41 @@
package buildcraft.api.power;
import buildcraft.api.core.Orientations;
import buildcraft.api.core.SafeTimeTracker;
import net.minecraft.src.NBTTagCompound;
public interface IPowerProvider {
int getLatency();
int getMinEnergyReceived();
int getMaxEnergyReceived();
int getMaxEnergyStored();
int getActivationEnergy();
float getEnergyStored();
void configure(int latency, int minEnergyReceived, int maxEnergyReceived, int minActivationEnergy, int maxStoredEnergy);
void configurePowerPerdition(int powerLoss, int powerLossRegularity);
boolean update(IPowerReceptor receptor);
boolean preConditions(IPowerReceptor receptor);
float useEnergy(float min, float max, boolean doUse);
void readFromNBT(NBTTagCompound nbttagcompound);
void writeToNBT(NBTTagCompound nbttagcompound);
void receiveEnergy(float quantity, Orientations from);
boolean isPowerSource(Orientations from);
SafeTimeTracker getTimeTracker();
}

View file

@ -0,0 +1,23 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.power;
public interface IPowerReceptor {
public void setPowerProvider(IPowerProvider provider);
public IPowerProvider getPowerProvider();
public void doWork();
public int powerRequest();
}

View file

@ -0,0 +1,56 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.power;
import net.minecraft.src.NBTTagCompound;
public abstract class PowerFramework {
static private String baseNBTName = "net.minecraft.src.buildcarft.Power";
public static PowerFramework currentFramework;
public abstract IPowerProvider createPowerProvider();
public void loadPowerProvider(IPowerReceptor receptor, NBTTagCompound compound) {
IPowerProvider provider = createPowerProvider();
if (compound.hasKey(baseNBTName)) {
NBTTagCompound cpt = compound.getCompoundTag(baseNBTName);
if (cpt.getString("class").equals(this.getClass().getName())) {
provider.readFromNBT(cpt.getCompoundTag("contents"));
}
}
receptor.setPowerProvider(provider);
}
public void savePowerProvider(IPowerReceptor receptor, NBTTagCompound compound) {
IPowerProvider provider = receptor.getPowerProvider();
if (provider == null) {
return;
}
NBTTagCompound cpt = new NBTTagCompound();
cpt.setString("class", this.getClass().getName());
NBTTagCompound contents = new NBTTagCompound();
provider.writeToNBT(contents);
cpt.setTag("contents", contents);
compound.setTag(baseNBTName, cpt);
}
}

View file

@ -0,0 +1,162 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.power;
import buildcraft.api.core.Orientations;
import buildcraft.api.core.SafeTimeTracker;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.TileEntity;
public abstract class PowerProvider implements IPowerProvider {
protected int latency;
protected int minEnergyReceived;
protected int maxEnergyReceived;
protected int maxEnergyStored;
protected int minActivationEnergy;
protected float energyStored = 0;
protected int powerLoss = 1;
protected int powerLossRegularity = 100;
public SafeTimeTracker timeTracker = new SafeTimeTracker();
public SafeTimeTracker energyLossTracker = new SafeTimeTracker();
public int[] powerSources = { 0, 0, 0, 0, 0, 0 };
@Override public SafeTimeTracker getTimeTracker() { return this.timeTracker; }
@Override public int getLatency() { return this.latency; }
@Override public int getMinEnergyReceived() { return this.minEnergyReceived; }
@Override public int getMaxEnergyReceived() { return this.maxEnergyReceived; }
@Override public int getMaxEnergyStored() { return this.maxEnergyStored; }
@Override public int getActivationEnergy() { return this.minActivationEnergy; }
@Override public float getEnergyStored() { return this.energyStored; }
@Override
public void configure(int latency, int minEnergyReceived, int maxEnergyReceived, int minActivationEnergy, int maxStoredEnergy) {
this.latency = latency;
this.minEnergyReceived = minEnergyReceived;
this.maxEnergyReceived = maxEnergyReceived;
this.maxEnergyStored = maxStoredEnergy;
this.minActivationEnergy = minActivationEnergy;
}
@Override
public void configurePowerPerdition(int powerLoss, int powerLossRegularity) {
this.powerLoss = powerLoss;
this.powerLossRegularity = powerLossRegularity;
}
@Override
public boolean update(IPowerReceptor receptor) {
if (!preConditions(receptor)) {
return false;
}
TileEntity tile = (TileEntity) receptor;
boolean result = false;
if (energyStored >= minActivationEnergy) {
if (latency == 0) {
receptor.doWork();
result = true;
} else {
if (timeTracker.markTimeIfDelay(tile.worldObj, latency)) {
receptor.doWork();
result = true;
}
}
}
if (powerLoss > 0 && energyLossTracker.markTimeIfDelay(tile.worldObj, powerLossRegularity)) {
energyStored -= powerLoss;
if (energyStored < 0) {
energyStored = 0;
}
}
for (int i = 0; i < 6; ++i) {
if (powerSources[i] > 0) {
powerSources[i]--;
}
}
return result;
}
@Override
public boolean preConditions(IPowerReceptor receptor) {
return true;
}
@Override
public float useEnergy(float min, float max, boolean doUse) {
float result = 0;
if (energyStored >= min) {
if (energyStored <= max) {
result = energyStored;
if (doUse) {
energyStored = 0;
}
} else {
result = max;
if (doUse) {
energyStored -= max;
}
}
}
return result;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
latency = nbttagcompound.getInteger("latency");
minEnergyReceived = nbttagcompound.getInteger("minEnergyReceived");
maxEnergyReceived = nbttagcompound.getInteger("maxEnergyReceived");
maxEnergyStored = nbttagcompound.getInteger("maxStoreEnergy");
minActivationEnergy = nbttagcompound.getInteger("minActivationEnergy");
try {
energyStored = nbttagcompound.getFloat("storedEnergy");
} catch (Throwable c) {
energyStored = 0;
}
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setInteger("latency", latency);
nbttagcompound.setInteger("minEnergyReceived", minEnergyReceived);
nbttagcompound.setInteger("maxEnergyReceived", maxEnergyReceived);
nbttagcompound.setInteger("maxStoreEnergy", maxEnergyStored);
nbttagcompound.setInteger("minActivationEnergy", minActivationEnergy);
nbttagcompound.setFloat("storedEnergy", energyStored);
}
@Override
public void receiveEnergy(float quantity, Orientations from) {
powerSources[from.ordinal()] = 2;
energyStored += quantity;
if (energyStored > maxEnergyStored) {
energyStored = maxEnergyStored;
}
}
@Override
public boolean isPowerSource(Orientations from) {
return powerSources[from.ordinal()] != 0;
}
}

View file

@ -0,0 +1,171 @@
package universalelectricity.prefab;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.INetworkManager;
import net.minecraft.src.Packet250CustomPayload;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.Vector3;
import universalelectricity.electricity.ElectricityManager;
import universalelectricity.electricity.ElectricityNetwork;
import universalelectricity.implement.IConductor;
import universalelectricity.implement.IConnector;
import universalelectricity.prefab.network.IPacketReceiver;
import com.google.common.io.ByteArrayDataInput;
/**
* This tile entity pre-fabricated for all
* conductors.
*
* @author Calclavia
*
*/
public abstract class TileEntityConductor extends TileEntityAdvanced implements IConductor, IPacketReceiver
{
private ElectricityNetwork network;
/**
* Stores information on the blocks that this
* conductor is connected to
*/
public TileEntity[] connectedBlocks =
{ null, null, null, null, null, null };
public TileEntityConductor()
{
this.reset();
}
@Override
public ElectricityNetwork getNetwork()
{
return this.network;
}
@Override
public void setNetwork(ElectricityNetwork network)
{
this.network = network;
}
@Override
public TileEntity[] getConnectedBlocks()
{
return connectedBlocks;
}
@Override
public void initiate()
{
this.refreshConnectedBlocks();
}
@Override
public void updateConnection(TileEntity tileEntity, ForgeDirection side)
{
if (tileEntity != null)
{
if (tileEntity instanceof IConnector)
{
this.connectedBlocks[side.ordinal()] = tileEntity;
if (tileEntity.getClass() == this.getClass())
{
ElectricityManager.instance.mergeConnection(this.getNetwork(), ((TileEntityConductor) tileEntity).getNetwork());
}
return;
}
}
if (this.connectedBlocks[side.ordinal()] != null)
{
if (this.connectedBlocks[side.ordinal()] instanceof IConductor)
{
ElectricityManager.instance.splitConnection(this, (IConductor) this.getConnectedBlocks()[side.ordinal()]);
}
}
this.connectedBlocks[side.ordinal()] = null;
}
@Override
public void updateConnectionWithoutSplit(TileEntity tileEntity, ForgeDirection side)
{
if (tileEntity != null)
{
if (tileEntity instanceof IConnector)
{
this.connectedBlocks[side.ordinal()] = tileEntity;
if (tileEntity.getClass() == this.getClass())
{
ElectricityManager.instance.mergeConnection(this.getNetwork(), ((TileEntityConductor) tileEntity).getNetwork());
}
return;
}
}
this.connectedBlocks[side.ordinal()] = null;
}
@Override
public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
if (this.worldObj.isRemote)
{
this.refreshConnectedBlocks();
}
}
/**
* Determines if this TileEntity requires
* update calls.
*
* @return True if you want updateEntity() to
* be called, false if not
*/
@Override
public boolean canUpdate()
{
return false;
}
@Override
public void reset()
{
this.network = null;
if (ElectricityManager.instance != null)
{
ElectricityManager.instance.registerConductor(this);
}
}
@Override
public void refreshConnectedBlocks()
{
if (this.worldObj != null)
{
for (byte i = 0; i < 6; i++)
{
this.updateConnection(Vector3.getConnectorFromSide(this.worldObj, Vector3.get(this), ForgeDirection.getOrientation(i)), ForgeDirection.getOrientation(i));
}
}
}
@Override
public World getWorld()
{
return this.worldObj;
}
@Override
public boolean canConnect(ForgeDirection side)
{
return true;
}
}

View file

@ -0,0 +1,99 @@
package universalelectricity.prefab.multiblock;
import java.util.Random;
import net.minecraft.src.Block;
import net.minecraft.src.BlockContainer;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.ItemStack;
import net.minecraft.src.MovingObjectPosition;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
import universalelectricity.core.UniversalElectricity;
import universalelectricity.core.Vector3;
public class BlockMulti extends BlockContainer
{
public BlockMulti(int id)
{
super(id, UniversalElectricity.machine);
this.setHardness(0.8F);
this.setBlockName("MultiBlock");
}
public void makeFakeBlock(World worldObj, Vector3 position, Vector3 mainBlock)
{
worldObj.setBlockWithNotify(position.intX(), position.intY(), position.intZ(), this.blockID);
((TileEntityMulti) worldObj.getBlockTileEntity(position.intX(), position.intY(), position.intZ())).setMainBlock(mainBlock);
}
@Override
public void breakBlock(World par1World, int x, int y, int z, int par5, int par6)
{
TileEntityMulti tileEntity = (TileEntityMulti) par1World.getBlockTileEntity(x, y, z);
tileEntity.onBlockRemoval();
super.breakBlock(par1World, x, y, z, par5, par6);
}
/**
* Called when the block is right clicked by the player. This modified
* version detects electric items and wrench actions on your machine block.
* Do not override this function. Use machineActivated instead! (It does the
* same thing)
*/
@Override
public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
TileEntityMulti tileEntity = (TileEntityMulti) par1World.getBlockTileEntity(x, y, z);
return tileEntity.onBlockActivated(par1World, x, y, z, par5EntityPlayer);
}
/**
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped(Random par1Random)
{
return 0;
}
@Override
public int getRenderType()
{
return -1;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityMulti();
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World par1World, int x, int y, int z)
{
TileEntity tileEntity = par1World.getBlockTileEntity(x, y, z);
Vector3 mainBlockPosition = ((TileEntityMulti) tileEntity).mainBlockPosition;
if (mainBlockPosition != null)
{
int mainBlockID = par1World.getBlockId(mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ());
if (mainBlockID > 0) { return Block.blocksList[mainBlockID].getPickBlock(target, par1World, mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ()); }
}
return null;
}
}

View file

@ -0,0 +1,17 @@
package universalelectricity.prefab.multiblock;
import net.minecraft.src.EntityPlayer;
/**
* A general interface to be implemented by anything that needs it.
*
* @author Calclavia
*
*/
public interface IBlockActivate
{
/**
* Called when activated
*/
public boolean onActivated(EntityPlayer entityPlayer);
}

View file

@ -0,0 +1,30 @@
package universalelectricity.prefab.multiblock;
import net.minecraft.src.TileEntity;
import universalelectricity.core.Vector3;
/**
* Interface to be applied to tile entity blocks that occupies more than one
* block space. Useful for large machines.
*
* @author Calclavia
*
*/
public interface IMultiBlock extends IBlockActivate
{
/**
* Called when this multiblock is created
*
* @param placedPosition
* - The position the block was placed at
*/
public void onCreate(Vector3 placedPosition);
/**
* Called when one of the multiblocks of this block is destroyed
*
* @param callingBlock
* - The tile entity who called the onDestroy function
*/
public void onDestroy(TileEntity callingBlock);
}

View file

@ -0,0 +1,120 @@
package universalelectricity.prefab.multiblock;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.INetworkManager;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.Packet;
import net.minecraft.src.Packet250CustomPayload;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
import universalelectricity.core.Vector3;
import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.network.PacketManager;
import com.google.common.io.ByteArrayDataInput;
/**
* This is a multiblock to be used for blocks that are bigger than one block.
*
* @author Calclavia
*
*/
public class TileEntityMulti extends TileEntity implements IPacketReceiver
{
// The the position of the main block
public Vector3 mainBlockPosition;
public void setMainBlock(Vector3 mainBlock)
{
this.mainBlockPosition = mainBlock;
if (!this.worldObj.isRemote)
{
PacketManager.sendPacketToClients(this.getDescriptionPacket());
}
}
@Override
public Packet getDescriptionPacket()
{
return PacketManager.getPacket("BasicComponents", this, this.mainBlockPosition.x, this.mainBlockPosition.y, this.mainBlockPosition.z);
}
public void onBlockRemoval()
{
if (mainBlockPosition != null)
{
TileEntity tileEntity = this.worldObj.getBlockTileEntity((int) mainBlockPosition.x, (int) mainBlockPosition.y, (int) mainBlockPosition.z);
if (tileEntity != null && tileEntity instanceof IMultiBlock)
{
IMultiBlock mainBlock = (IMultiBlock) tileEntity;
if (mainBlock != null)
{
mainBlock.onDestroy(this);
}
}
}
}
public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer)
{
if (mainBlockPosition != null)
{
TileEntity tileEntity = this.worldObj.getBlockTileEntity((int) mainBlockPosition.x, (int) mainBlockPosition.y, (int) mainBlockPosition.z);
if (tileEntity != null)
{
if (tileEntity instanceof IMultiBlock) { return ((IMultiBlock) tileEntity).onActivated(par5EntityPlayer); }
}
}
return false;
}
/**
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
this.mainBlockPosition = Vector3.readFromNBT("mainBlockPosition", par1NBTTagCompound);
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
this.mainBlockPosition.writeToNBT("mainBlockPosition", par1NBTTagCompound);
}
/**
* Determines if this TileEntity requires update calls.
*
* @return True if you want updateEntity() to be called, false if not
*/
public boolean canUpdate()
{
return false;
}
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
try
{
this.mainBlockPosition = new Vector3(dataStream.readDouble(), dataStream.readDouble(), dataStream.readDouble());
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,88 @@
package universalelectricity.prefab.network;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.server.MinecraftServer;
import net.minecraft.src.INetworkManager;
import net.minecraft.src.NetHandler;
import net.minecraft.src.NetLoginHandler;
import net.minecraft.src.Packet1Login;
import cpw.mods.fml.common.network.IConnectionHandler;
import cpw.mods.fml.common.network.Player;
public class ConnectionHandler implements IConnectionHandler
{
private static final List<ISimpleConnectionHandler> simpleConnectionHandlers = new ArrayList<ISimpleConnectionHandler>();
public static enum ConnectionType
{
LOGIN_SERVER, LOGIN_CLIENT, RECEIVED, OPEN_REMOTE, OPEN_LOCAL, CLOSED
}
/**
* Registers a simple connection handler
*
* @param tileEntity
*/
public static void registerConnectionHandler(ISimpleConnectionHandler tileEntity)
{
simpleConnectionHandlers.add(tileEntity);
}
@Override
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
{
for (ISimpleConnectionHandler handler : simpleConnectionHandlers)
{
handler.handelConnection(ConnectionType.LOGIN_SERVER, player, netHandler, manager);
}
}
@Override
public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login)
{
for (ISimpleConnectionHandler handler : simpleConnectionHandlers)
{
handler.handelConnection(ConnectionType.LOGIN_CLIENT, clientHandler, manager, login);
}
}
@Override
public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager)
{
for (ISimpleConnectionHandler handler : simpleConnectionHandlers)
{
handler.handelConnection(ConnectionType.RECEIVED, netHandler, manager);
}
return null;
}
@Override
public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager)
{
for (ISimpleConnectionHandler handler : simpleConnectionHandlers)
{
handler.handelConnection(ConnectionType.OPEN_REMOTE, netClientHandler, server, port, manager);
}
}
@Override
public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, INetworkManager manager)
{
for (ISimpleConnectionHandler handler : simpleConnectionHandlers)
{
handler.handelConnection(ConnectionType.OPEN_LOCAL, netClientHandler, server, manager);
}
}
@Override
public void connectionClosed(INetworkManager manager)
{
for (ISimpleConnectionHandler handler : simpleConnectionHandlers)
{
handler.handelConnection(ConnectionType.CLOSED, manager);
}
}
}

View file

@ -0,0 +1,14 @@
package universalelectricity.prefab.network;
import universalelectricity.prefab.network.ConnectionHandler.ConnectionType;
public interface ISimpleConnectionHandler
{
/**
* Called when a player logs in. Use this to reset some tile entities
* variables if you need to.
*
* @param player
*/
public void handelConnection(ConnectionType type, Object... data);
}

View file

@ -0,0 +1,104 @@
package universalelectricity.prefab.ore;
import java.util.Random;
import net.minecraft.src.Block;
import net.minecraft.src.IChunkProvider;
import net.minecraft.src.ItemStack;
import net.minecraft.src.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.oredict.OreDictionary;
import universalelectricity.core.UEConfig;
import universalelectricity.core.UniversalElectricity;
/**
* This class is used for storing ore generation data. If you are too lazy to
* generate your own ores, you can do
* {@link #OreGenerator.ORES_TO_GENERATE.add()} to add your ore to the list of
* ores to generate.
*
* @author Calclavia
*
*/
public abstract class OreGenBase
{
public String name;
public String oreDictionaryName;
public boolean shouldGenerate;
public int blockIndexTexture;
public ItemStack oreStack;
public int oreID;
public int oreMeta;
/**
* What harvest level does this machine need to be acquired?
*/
public int harvestLevel;
/**
* The predefined tool classes are "pickaxe", "shovel", "axe". You can add
* others for custom tools.
*/
public String harvestTool;
/**
* @param name
* - The name of the ore for display
* @param textureFile
* - The 16x16 png texture of your ore to override
* @param minGenerateLevel
* - The highest generation level of your ore
* @param maxGenerateLevel
* - The lowest generation level of your ore
* @param amountPerChunk
* - The amount of ores to generate per chunk
* @param amountPerBranch
* - The amount of ores to generate in a clutter. E.g coal
* generates with a lot of other coal next to it. How much do you
* want?
*/
public OreGenBase(String name, String oreDiectionaryName, ItemStack stack, String harvestTool, int harvestLevel)
{
this.name = name;
this.shouldGenerate = false;
this.harvestTool = harvestTool;
this.harvestLevel = harvestLevel;
this.oreDictionaryName = oreDiectionaryName;
this.oreStack = stack;
this.oreID = stack.itemID;
this.oreMeta = stack.getItemDamage();
OreDictionary.registerOre(oreDictionaryName, stack);
MinecraftForge.setBlockHarvestLevel(Block.blocksList[stack.itemID], stack.getItemDamage(), harvestTool, harvestLevel);
}
public OreGenBase enable()
{
this.shouldGenerate = shouldGenerateOre(name);
return this;
}
// You may inherit from this class and change this function if you want a
// custom texture render for your ore.
public int getBlockTextureFromSide(int side)
{
return this.blockIndexTexture;
}
// Checks the config file and see if Universal Electricity should generate
// this ore
private static boolean shouldGenerateOre(String oreName)
{
return UEConfig.getConfigData(UniversalElectricity.CONFIGURATION, "Generate " + oreName, true);
}
public abstract void generate(World world, Random random, int varX, int varZ);
public abstract boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator);
}

View file

@ -0,0 +1,134 @@
package universalelectricity.prefab.ore;
import java.util.Random;
import net.minecraft.src.ChunkProviderEnd;
import net.minecraft.src.ChunkProviderGenerate;
import net.minecraft.src.ChunkProviderHell;
import net.minecraft.src.IChunkProvider;
import net.minecraft.src.ItemStack;
import net.minecraft.src.MathHelper;
import net.minecraft.src.World;
/**
* This class is used for storing ore generation data. If you are too lazy to
* generate your own ores, you can do
* {@link #OreGenerator.ORES_TO_GENERATE.add()} to add your ore to the list of
* ores to generate.
*
* @author Calclavia
*
*/
public class OreGenReplace extends OreGenBase
{
public int minGenerateLevel;
public int maxGenerateLevel;
public int amountPerChunk;
public int amountPerBranch;
public int replaceID;
public boolean generateSurface;
public boolean generateNether;
public boolean generateEnd;
/**
* @param name
* - The name of the ore for display
* @param textureFile
* - The 16x16 png texture of your ore to override
* @param minGenerateLevel
* - The highest generation level of your ore
* @param maxGenerateLevel
* - The lowest generation level of your ore
* @param amountPerChunk
* - The amount of ores to generate per chunk
* @param amountPerBranch
* - The amount of ores to generate in a clutter. E.g coal
* generates with a lot of other coal next to it. How much do you
* want?
*/
public OreGenReplace(String name, String oreDiectionaryName, ItemStack stack, int replaceID, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel)
{
super(name, oreDiectionaryName, stack, harvestTool, harvestLevel);
this.minGenerateLevel = minGenerateLevel;
this.maxGenerateLevel = maxGenerateLevel;
this.amountPerChunk = amountPerChunk;
this.amountPerBranch = amountPerBranch;
this.replaceID = replaceID;
}
public void generate(World world, Random random, int varX, int varZ)
{
for (int i = 0; i < this.amountPerChunk; i++)
{
int x = varX + random.nextInt(16);
int z = varZ + random.nextInt(16);
int y = random.nextInt(this.maxGenerateLevel - this.minGenerateLevel) + this.minGenerateLevel;
generateReplace(world, random, x, y, z);
}
}
public boolean generateReplace(World par1World, Random par2Random, int par3, int par4, int par5)
{
float var6 = par2Random.nextFloat() * (float) Math.PI;
double var7 = (double) ((float) (par3 + 8) + MathHelper.sin(var6) * (float) this.amountPerBranch / 8.0F);
double var9 = (double) ((float) (par3 + 8) - MathHelper.sin(var6) * (float) this.amountPerBranch / 8.0F);
double var11 = (double) ((float) (par5 + 8) + MathHelper.cos(var6) * (float) this.amountPerBranch / 8.0F);
double var13 = (double) ((float) (par5 + 8) - MathHelper.cos(var6) * (float) this.amountPerBranch / 8.0F);
double var15 = (double) (par4 + par2Random.nextInt(3) - 2);
double var17 = (double) (par4 + par2Random.nextInt(3) - 2);
for (int var19 = 0; var19 <= this.amountPerBranch; ++var19)
{
double var20 = var7 + (var9 - var7) * (double) var19 / (double) this.amountPerBranch;
double var22 = var15 + (var17 - var15) * (double) var19 / (double) this.amountPerBranch;
double var24 = var11 + (var13 - var11) * (double) var19 / (double) this.amountPerBranch;
double var26 = par2Random.nextDouble() * (double) this.amountPerBranch / 16.0D;
double var28 = (double) (MathHelper.sin((float) var19 * (float) Math.PI / (float) this.amountPerBranch) + 1.0F) * var26 + 1.0D;
double var30 = (double) (MathHelper.sin((float) var19 * (float) Math.PI / (float) this.amountPerBranch) + 1.0F) * var26 + 1.0D;
int var32 = MathHelper.floor_double(var20 - var28 / 2.0D);
int var33 = MathHelper.floor_double(var22 - var30 / 2.0D);
int var34 = MathHelper.floor_double(var24 - var28 / 2.0D);
int var35 = MathHelper.floor_double(var20 + var28 / 2.0D);
int var36 = MathHelper.floor_double(var22 + var30 / 2.0D);
int var37 = MathHelper.floor_double(var24 + var28 / 2.0D);
for (int var38 = var32; var38 <= var35; ++var38)
{
double var39 = ((double) var38 + 0.5D - var20) / (var28 / 2.0D);
if (var39 * var39 < 1.0D)
{
for (int var41 = var33; var41 <= var36; ++var41)
{
double var42 = ((double) var41 + 0.5D - var22) / (var30 / 2.0D);
if (var39 * var39 + var42 * var42 < 1.0D)
{
for (int var44 = var34; var44 <= var37; ++var44)
{
double var45 = ((double) var44 + 0.5D - var24) / (var28 / 2.0D);
int block = par1World.getBlockId(var38, var41, var44);
if (var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && (this.replaceID == 0 || block == this.replaceID))
{
par1World.setBlockAndMetadata(var38, var41, var44, this.oreID, this.oreMeta);
}
}
}
}
}
}
}
return true;
}
@Override
public boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator)
{
return ((this.generateSurface && chunkGenerator instanceof ChunkProviderGenerate) || (this.generateNether && chunkGenerator instanceof ChunkProviderHell) || (this.generateEnd && chunkGenerator instanceof ChunkProviderEnd));
}
}

View file

@ -0,0 +1,18 @@
package universalelectricity.prefab.ore;
import net.minecraft.src.ItemStack;
public class OreGenReplaceStone extends OreGenReplace
{
public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int replaceID, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel)
{
super(name, oreDiectionaryName, stack, 1, minGenerateLevel, maxGenerateLevel, amountPerChunk, amountPerBranch, harvestTool, harvestLevel);
this.generateSurface = true;
}
// A simplified version of the constructor
public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int replaceID, int maxGenerateLevel, int amountPerChunk, int amountPerBranch)
{
this(name, oreDiectionaryName, stack, 0, replaceID, maxGenerateLevel, amountPerChunk, amountPerBranch, "pickaxe", 1);
}
}

View file

@ -0,0 +1,75 @@
package universalelectricity.prefab.ore;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.src.IChunkProvider;
import net.minecraft.src.World;
import cpw.mods.fml.common.IWorldGenerator;
import cpw.mods.fml.common.registry.GameRegistry;
public class OreGenerator implements IWorldGenerator
{
public static boolean isInitiated = false;
/**
* Add your ore data to this list of ores for it to automatically generate!
* No hassle indeed!
*/
private static final List<OreGenBase> ORES_TO_GENERATE = new ArrayList<OreGenBase>();
/**
* Adds an ore to the ore generate list. Do this in pre-init.
*/
public static void addOre(OreGenBase data)
{
if (!isInitiated)
{
GameRegistry.registerWorldGenerator(new OreGenerator());
}
ORES_TO_GENERATE.add(data);
}
/**
* Checks to see if this ore
*
* @param oreName
* @return
*/
public static boolean oreExists(String oreName)
{
for (OreGenBase ore : ORES_TO_GENERATE)
{
if (ore.oreDictionaryName == oreName) { return true; }
}
return false;
}
/**
* Removes an ore to the ore generate list. Do this in init.
*/
public static void removeOre(OreGenBase data)
{
ORES_TO_GENERATE.remove(data);
}
@Override
public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
chunkX = chunkX << 4;
chunkZ = chunkZ << 4;
// Checks to make sure this is the normal world
for (OreGenBase oreData : ORES_TO_GENERATE)
{
if (oreData.shouldGenerate && oreData.isOreGeneratedInWorld(world, chunkGenerator))
{
oreData.generate(world, rand, chunkX, chunkZ);
}
}
}
}

View file

@ -0,0 +1,41 @@
package universalelectricity.prefab.potion;
import net.minecraft.src.Potion;
import cpw.mods.fml.common.registry.LanguageRegistry;
public abstract class CustomPotion extends Potion
{
/**
* Creates a new type of potion
*
* @param id
* - The ID of this potion. Make it greater than 20.
* @param isBadEffect
* - Is this potion a good potion or a bad one?
* @param color
* - The color of this potion.
* @param name
* - The name of this potion.
*/
public CustomPotion(int id, boolean isBadEffect, int color, String name)
{
super(id, isBadEffect, color);
this.setPotionName("potion." + name);
LanguageRegistry.instance().addStringLocalization(this.getName(), name);
}
@Override
public Potion setIconIndex(int par1, int par2)
{
super.setIconIndex(par1, par2);
return this;
}
/**
* You must register all your potion effects during mod initialization!
*/
public void register()
{
Potion.potionTypes[this.getId()] = this;
}
}

View file

@ -0,0 +1,41 @@
package universalelectricity.prefab.potion;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Potion;
import net.minecraft.src.PotionEffect;
public class CustomPotionEffect extends PotionEffect
{
public CustomPotionEffect(int potionID, int duration, int amplifier)
{
super(potionID, duration, amplifier);
}
public CustomPotionEffect(Potion potion, int duration, int amplifier)
{
this(potion.getId(), duration, amplifier);
}
/**
* Creates a potion effect with custom curable items.
*
* @param curativeItems
* - ItemStacks that can cure this potion effect
*/
public CustomPotionEffect(int potionID, int duration, int amplifier, List<ItemStack> curativeItems)
{
super(potionID, duration, amplifier);
if (curativeItems == null)
{
this.setCurativeItems(new ArrayList<ItemStack>());
}
else
{
this.setCurativeItems(curativeItems);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 791 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 397 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 407 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 534 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 950 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 957 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 957 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB