Updated to UE 1.2.0

This commit is contained in:
Henry Mao 2012-12-08 12:33:18 +08:00
parent 0ba2651413
commit 8a611891fb
54 changed files with 1458 additions and 995 deletions

View file

@ -1 +1 @@
0.1.3
0.1.4

View file

@ -39,6 +39,7 @@ echo open www.calclavia.com>ftpscript.txt
echo al@calclavia.com>>ftpscript.txt
echo VkE4laBa84R9>>ftpscript.txt
echo binary>>ftpscript.txt
echo put "modversion.txt">>ftpscript.txt
echo put "builds\%FILE_NAME%">>ftpscript.txt
echo put "builds\%API_NAME%">>ftpscript.txt
echo put info.txt>>ftpscript.txt

View file

@ -2,7 +2,7 @@
{
"modid" : "AssemblyLine",
"name" : "Assembly Line",
"version" : "0.1.3",
"version" : "0.1.4",
"url" : "http://calclavia.com/universalelectricity/?m=18",
"credits" : "",
"authors": [

View file

@ -8,9 +8,9 @@ import net.minecraft.src.ItemStack;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import universalelectricity.core.UEConfig;
import universalelectricity.core.UniversalElectricity;
import universalelectricity.prefab.UETab;
import universalelectricity.prefab.UpdateNotifier;
import universalelectricity.prefab.network.PacketManager;
import assemblyline.machine.BlockArchitectTable;
import assemblyline.machine.BlockMulti;
@ -33,18 +33,19 @@ import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = "AssemblyLine", name = "Assembly Line", version = AssemblyLine.VERSION, dependencies = "after:BasicComponents")
@NetworkMod(channels =
{ AssemblyLine.CHANNEL }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class)
@Mod(modid = AssemblyLine.CHANNEL, name = AssemblyLine.NAME, version = AssemblyLine.VERSION, dependencies = "after:BasicComponents")
@NetworkMod(channels = { AssemblyLine.CHANNEL }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class)
public class AssemblyLine
{
@SidedProxy(clientSide = "assemblyline.ALClientProxy", serverSide = "assemblyline.ALCommonProxy")
public static ALCommonProxy proxy;
@Instance("AssemblyLine")
@Instance(AssemblyLine.CHANNEL)
public static AssemblyLine instance;
public static final String VERSION = "0.1.3";
public static final String NAME = "Assembly Line";
public static final String VERSION = "0.1.4";
public static final String CHANNEL = "AssemblyLine";
@ -52,20 +53,30 @@ public class AssemblyLine
public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), "UniversalElectricity/AssemblyLine.cfg"));
public static final int BLOCK_ID_PREFIX = 3020;
public static final Block blockConveyorBelt = new BlockConveyorBelt(UEConfig.getBlockConfigID(CONFIGURATION, "Conveyor Belt", BLOCK_ID_PREFIX));
public static final Block blockInteraction = new BlockMulti(UEConfig.getBlockConfigID(CONFIGURATION, "Machine", BLOCK_ID_PREFIX + 1));
public static final Block blockArchitectTable = new BlockArchitectTable(UEConfig.getBlockConfigID(CONFIGURATION, "Architect's Table", BLOCK_ID_PREFIX + 2));
public static final int BLOCK_ID_PREFIX = 3030;
public static Block blockConveyorBelt;
public static Block blockInteraction;
public static Block blockArchitectTable;
@PreInit
public void preInit(FMLPreInitializationEvent event)
{
UniversalElectricity.register(this, 1, 1, 3, false);
instance = this;
CONFIGURATION.load();
blockConveyorBelt = new BlockConveyorBelt(CONFIGURATION.getBlock("Conveyor Belt", BLOCK_ID_PREFIX).getInt());
blockInteraction = new BlockMulti(CONFIGURATION.getBlock("Machine", BLOCK_ID_PREFIX + 1).getInt());
blockArchitectTable = new BlockArchitectTable(CONFIGURATION.getBlock("Architect's Table", BLOCK_ID_PREFIX + 2).getInt());
CONFIGURATION.save();
NetworkRegistry.instance().registerGuiHandler(this, this.proxy);
GameRegistry.registerBlock(blockConveyorBelt);
GameRegistry.registerBlock(blockArchitectTable);
GameRegistry.registerBlock(blockInteraction, ItemBlockMulti.class);
UpdateNotifier.INSTANCE.checkUpdate(NAME, VERSION, "http://calclavia.com/downloads/al/modversion.txt");
proxy.preInit();
}
@ -74,6 +85,8 @@ public class AssemblyLine
{
proxy.init();
//TODO Load language files and use those for block naming
GameRegistry.registerTileEntity(TileEntityConveyorBelt.class, "ConveyorBelt");
GameRegistry.registerTileEntity(TileEntityRejector.class, "Sorter");
GameRegistry.registerTileEntity(TileEntityManipulator.class, "Manipulator");
@ -88,16 +101,13 @@ public class AssemblyLine
}
// Conveyor Belt
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockConveyorBelt, 2), new Object[]
{ "III", "WMW", 'I', "ingotSteel", 'W', Block.wood, 'M', "motor" }));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockConveyorBelt, 2), new Object[] { "III", "WMW", 'I', "ingotSteel", 'W', Block.wood, 'M', "motor" }));
// Rejector
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockInteraction, 1, MachineType.SORTER.metadata), new Object[]
{ "WPW", "@R@", '@', "plateSteel", 'R', Item.redstone, 'P', Block.pistonBase, 'C', "basicCircuit", 'W', "copperWire" }));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockInteraction, 1, MachineType.SORTER.metadata), new Object[] { "WPW", "@R@", '@', "plateSteel", 'R', Item.redstone, 'P', Block.pistonBase, 'C', "basicCircuit", 'W', "copperWire" }));
// Retriever
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(blockInteraction, 1, MachineType.MANIPULATOR.metadata), new Object[]
{ Block.dispenser, "basicCircuit" }));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(blockInteraction, 1, MachineType.MANIPULATOR.metadata), new Object[] { Block.dispenser, "basicCircuit" }));
UETab.setItemStack(new ItemStack(blockConveyorBelt));
}

View file

@ -51,4 +51,9 @@ public class TaskManager
task.onTaskStart();
tasks.add(task);
}
public boolean hasTask()
{
return this.tasks.size() > 0;
}
}

View file

@ -64,8 +64,7 @@ public class BlockMulti extends BlockMachine
}
/**
* @param currentDirection
* - An integer from 0 to 4.
* @param currentDirection - An integer from 0 to 4.
* @return The metadata this block should change into.
*/
public int getNextDirectionMeta(int currentDirection)
@ -110,7 +109,7 @@ public class BlockMulti extends BlockMachine
}
@Override
public boolean onMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer)
public boolean onMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
if (!par1World.isRemote)
{
@ -149,7 +148,7 @@ public class BlockMulti extends BlockMachine
}
@Override
public boolean onUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer)
public boolean onUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
int metadata = par1World.getBlockMetadata(x, y, z);
MachineType machineType = MachineType.get(metadata);
@ -158,7 +157,7 @@ public class BlockMulti extends BlockMachine
}
@Override
public boolean onSneakUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer)
public boolean onSneakUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
int metadata = par1World.getBlockMetadata(x, y, z);
@ -175,7 +174,7 @@ public class BlockMulti extends BlockMachine
}
else
{
return this.onUseWrench(par1World, x, y, z, par5EntityPlayer);
return this.onUseWrench(par1World, x, y, z, par5EntityPlayer, side, hitX, hitY, hitZ);
}
}

View file

@ -16,6 +16,7 @@ import net.minecraft.src.TileEntityChest;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.ISidedInventory;
import universalelectricity.core.electricity.ElectricInfo;
import universalelectricity.core.implement.IConductor;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.implement.IRedstoneReceptor;
import universalelectricity.prefab.network.IPacketReceiver;
@ -32,7 +33,7 @@ public class TileEntityManipulator extends TileEntityElectricityReceiver impleme
/**
* Joules required to run this thing.
*/
public static final int JOULES_REQUIRED = 15;
public static final int WATT_REQUEST = 15;
/**
* The amount of watts received.
@ -46,12 +47,6 @@ public class TileEntityManipulator extends TileEntityElectricityReceiver impleme
private boolean isPowered = false;
@Override
public double wattRequest()
{
return JOULES_REQUIRED;
}
@Override
public void updateEntity()
{
@ -59,7 +54,34 @@ public class TileEntityManipulator extends TileEntityElectricityReceiver impleme
if (!this.worldObj.isRemote)
{
if (!this.isDisabled() && this.wattsReceived >= this.JOULES_REQUIRED)
for (int i = 0; i < 6; i++)
{
ForgeDirection inputDirection = ForgeDirection.getOrientation(i);
TileEntity inputTile = Vector3.getTileEntityFromSide(this.worldObj, Vector3.get(this), inputDirection);
if (inputTile != null)
{
if (inputTile instanceof IConductor)
{
if (this.wattsReceived >= this.WATT_REQUEST)
{
((IConductor) inputTile).getNetwork().stopRequesting(this);
}
else
{
((IConductor) inputTile).getNetwork().startRequesting(this, this.WATT_REQUEST / this.getVoltage(), this.getVoltage());
this.wattsReceived += ((IConductor) inputTile).getNetwork().consumeElectricity(this).getWatts();
}
}
}
}
}
if (!this.worldObj.isRemote)
{
if (!this.isDisabled() && this.wattsReceived >= this.WATT_REQUEST)
{
if (!this.isOutput)
{
@ -186,8 +208,7 @@ public class TileEntityManipulator extends TileEntityElectricityReceiver impleme
*/
if (tileEntity instanceof TileEntityChest)
{
TileEntityChest[] chests =
{ (TileEntityChest) tileEntity, null };
TileEntityChest[] chests = { (TileEntityChest) tileEntity, null };
/**
* Try to find a double chest.
@ -290,8 +311,7 @@ public class TileEntityManipulator extends TileEntityElectricityReceiver impleme
*/
if (tileEntity instanceof TileEntityChest)
{
TileEntityChest[] chests =
{ (TileEntityChest) tileEntity, null };
TileEntityChest[] chests = { (TileEntityChest) tileEntity, null };
/**
* Try to find a double chest.
@ -378,18 +398,6 @@ public class TileEntityManipulator extends TileEntityElectricityReceiver impleme
return PacketManager.getPacket(AssemblyLine.CHANNEL, this, this.isOutput);
}
@Override
public boolean canReceiveFromSide(ForgeDirection side)
{
return true;
}
@Override
public void onReceive(Object sender, double amps, double voltage, ForgeDirection side)
{
this.wattsReceived += ElectricInfo.getWatts(amps, voltage);
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{

View file

@ -1,5 +1,6 @@
package assemblyline.machine;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.src.AxisAlignedBB;
@ -15,6 +16,8 @@ import net.minecraft.src.Packet;
import net.minecraft.src.Packet250CustomPayload;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.electricity.ElectricityConnections;
import universalelectricity.core.implement.IConductor;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.network.PacketManager;
@ -44,7 +47,7 @@ public class TileEntityRejector extends TileEntityElectricityReceiver implements
/**
* Joules required per tick.
*/
public static final int JOULES_REQUIRED = 10;
public static final int WATT_REQUEST = 10;
/**
* Stored energy
@ -57,8 +60,7 @@ public class TileEntityRejector extends TileEntityElectricityReceiver implements
/**
* on/off value for the GUI buttons
*/
public boolean[] guiButtons = new boolean[]
{ true, true, true, true, true };
public boolean[] guiButtons = new boolean[] { true, true, true, true, true };
/**
* the belt found in the search area
*/
@ -71,6 +73,33 @@ public class TileEntityRejector extends TileEntityElectricityReceiver implements
{
super.updateEntity();
if (!this.worldObj.isRemote)
{
for (int i = 0; i < 6; i++)
{
ForgeDirection inputDirection = ForgeDirection.getOrientation(i);
TileEntity inputTile = Vector3.getTileEntityFromSide(this.worldObj, Vector3.get(this), inputDirection);
if (inputTile != null)
{
if (inputTile instanceof IConductor)
{
if (this.wattsReceived >= this.WATT_REQUEST)
{
((IConductor) inputTile).getNetwork().stopRequesting(this);
}
else
{
((IConductor) inputTile).getNetwork().startRequesting(this, this.WATT_REQUEST / this.getVoltage(), this.getVoltage());
this.wattsReceived += ((IConductor) inputTile).getNetwork().consumeElectricity(this).getWatts();
}
}
}
}
}
/**
* Has to update a bit faster than a conveyer belt
*/
@ -104,7 +133,7 @@ public class TileEntityRejector extends TileEntityElectricityReceiver implements
boolean flag = false;
if (itemsBehind.size() > 0 && this.wattsReceived > this.JOULES_REQUIRED)
if (itemsBehind.size() > 0 && this.wattsReceived > this.WATT_REQUEST)
{
// for every item found check
// if can be thrown then throw
@ -143,10 +172,8 @@ public class TileEntityRejector extends TileEntityElectricityReceiver implements
/**
* Used to move after it has been rejected
*
* @param side
* - used to do the offset
* @param entity
* - Entity being thrown
* @param side - used to do the offset
* @param entity - Entity being thrown
*/
public void throwItem(ForgeDirection side, Entity entity)
{
@ -159,12 +186,12 @@ public class TileEntityRejector extends TileEntityElectricityReceiver implements
entity.motionX = (double) side.offsetX * 0.15;
entity.motionY += 0.10000000298023224D;
entity.motionZ = (double) side.offsetZ * 0.15;
this.wattsReceived -= this.JOULES_REQUIRED;
this.wattsReceived -= this.WATT_REQUEST;
}
public boolean canItemBeThrow(Entity entity)
{
// TODO add other things than items
// TODO Add other things than items
if (entity instanceof EntityItem)
{
EntityItem itemE = (EntityItem) entity;
@ -172,7 +199,6 @@ public class TileEntityRejector extends TileEntityElectricityReceiver implements
if (this.guiButtons[4])
{
// reject matching items
for (int i = 0; i < this.containingItems.length; i++)
{
@ -217,12 +243,6 @@ public class TileEntityRejector extends TileEntityElectricityReceiver implements
return 0;
}
@Override
public boolean canReceiveFromSide(ForgeDirection side)
{
return side == ForgeDirection.DOWN;
}
/**
* Used to change any one of the boolean value of on/off array After changing the value if it
* was changed client side it will send a packet server side with the changes
@ -240,8 +260,7 @@ public class TileEntityRejector extends TileEntityElectricityReceiver implements
{
this.guiButtons[i] = true;
}
Packet packet = PacketManager.getPacket("asmLine", this, new Object[]
{ PacketTypes.SETTINGON.ordinal(), i });
Packet packet = PacketManager.getPacket("asmLine", this, new Object[] { PacketTypes.SETTINGON.ordinal(), i });
if (worldObj.isRemote)
{
PacketDispatcher.sendPacketToServer(packet);
@ -254,8 +273,7 @@ public class TileEntityRejector extends TileEntityElectricityReceiver implements
public Object[] data(PacketTypes id)
{
if (id == PacketTypes.ANIMATION) { return new Object[]
{ id.ordinal(), this.firePiston }; }
if (id == PacketTypes.ANIMATION) { return new Object[] { id.ordinal(), this.firePiston }; }
if (id == PacketTypes.GUI)
{
Object[] da = new Object[this.guiButtons.length];
@ -266,8 +284,7 @@ public class TileEntityRejector extends TileEntityElectricityReceiver implements
}
return da;
}
return new Object[]
{ id.ordinal() };
return new Object[] { id.ordinal() };
}
@Override
@ -317,12 +334,6 @@ public class TileEntityRejector extends TileEntityElectricityReceiver implements
return 4;
}
@Override
public boolean canConnect(ForgeDirection side)
{
return true;
}
/**
* UE methods
*/
@ -332,19 +343,6 @@ public class TileEntityRejector extends TileEntityElectricityReceiver implements
return 120;
}
@Override
public double wattRequest()
{
return JOULES_REQUIRED;
}
@Override
public void onReceive(Object sender, double amps, double voltage, ForgeDirection side)
{
this.wattsReceived += (amps * voltage);
}
/**
* Inventory functions.
*/

View file

@ -7,7 +7,6 @@ import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.NBTTagList;
import net.minecraft.src.Packet250CustomPayload;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.tile.TileEntityElectricityReceiver;
import assemblyline.machine.belt.TileEntityConveyorBelt;
@ -32,7 +31,7 @@ public class TileEntityRoboticSorter extends TileEntityElectricityReceiver imple
/**
* Joules required per tick.
*/
public static final int JOULES_REQUIRED = 10;
public static final int WATT_REQUEST = 10;
/**
* Stored energy
@ -41,8 +40,7 @@ public class TileEntityRoboticSorter extends TileEntityElectricityReceiver imple
/**
* on/off value for the GUI buttons
*/
public boolean[] guiButtons = new boolean[]
{ true, true, true, true, true };
public boolean[] guiButtons = new boolean[] { true, true, true, true, true };
/**
* the belt found in the search area
*/
@ -62,34 +60,12 @@ public class TileEntityRoboticSorter extends TileEntityElectricityReceiver imple
return 4;
}
@Override
public boolean canConnect(ForgeDirection side)
{
return true;
}
/**
* UE methods
*/
@Override
public double getVoltage()
{
return 120;
}
@Override
public double wattRequest()
{
return JOULES_REQUIRED;
}
@Override
public void onReceive(Object sender, double amps, double voltage, ForgeDirection side)
{
this.wattsReceived += (amps * voltage);
}
/**
* Inventory functions.
*/
@ -241,12 +217,4 @@ public class TileEntityRoboticSorter extends TileEntityElectricityReceiver imple
{
return 1;
}
@Override
public boolean canReceiveFromSide(ForgeDirection side)
{
// TODO Auto-generated method stub
return false;
}
}

View file

@ -33,7 +33,7 @@ public class BlockConveyorBelt extends BlockMachine
}
@Override
public boolean onUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer)
public boolean onUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
int metadata = par1World.getBlockMetadata(x, y, z);

View file

@ -28,7 +28,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
/**
* Joules required to run this thing.
*/
public static final int JOULES_REQUIRED = 5;
public static final int WATT_REQUEST = 5;
/**
* The amount of watts received.
@ -40,8 +40,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
public boolean running = false;
public boolean textureFlip = false;
public boolean slantedBelt = false;
public TileEntityConveyorBelt[] adjBelts =
{ null, null, null, null };
public TileEntityConveyorBelt[] adjBelts = { null, null, null, null };
public int clearCount = 0;
public int powerTransferRange = 0;
@ -83,7 +82,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
}
this.powerTransferRange = rr - 1;
return false;
}
@ -92,6 +91,33 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
{
super.updateEntity();
if (!this.worldObj.isRemote)
{
for (int i = 0; i < 6; i++)
{
ForgeDirection inputDirection = ForgeDirection.getOrientation(i);
TileEntity inputTile = Vector3.getTileEntityFromSide(this.worldObj, Vector3.get(this), inputDirection);
if (inputTile != null)
{
if (inputTile instanceof IConductor)
{
if (this.wattsReceived >= this.WATT_REQUEST)
{
((IConductor) inputTile).getNetwork().stopRequesting(this);
}
else
{
((IConductor) inputTile).getNetwork().startRequesting(this, this.WATT_REQUEST / this.getVoltage(), this.getVoltage());
this.wattsReceived += ((IConductor) inputTile).getNetwork().consumeElectricity(this).getWatts();
}
}
}
}
}
if (this.ticks % 10 == 0)
{
if (!worldObj.isRemote)
@ -99,7 +125,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
PacketManager.sendPacketToClients(this.getDescriptionPacket(), this.worldObj, Vector3.get(this), 15);
}
if (this.wattsReceived >= JOULES_REQUIRED)
if (this.wattsReceived >= WATT_REQUEST)
{
this.wattsReceived = 0;
this.powerTransferRange = 20;
@ -144,10 +170,8 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
/**
* Causes all items to be moved above the belt
*
* @param extendLife
* - increases the items life
* @param preventPickUp
* - prevent a player from picking the item up
* @param extendLife - increases the items life
* @param preventPickUp - prevent a player from picking the item up
*/
public void conveyItemsHorizontal(boolean extendLife, boolean preventPickUp)
{
@ -166,22 +190,22 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
if (direction == 0)
{
entity.motionZ -= 1 * this.speed;
//entity.posX = this.xCoord + 0.5D;
// entity.posX = this.xCoord + 0.5D;
}
if (direction == 1)
{
entity.motionX += 1 * this.speed;
//entity.posZ = this.zCoord + 0.5D;
// entity.posZ = this.zCoord + 0.5D;
}
if (direction == 2)
{
entity.motionZ += 1 * this.speed;
//entity.posX = this.xCoord + 0.5D;
// entity.posX = this.xCoord + 0.5D;
}
if (direction == 3)
{
entity.motionX -= 1 * this.speed;
//entity.posZ = this.zCoord + 0.5D;
// entity.posZ = this.zCoord + 0.5D;
}
}
}
@ -219,24 +243,6 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
return PacketManager.getPacket(AssemblyLine.CHANNEL, this, this.wattsReceived);
}
@Override
public double wattRequest()
{
return JOULES_REQUIRED;
}
@Override
public void onReceive(Object sender, double amps, double voltage, ForgeDirection side)
{
this.wattsReceived += ElectricInfo.getWatts(amps, voltage);
}
@Override
public boolean canReceiveFromSide(ForgeDirection side)
{
return side == ForgeDirection.DOWN;
}
public int getBeltDirection()
{
int meta = worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord);

View file

@ -56,8 +56,7 @@ public class BlockCrafter extends BlockMachine
}
/**
* @param currentDirection
* - An integer from 0 to 4.
* @param currentDirection - An integer from 0 to 4.
* @return The metadata this block should change into.
*/
public int getNextDirectionMeta(int currentDirection)
@ -103,7 +102,7 @@ public class BlockCrafter extends BlockMachine
}
@Override
public boolean onMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer)
public boolean onMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
if (!par1World.isRemote)
{
@ -117,7 +116,8 @@ public class BlockCrafter extends BlockMachine
return true;
}
public boolean onSneakUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer)
@Override
public boolean onSneakUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
return false;
}

View file

@ -1,5 +1,7 @@
package assemblyline.machines.crafter;
import java.util.EnumSet;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IInventory;
import net.minecraft.src.INetworkManager;
@ -7,14 +9,19 @@ import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.NBTTagList;
import net.minecraft.src.Packet250CustomPayload;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.electricity.ElectricityConnections;
import universalelectricity.core.implement.IConductor;
import universalelectricity.core.implement.IJouleStorage;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.tile.TileEntityElectricityReceiver;
import assemblyline.ai.TaskManager;
import com.google.common.io.ByteArrayDataInput;
public class TileEntityCraftingArm extends TileEntityElectricityReceiver implements IInventory, IPacketReceiver
public class TileEntityCraftingArm extends TileEntityElectricityReceiver implements IInventory, IPacketReceiver, IJouleStorage
{
/**
* The items this container contains.
@ -28,27 +35,56 @@ public class TileEntityCraftingArm extends TileEntityElectricityReceiver impleme
*/
public EntityCraftingArm EntityArm = null;
public double wattUsed = 20;
public final double WATT_REQUEST = 20;
public double jouleReceived = 0;
public double maxJoules = 100;
/**
* does this arm have a task to do
*/
public boolean hasTask = true;
public double wattsReceived = 0;
private int playerUsing = 0;
@Override
public void initiate()
{
ElectricityConnections.registerConnector(this, EnumSet.of(ForgeDirection.DOWN, ForgeDirection.SOUTH, ForgeDirection.NORTH, ForgeDirection.EAST, ForgeDirection.WEST));
}
public void updateEntity()
{
super.updateEntity();
if (!this.worldObj.isRemote)
{
for (int i = 0; i < 6; i++)
{
ForgeDirection inputDirection = ForgeDirection.getOrientation(i);
if (inputDirection != ForgeDirection.UP)
{
TileEntity inputTile = Vector3.getTileEntityFromSide(this.worldObj, Vector3.get(this), inputDirection);
if (inputTile != null)
{
if (inputTile instanceof IConductor)
{
if (this.getJoules() >= this.getMaxJoules())
{
((IConductor) inputTile).getNetwork().stopRequesting(this);
}
else
{
((IConductor) inputTile).getNetwork().startRequesting(this, this.WATT_REQUEST / this.getVoltage(), this.getVoltage());
this.setJoules(this.getJoules() + ((IConductor) inputTile).getNetwork().consumeElectricity(this).getWatts());
}
}
}
}
}
}
taskManager.onUpdate();
if (this.ticks % 5 == 0 && !this.isDisabled() && this.hasTask && EntityArm != null)
if (this.ticks % 5 == 0 && !this.isDisabled() && this.taskManager.hasTask() && EntityArm != null)
{
this.jouleReceived -= this.wattUsed;
this.wattsReceived -= this.WATT_REQUEST;
this.doWork();
}
}
@ -61,36 +97,6 @@ public class TileEntityCraftingArm extends TileEntityElectricityReceiver impleme
}
/**
* UE methods
*/
@Override
public void onReceive(Object 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 boolean canConnect(ForgeDirection side)
{
if (side != ForgeDirection.UP) { return true; }
return false;
}
@Override
public double getVoltage()
{
@ -255,4 +261,22 @@ public class TileEntityCraftingArm extends TileEntityElectricityReceiver impleme
nbt.setTag("Items", var2);
}
@Override
public double getJoules(Object... data)
{
return this.wattsReceived;
}
@Override
public void setJoules(double joules, Object... data)
{
this.wattsReceived = joules;
}
@Override
public double getMaxJoules(Object... data)
{
return 1000;
}
}

View file

@ -1,50 +0,0 @@
package universalelectricity.core;
import net.minecraftforge.common.Configuration;
public class UEConfig
{
public static int getConfigData(Configuration configuration, String name, int defaultInt)
{
configuration.load();
int returnInt = defaultInt;
returnInt = Integer.parseInt(configuration.get(name, Configuration.CATEGORY_GENERAL, defaultInt).value);
configuration.save();
return returnInt;
}
public static boolean getConfigData(Configuration configuration, String name, boolean defaultBoolean)
{
configuration.load();
boolean returnBoolean = defaultBoolean;
returnBoolean = Boolean.parseBoolean(configuration.get(name, Configuration.CATEGORY_GENERAL, defaultBoolean).value);
configuration.save();
return returnBoolean;
}
public static int getBlockConfigID(Configuration configuration, String name, int defaultID)
{
configuration.load();
int id = defaultID;
id = Integer.parseInt(configuration.getBlock(name, defaultID).value);
if (id <= 136) { return defaultID; }
configuration.save();
return id;
}
public static int getItemConfigID(Configuration configuration, String name, int defaultID)
{
configuration.load();
int id = defaultID;
id = Integer.parseInt(configuration.getItem(name, Configuration.CATEGORY_ITEM, defaultID).value);
if (id < 256) { return defaultID; }
configuration.save();
return id;
}
}

View file

@ -2,14 +2,10 @@ package universalelectricity.core;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.world.WorldEvent.Load;
import net.minecraftforge.event.world.WorldEvent.Unload;
import universalelectricity.core.electricity.ElectricityManager;
import universalelectricity.core.electricity.ElectricityManagerTicker;
import universalelectricity.core.electricity.Electricity;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.registry.TickRegistry;
/**
* A class used to load Universal Electricity and make it work.
@ -27,8 +23,7 @@ public class UELoader
{
if (!isInitialized)
{
TickRegistry.registerTickHandler(new ElectricityManagerTicker(), Side.SERVER);
ElectricityManager.instance = new ElectricityManager();
Electricity.instance = new Electricity();
MinecraftForge.EVENT_BUS.register(this);
if (UniversalElectricity.BC3_RATIO <= 0 || !Loader.isModLoaded("BuildCraft|Core"))
@ -51,19 +46,18 @@ public class UELoader
FMLLog.finest("Universal Electricity v" + UniversalElectricity.VERSION + " successfully loaded!");
UniversalElectricity.IC2_RATIO = UniversalElectricity.CONFIGURATION.get("Compatiblity", "IndustrialCraft Conversion Ratio", UniversalElectricity.IC2_RATIO).getInt();
UniversalElectricity.BC3_RATIO = UniversalElectricity.CONFIGURATION.get("Compatiblity", "BuildCraft Conversion Ratio", UniversalElectricity.BC3_RATIO).getInt();
UniversalElectricity.TO_IC2_RATIO = 1 / UniversalElectricity.IC2_RATIO;
UniversalElectricity.TO_BC_RATIO = 1 / UniversalElectricity.BC3_RATIO;
isInitialized = true;
}
}
@ForgeSubscribe
public void onWorldLoad(Load event)
{
ElectricityManagerTicker.inGameTicks = 0;
}
@ForgeSubscribe
public void onWorldUnload(Unload event)
{
ElectricityManager.instance = new ElectricityManager();
Electricity.instance = new Electricity();
}
}

View file

@ -30,8 +30,8 @@ public class UniversalElectricity
* The version of the Universal Electricity API.
*/
public static final int MAJOR_VERSION = 1;
public static final int MINOR_VERSION = 1;
public static final int REVISION_VERSION = 3;
public static final int MINOR_VERSION = 2;
public static final int REVISION_VERSION = 0;
public static final String VERSION = MAJOR_VERSION + "." + MINOR_VERSION + "." + REVISION_VERSION;
/**
@ -43,11 +43,11 @@ public class UniversalElectricity
* Conversion ratios between Buildcraft and Industrialcraft energy.
*/
// EU to Watts ratio
public static final float IC2_RATIO = (float) UEConfig.getConfigData(CONFIGURATION, "IndustrialCraft Conversion Ratio", 7);
public static int IC2_RATIO = 7;
// MJ to Watts ratio.
public static final float BC3_RATIO = (float) UEConfig.getConfigData(CONFIGURATION, "BuildCraft Conversion Ratio", 85);;
public static final float TO_IC2_RATIO = 1 / IC2_RATIO;
public static final float TO_BC_RATIO = 1 / BC3_RATIO;
public static int BC3_RATIO = 85;
public static int TO_IC2_RATIO = 1 / IC2_RATIO;
public static int TO_BC_RATIO = 1 / BC3_RATIO;
/**
* Use this material for all your machine blocks. It can be breakable by hand.
@ -62,19 +62,19 @@ public class UniversalElectricity
*/
public static void register(Object mod, int major, int minor, int revision, boolean strict)
{
if (MAJOR_VERSION != major) { throw new RuntimeException("Universal Electricity wrong version! Require v" + major + "." + minor + "." + revision); }
if (MAJOR_VERSION != major) { throw new RuntimeException("A Universal Electricity mod is way too old! Make sure it is update to v" + major + "." + minor + "." + revision); }
if (MINOR_VERSION < minor) { throw new RuntimeException("Universal Electricity minor version is too old! Require v" + major + "." + minor + "." + revision); }
if (MINOR_VERSION < minor) { throw new RuntimeException("A Universal Electricity mod is too old! Make sure it is update to v" + major + "." + minor + "." + revision); }
if (REVISION_VERSION < revision)
{
if (strict)
{
throw new RuntimeException("Universal Electricity is too old! Require v" + major + "." + minor + "." + revision);
throw new RuntimeException("A Universal Electricity mod is too old! Require v" + major + "." + minor + "." + revision);
}
else
{
FMLLog.warning("Universal Electricity is not the specified version. Odd things might happen. Recommend to have v" + major + "." + minor + "." + revision);
FMLLog.warning("The version of Universal Electricity detected is not the recommended version by the mod. Odd things might happen. Recommended to try v" + major + "." + minor + "." + revision);
}
}

View file

@ -186,8 +186,7 @@ public class ElectricInfo
/**
* Rounds a number to a specific number place places
*
* @param The
* number
* @param The number
* @return The rounded number
*/
public static double roundDecimals(double d, int significantFigures)

View file

@ -0,0 +1,142 @@
package universalelectricity.core.electricity;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.implement.IConductor;
import universalelectricity.core.vector.Vector3;
import cpw.mods.fml.common.FMLLog;
/**
* THIS IS THE NEW ELECTRICITY MANAGER. THIS IS ONLY A DRAFT!
*
* The Electricity Network Manager.
*
* @author Calclavia
*
*/
public class Electricity
{
public static Electricity instance = new Electricity();
private List<ElectricityNetwork> electricityNetworks = new ArrayList<ElectricityNetwork>();
/**
* Registers a conductor into the UE electricity net.
*/
public void registerConductor(IConductor newConductor)
{
this.cleanUpNetworks();
ElectricityNetwork newNetwork = new ElectricityNetwork(newConductor);
this.electricityNetworks.add(newNetwork);
}
public void unregister(TileEntity tileEntity)
{
for (ElectricityNetwork network : this.electricityNetworks)
{
network.stopProducing(tileEntity);
network.stopRequesting(tileEntity);
}
}
/**
* Merges two connection lines together into one.
*
* @param networkA - The network to be merged into. This network will be kept.
* @param networkB - The network to be merged. This network will be deleted.
*/
public void mergeConnection(ElectricityNetwork networkA, ElectricityNetwork networkB)
{
if (networkA != networkB)
{
if (networkA != null && networkB != null)
{
networkA.conductors.addAll(networkB.conductors);
networkA.setNetwork();
this.electricityNetworks.remove(networkB);
networkB = null;
networkA.cleanConductors();
}
else
{
System.err.println("Failed to merge Universal Electricity wire connections!");
}
}
}
/**
* Separate one connection line into two different ones between two conductors. This function
* does this by resetting all wires in the connection line and making them each reconnect.
*
* @param conductorA - existing conductor
* @param conductorB - broken/invalid conductor
*/
public void splitConnection(IConductor conductorA, IConductor conductorB)
{
ElectricityNetwork network = conductorA.getNetwork();
if (network != null)
{
network.cleanConductors();
network.resetConductors();
for (IConductor conductor : network.conductors)
{
for (byte i = 0; i < 6; i++)
{
conductor.updateConnectionWithoutSplit(Vector3.getConnectorFromSide(((TileEntity) conductor).worldObj, Vector3.get((TileEntity) conductor), ForgeDirection.getOrientation(i)), ForgeDirection.getOrientation(i));
}
}
}
else
{
FMLLog.severe("Conductor invalid network while splitting connection!");
}
}
/**
* Clean up and remove all useless and invalid connections.
*/
public void cleanUpNetworks()
{
try
{
Iterator it = electricityNetworks.iterator();
while (it.hasNext())
{
ElectricityNetwork network = ((ElectricityNetwork) it.next());
network.cleanConductors();
if (network.conductors.size() == 0)
{
it.remove();
}
}
}
catch (Exception e)
{
FMLLog.severe("Failed to clean up wire connections!");
e.printStackTrace();
}
}
public void resetConductors()
{
Iterator it = electricityNetworks.iterator();
while (it.hasNext())
{
ElectricityNetwork network = ((ElectricityNetwork) it.next());
network.resetConductors();
}
System.out.println(electricityNetworks.size());
}
}

View file

@ -0,0 +1,52 @@
package universalelectricity.core.electricity;
import java.util.EnumSet;
import java.util.HashMap;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;
/**
* Register your block to allow a wire connection with this class. This class manages the visual
* aspect of a wire connection and does not effect the actual transmission of electricity.
*
* @author Calclavia
*
*/
public class ElectricityConnections
{
private static final HashMap<TileEntity, EnumSet<ForgeDirection>> connectors = new HashMap<TileEntity, EnumSet<ForgeDirection>>();
/**
* Registers a block to allow connection from Universal Electricity wires.
*
* @param tileEntity - The TileEntity
* @param connectableDirections - Directions that allow connection
*/
public static void registerConnector(TileEntity tileEntity, EnumSet<ForgeDirection> connectableDirections)
{
connectors.put(tileEntity, connectableDirections);
}
public static boolean isConnector(TileEntity tileEntity)
{
return connectors.containsKey(tileEntity);
}
public static boolean canConnect(TileEntity tileEntity, ForgeDirection side)
{
EnumSet<ForgeDirection> enumSet = connectors.get(tileEntity);
if (enumSet != null) { return enumSet.contains(side); }
return false;
}
/**
* Returns the directions in which this block may connect or be connected from.
*/
public static EnumSet<ForgeDirection> getDirections(TileEntity tileEntity)
{
return connectors.get(tileEntity);
}
}

View file

@ -1,413 +0,0 @@
package universalelectricity.core.electricity;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.minecraft.src.Entity;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.implement.IConductor;
import universalelectricity.core.implement.IElectricityReceiver;
import universalelectricity.core.vector.Vector3;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.TickType;
/**
* This class is used to manage electricity transferring and flow. It is also used to call updates
* on UE tile entities.
*
* @author Calclavia
*
*/
public class ElectricityManager
{
/**
* ElectricityManager exists on both client and server side. Rely on the server side one as it
* is more accurate! Client side only simulates.
*/
public static ElectricityManager instance;
private List<ElectricityTransferData> electricityTransferQueue = new ArrayList<ElectricityTransferData>();
private List<ElectricityNetwork> electricityNetworks = new ArrayList<ElectricityNetwork>();
public ElectricityManager()
{
System.out.println("Universal Electricity's Electricity Manager Initiated.");
}
/**
* Registers a the conductor into the UE electricity net.
*
* @param conductor
* - The IConductor tile entity.
*/
public void registerConductor(IConductor newConductor)
{
cleanUpConnections();
this.electricityNetworks.add(new ElectricityNetwork(newConductor));
}
/**
* Merges two connection lines together into one.
*
* @param networkA
* - The network to be merged into. This network will be kept.
* @param networkB
* - The network to be merged. This network will be deleted.
*/
public void mergeConnection(ElectricityNetwork networkA, ElectricityNetwork networkB)
{
if (networkA != networkB)
{
if (networkA != null && networkB != null)
{
networkA.conductors.addAll(networkB.conductors);
networkA.setNetwork();
this.electricityNetworks.remove(networkB);
networkB = null;
}
else
{
System.err.println("Failed to merge Universal Electricity wire connections!");
}
}
}
/**
* Separate one connection line into two different ones between two conductors. This function
* does this by resetting all wires in the connection line and making them each reconnect.
*
* @param conductorA
* - existing conductor
* @param conductorB
* - broken/invalid conductor
*/
public void splitConnection(IConductor conductorA, IConductor conductorB)
{
ElectricityNetwork connection = conductorA.getNetwork();
if (connection != null)
{
connection.cleanUpArray();
for (IConductor conductor : connection.conductors)
{
conductor.reset();
}
for (IConductor conductor : connection.conductors)
{
for (byte i = 0; i < 6; i++)
{
conductor.updateConnectionWithoutSplit(Vector3.getConnectorFromSide(conductor.getWorld(), new Vector3(((TileEntity) conductor).xCoord, ((TileEntity) conductor).yCoord, ((TileEntity) conductor).zCoord), ForgeDirection.getOrientation(i)), ForgeDirection.getOrientation(i));
}
}
}
else
{
FMLLog.severe("Conductor invalid network while splitting connection!");
}
}
/**
* Clean up and remove all useless and invalid connections.
*/
public void cleanUpConnections()
{
try
{
for (int i = 0; i < this.electricityNetworks.size(); i++)
{
this.electricityNetworks.get(i).cleanUpArray();
if (this.electricityNetworks.get(i).conductors.size() == 0)
{
this.electricityNetworks.remove(i);
}
}
}
catch (Exception e)
{
FMLLog.severe("Failed to clean up wire connections!");
}
}
/**
* Produces electricity into a specific wire which will be distributed across the electricity
* network.
*
* @param sender
* The machine sending the electricity.
* @param targetConductor
* The conductor receiving the electricity (or connected to the machine).
* @param amps
* The amount of amps this machine is sending.
* @param voltage
* The amount of volts this machine is sending.
*/
public void produceElectricity(Object sender, IConductor targetConductor, double amps, double voltage)
{
if (targetConductor != null && amps > 0 && voltage > 0)
{
// Find a path between this conductor
// and all connected units and
// try to send the electricity to them
// directly
ElectricityNetwork electricityNetwork = targetConductor.getNetwork();
if (electricityNetwork != null)
{
List<IElectricityReceiver> allElectricUnitsInLine = electricityNetwork.getConnectedReceivers();
double leftOverAmps = amps;
for (IConductor conductor : electricityNetwork.conductors)
{
for (byte i = 0; i < conductor.getConnectedBlocks().length; i++)
{
TileEntity tileEntity = conductor.getConnectedBlocks()[i];
if (tileEntity != null)
{
if (tileEntity instanceof IElectricityReceiver)
{
IElectricityReceiver receiver = (IElectricityReceiver) tileEntity;
if (this.getActualWattRequest(receiver) > 0 && receiver.canReceiveFromSide(ForgeDirection.getOrientation(i).getOpposite()))
{
double transferAmps = Math.max(0, Math.min(leftOverAmps, Math.min(amps / allElectricUnitsInLine.size(), ElectricInfo.getAmps(this.getActualWattRequest(receiver), receiver.getVoltage()))));
leftOverAmps -= transferAmps;
double ampsReceived = transferAmps;
double voltsReceived = voltage;
if (sender instanceof TileEntity)
{
// Calculate electricity loss
double distance = Vector3.distance(Vector3.get((TileEntity) sender), Vector3.get((TileEntity) receiver));
ampsReceived = transferAmps - (transferAmps * transferAmps * targetConductor.getResistance() * distance) / voltage;
voltsReceived = voltage - (transferAmps * targetConductor.getResistance() * distance);
}
this.electricityTransferQueue.add(new ElectricityTransferData(sender, receiver, electricityNetwork, ForgeDirection.getOrientation(i).getOpposite(), ampsReceived, voltsReceived));
}
}
}
}
}
}
else
{
FMLLog.severe("Conductor not registered to a network!");
}
}
}
public void produceElectricity(Object sender, Entity entity, double amps, double voltage, ForgeDirection outputDirection)
{
if (entity instanceof IElectricityReceiver)
{
IElectricityReceiver electricEntity = ((IElectricityReceiver) entity);
if (electricEntity.wattRequest() > 0)
{
if (electricEntity.canReceiveFromSide(outputDirection.getOpposite()))
{
electricEntity.onReceive(this, amps, voltage, outputDirection.getOpposite());
}
}
}
}
/**
* Gets the actual watt request of an electric receiver accounting all current electricity
* packets qued up for it.
*
* @return - The amount of watts requested.
*/
public double getActualWattRequest(IElectricityReceiver receiver)
{
double wattsRequest = receiver.wattRequest();
try
{
for (int i = 0; i < electricityTransferQueue.size(); i++)
{
if (electricityTransferQueue.get(i) != null)
{
if (electricityTransferQueue.get(i).isValid())
{
if (electricityTransferQueue.get(i).receiver == receiver)
{
wattsRequest -= electricityTransferQueue.get(i).amps * electricityTransferQueue.get(i).voltage;
}
}
}
}
}
catch (Exception e)
{
FMLLog.severe("Failed to get watt request!");
}
return Math.max(Math.min(wattsRequest, receiver.wattRequest()), 0);
}
/**
* Checks if the current connection line needs electricity
*
* @return - The amount of joules this connection line needs
*/
public double getElectricityRequired(ElectricityNetwork network)
{
double need = 0;
if (network != null)
{
for (IConductor conductor : network.conductors)
{
for (byte i = 0; i < conductor.getConnectedBlocks().length; i++)
{
TileEntity tileEntity = conductor.getConnectedBlocks()[i];
if (tileEntity != null)
{
if (tileEntity instanceof IElectricityReceiver)
{
IElectricityReceiver electricUnit = (IElectricityReceiver) tileEntity;
if (electricUnit.canReceiveFromSide(ForgeDirection.getOrientation(i).getOpposite()))
{
need += electricUnit.wattRequest();
}
}
}
}
}
}
return need;
}
public double getActualElectricityRequired(ElectricityNetwork network)
{
double need = 0;
if (network != null)
{
for (IConductor conductor : network.conductors)
{
for (byte i = 0; i < conductor.getConnectedBlocks().length; i++)
{
TileEntity tileEntity = conductor.getConnectedBlocks()[i];
if (tileEntity != null)
{
if (tileEntity instanceof IElectricityReceiver)
{
IElectricityReceiver electricUnit = (IElectricityReceiver) tileEntity;
if (electricUnit.canReceiveFromSide(ForgeDirection.getOrientation(i).getOpposite()))
{
need += this.getActualWattRequest(electricUnit);
}
}
}
}
}
}
return need;
}
/**
* This function is called to refresh all conductors in the world.
*/
public void refreshConductors()
{
try
{
Iterator it = electricityNetworks.iterator();
while (it.hasNext())
{
((ElectricityNetwork) it.next()).refreshConductors();
}
}
catch (Exception e)
{
FMLLog.fine("Failed to refresh conductors.");
}
}
public void onTick(EnumSet<TickType> type, Object... tickData)
{
if (ElectricityManagerTicker.inGameTicks % 40 == 0)
{
this.refreshConductors();
}
if (type.contains(TickType.WORLD) && !type.contains(TickType.WORLDLOAD))
{
try
{
HashMap conductorAmpData = new HashMap<ElectricityNetwork, Double>();
for (int i = 0; i < electricityTransferQueue.size(); i++)
{
if (electricityTransferQueue.get(i) != null)
{
if (electricityTransferQueue.get(i).isValid())
{
double amps = electricityTransferQueue.get(i).amps;
if (conductorAmpData.containsKey(electricityTransferQueue.get(i).network))
{
amps += (Double) conductorAmpData.get(electricityTransferQueue.get(i).network);
}
conductorAmpData.put(electricityTransferQueue.get(i).network, amps);
electricityTransferQueue.get(i).receiver.onReceive(electricityTransferQueue.get(i).sender, electricityTransferQueue.get(i).amps, electricityTransferQueue.get(i).voltage, electricityTransferQueue.get(i).side);
}
}
electricityTransferQueue.remove(i);
}
Iterator it = conductorAmpData.entrySet().iterator();
while (it.hasNext())
{
Map.Entry pairs = (Map.Entry) it.next();
if (pairs.getKey() != null && pairs.getValue() != null)
{
if (pairs.getKey() instanceof ElectricityNetwork && pairs.getValue() instanceof Double)
{
if (((Double) pairs.getValue()) > ((ElectricityNetwork) pairs.getKey()).getLowestAmpConductor())
{
((ElectricityNetwork) pairs.getKey()).onOverCharge();
}
}
}
it.remove();
}
}
catch (Exception e)
{
System.err.println("Failed to transfer electricity to receivers.");
e.printStackTrace();
}
}
if (ElectricityManagerTicker.inGameTicks == 0)
{
this.refreshConductors();
}
}
}

View file

@ -1,45 +0,0 @@
package universalelectricity.core.electricity;
import java.util.EnumSet;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
public class ElectricityManagerTicker implements ITickHandler
{
public static long inGameTicks = 0;
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
if (ElectricityManager.instance != null)
{
ElectricityManager.instance.onTick(type, tickData);
}
inGameTicks++;
if (inGameTicks >= Long.MAX_VALUE)
{
inGameTicks = 0;
}
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
}
@Override
public EnumSet<TickType> ticks()
{
return EnumSet.of(TickType.WORLD, TickType.WORLDLOAD, TickType.SERVER);
}
@Override
public String getLabel()
{
return "Electricity Manager";
}
}

View file

@ -1,25 +1,240 @@
package universalelectricity.core.electricity;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.implement.IConductor;
import universalelectricity.core.implement.IElectricityReceiver;
import cpw.mods.fml.common.FMLLog;
public class ElectricityNetwork
{
public List<IConductor> conductors = new ArrayList<IConductor>();
private final HashMap<TileEntity, ElectricityPack> producers = new HashMap<TileEntity, ElectricityPack>();
private final HashMap<TileEntity, ElectricityPack> consumers = new HashMap<TileEntity, ElectricityPack>();
public final List<IConductor> conductors = new ArrayList<IConductor>();
public ElectricityNetwork(IConductor conductor)
{
this.addConductor(conductor);
}
/**
* Sets this tile entity to start producing energy in this network.
*/
public void startProducing(TileEntity tileEntity, double amperes, double voltage)
{
if (tileEntity != null && amperes > 0 && voltage > 0)
{
this.producers.put(tileEntity, new ElectricityPack(amperes, voltage));
}
}
public boolean isProducing(TileEntity tileEntity)
{
return this.producers.containsKey(tileEntity);
}
/**
* Sets this tile entity to stop producing energy in this network.
*/
public void stopProducing(TileEntity tileEntity)
{
this.producers.remove(tileEntity);
}
/**
* Sets this tile entity to start producing energy in this network.
*/
public void startRequesting(TileEntity tileEntity, double amperes, double voltage)
{
if (tileEntity != null && amperes > 0 && voltage > 0)
{
this.consumers.put(tileEntity, new ElectricityPack(amperes, voltage));
}
}
public boolean isRequesting(TileEntity tileEntity)
{
return this.consumers.containsKey(tileEntity);
}
/**
* Sets this tile entity to stop producing energy in this network.
*/
public void stopRequesting(TileEntity tileEntity)
{
this.consumers.remove(tileEntity);
}
/**
* @return The electricity produced in this electricity network
*/
public ElectricityPack getProduced()
{
ElectricityPack totalElectricity = new ElectricityPack(0, 0);
Iterator it = this.producers.entrySet().iterator();
while (it.hasNext())
{
Map.Entry pairs = (Map.Entry) it.next();
if (pairs != null)
{
TileEntity tileEntity = (TileEntity) pairs.getKey();
if (tileEntity == null)
{
it.remove();
continue;
}
if (tileEntity.isInvalid())
{
it.remove();
continue;
}
if (tileEntity.worldObj.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) != tileEntity)
{
it.remove();
continue;
}
ElectricityPack pack = (ElectricityPack) pairs.getValue();
if (pairs.getKey() != null && pairs.getValue() != null && pack != null)
{
totalElectricity.amperes += pack.amperes;
totalElectricity.voltage = Math.max(totalElectricity.voltage, pack.voltage);
}
}
}
return totalElectricity;
}
/**
* @return How much electricity this network needs.
*/
public ElectricityPack getRequest()
{
ElectricityPack totalElectricity = this.getRequestWithoutReduction();
totalElectricity.amperes = Math.max(totalElectricity.amperes - this.getProduced().amperes, 0);
return totalElectricity;
}
public ElectricityPack getRequestWithoutReduction()
{
ElectricityPack totalElectricity = new ElectricityPack(0, 0);
Iterator it = this.consumers.entrySet().iterator();
while (it.hasNext())
{
Map.Entry pairs = (Map.Entry) it.next();
if (pairs != null)
{
TileEntity tileEntity = (TileEntity) pairs.getKey();
if (tileEntity == null)
{
it.remove();
continue;
}
if (tileEntity.isInvalid())
{
it.remove();
continue;
}
if (tileEntity.worldObj.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) != tileEntity)
{
it.remove();
continue;
}
ElectricityPack pack = (ElectricityPack) pairs.getValue();
if (pack != null)
{
totalElectricity.amperes += pack.amperes;
totalElectricity.voltage = Math.max(totalElectricity.voltage, pack.voltage);
}
}
}
return totalElectricity;
}
/**
* @param tileEntity
* @return The electricity being input into this tile entity.
*/
public ElectricityPack consumeElectricity(TileEntity tileEntity)
{
ElectricityPack totalElectricity = new ElectricityPack(0, 0);
try
{
ElectricityPack tileRequest = this.consumers.get(tileEntity);
if (this.consumers.containsKey(tileEntity) && tileRequest != null)
{
// Calculate the electricity this tile entity is receiving in percentage.
totalElectricity = this.getProduced();
if (totalElectricity.getWatts() > 0)
{
ElectricityPack totalRequest = this.getRequestWithoutReduction();
totalElectricity.amperes *= (tileRequest.amperes / totalRequest.amperes);
int distance = this.conductors.size();
double ampsReceived = totalElectricity.amperes - (totalElectricity.amperes * totalElectricity.amperes * this.getResistance() * distance) / totalElectricity.voltage;
double voltsReceived = totalElectricity.voltage - (totalElectricity.amperes * this.getResistance() * distance);
totalElectricity.amperes = ampsReceived;
totalElectricity.voltage = voltsReceived;
return totalElectricity;
}
}
}
catch (Exception e)
{
FMLLog.severe("Failed to consume electricity!");
e.printStackTrace();
}
return totalElectricity;
}
/**
* @return Returns all producers in this electricity network.
*/
public HashMap<TileEntity, ElectricityPack> getProducers()
{
return this.producers;
}
/**
* @return Returns all consumers in this electricity network.
*/
public HashMap<TileEntity, ElectricityPack> getConsumers()
{
return this.consumers;
}
public void addConductor(IConductor newConductor)
{
this.cleanUpArray();
this.cleanConductors();
if (!conductors.contains(newConductor))
{
@ -31,34 +246,26 @@ public class ElectricityNetwork
/**
* Get only the electric units that can receive electricity from the given side.
*/
public List<IElectricityReceiver> getConnectedReceivers()
public List<TileEntity> getReceivers()
{
this.cleanUpArray();
List<IElectricityReceiver> returnArray = new ArrayList<IElectricityReceiver>();
List<TileEntity> receivers = new ArrayList<TileEntity>();
for (IConductor conductor : conductors)
Iterator it = this.consumers.entrySet().iterator();
while (it.hasNext())
{
for (byte i = 0; i < conductor.getConnectedBlocks().length; i++)
{
TileEntity tileEntity = conductor.getConnectedBlocks()[i];
Map.Entry pairs = (Map.Entry) it.next();
if (tileEntity != null)
{
if (tileEntity instanceof IElectricityReceiver)
{
if (!returnArray.contains((IElectricityReceiver) tileEntity) && ((IElectricityReceiver) tileEntity).canReceiveFromSide(ForgeDirection.getOrientation(i).getOpposite()))
{
returnArray.add((IElectricityReceiver) tileEntity);
}
}
}
if (pairs != null)
{
receivers.add((TileEntity) pairs.getKey());
}
}
return returnArray;
return receivers;
}
public void cleanUpArray()
public void cleanConductors()
{
for (int i = 0; i < conductors.size(); i++)
{
@ -73,9 +280,17 @@ public class ElectricityNetwork
}
}
public void resetConductors()
{
for (int i = 0; i < conductors.size(); i++)
{
conductors.get(i).reset();
}
}
public void setNetwork()
{
this.cleanUpArray();
this.cleanConductors();
for (IConductor conductor : this.conductors)
{
@ -85,7 +300,7 @@ public class ElectricityNetwork
public void onOverCharge()
{
this.cleanUpArray();
this.cleanConductors();
for (int i = 0; i < conductors.size(); i++)
{
@ -93,7 +308,22 @@ public class ElectricityNetwork
}
}
public double getLowestAmpConductor()
/**
* Gets the resistance of this electrical network.
*/
public double getResistance()
{
double resistance = 0;
for (int i = 0; i < conductors.size(); i++)
{
resistance = Math.max(resistance, conductors.get(i).getResistance());
}
return resistance;
}
public double getLowestAmpTolerance()
{
double lowestAmp = 0;

View file

@ -0,0 +1,24 @@
package universalelectricity.core.electricity;
public class ElectricityPack
{
public double amperes;
public double voltage;
public ElectricityPack(double amperes, double voltage)
{
this.amperes = amperes;
this.voltage = voltage;
}
public double getWatts()
{
return ElectricInfo.getWatts(amperes, voltage);
}
@Override
public String toString()
{
return "ElectricityPack [Amps:" + this.amperes + " Volts:" + this.voltage + "]";
}
}

View file

@ -1,41 +0,0 @@
package universalelectricity.core.electricity;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.implement.IElectricityReceiver;
public class ElectricityTransferData
{
public Object sender;
public IElectricityReceiver receiver;
public ElectricityNetwork network;
public double amps;
public double voltage;
public ForgeDirection side;
/**
* @param sender
* - Tile that's sending electricity.
* @param receiver
* - Receiver that's receiving electricity
* @param conductor
* - Conductor that is conducting the electricity
* @param side
* -
* @param amps
* @param voltage
*/
public ElectricityTransferData(Object sender, IElectricityReceiver receiver, ElectricityNetwork network, ForgeDirection side, double amps, double voltage)
{
this.sender = sender;
this.receiver = receiver;
this.network = network;
this.side = side;
this.amps = amps;
this.voltage = voltage;
}
public boolean isValid()
{
return this.sender != null && this.receiver != null && this.network != null && this.amps > 0 && this.voltage > 0;
}
}

View file

@ -1,7 +1,6 @@
package universalelectricity.core.implement;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.electricity.ElectricityNetwork;
@ -11,7 +10,7 @@ import universalelectricity.core.electricity.ElectricityNetwork;
* @author Calclavia
*
*/
public interface IConductor extends IConnector
public interface IConductor
{
/**
* The electrical network this conductor is on.
@ -53,19 +52,16 @@ public interface IConductor extends IConnector
*/
public void reset();
public World getWorld();
public void refreshConnectedBlocks();
/**
* Adds a connection between this conductor and a UE unit
*
* @param tileEntity
* - Must be either a producer, consumer or a conductor
* @param side
* - side in which the connection is coming from
* @param tileEntity - Must be either a producer, consumer or a conductor
* @param side - side in which the connection is coming from
*/
public void updateConnection(TileEntity tileEntity, ForgeDirection side);
public void updateConnectionWithoutSplit(TileEntity connectorFromSide, ForgeDirection orientation);
public void refreshConnectedBlocks();
}

View file

@ -1,21 +0,0 @@
package universalelectricity.core.implement;
import net.minecraftforge.common.ForgeDirection;
/**
* Applied to a TileEntity that can connect to UE wires.
*
* @author Calclavia
*
*/
public interface IConnector
{
/**
* Can this TileEntity visually connect to a wire on this specific side?
*
* @param side
* - The side in which the connection is coming from.
* @return - True if so.
*/
public boolean canConnect(ForgeDirection side);
}

View file

@ -12,8 +12,7 @@ public interface IDisableable
/**
* This is called when the tile entity is to be disabled.
*
* @param duration
* - The duration of the disable in ticks.
* @param duration - The duration of the disable in ticks.
*/
public void onDisable(int duration);

View file

@ -1,12 +0,0 @@
package universalelectricity.core.implement;
/**
* Applied to TileEntities that can produces electricity. Of course, you will still need to call
* ElectricityManager.instance.produce() to actually output the electricity.
*
* @author Calclavia
*/
public interface IElectricityProducer extends IConnector, IDisableable, IVoltage
{
}

View file

@ -1,40 +0,0 @@
package universalelectricity.core.implement;
import net.minecraftforge.common.ForgeDirection;
/**
* The IElectricityReceiver interface is an interface that must be applied to all TileEntities or
* Entities that can receive electricity.
*
* @author Calclavia
*
*/
public interface IElectricityReceiver extends IDisableable, IConnector, IVoltage
{
/**
* Called every tick on this machine.
*
* @param sender
* - Either the TileEntity or the Entity sending the electricity to this
* TileEntity/Entity.
* @param amps
* - Amount of amps this electric unit is receiving.
* @param voltage
* - The voltage of the electricity sent. If more than one packet is being sent to
* you in this update, the highest voltage will override.
* @param side
* - The side of the block in which the electricity is coming from.
*/
public void onReceive(Object sender, double amps, double voltage, ForgeDirection side);
/**
* How many watts does this electrical unit need this tick? Recommended for you to return the
* max electricity storage of this machine (if there is one).
*/
public double wattRequest();
/**
* Can this unit receive electricity from this specific side?
*/
public boolean canReceiveFromSide(ForgeDirection side);
}

View file

@ -18,7 +18,7 @@ public interface IItemElectric extends IJouleStorage, IVoltage
/**
* @return Returns true or false if this consumer can receive electricity at this given tick or
* moment.
* moment.
*/
public boolean canReceiveElectricity();

View file

@ -13,7 +13,7 @@ import net.minecraft.src.TileEntity;
import net.minecraft.src.Vec3;
import net.minecraft.src.World;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.implement.IConnector;
import universalelectricity.core.electricity.ElectricityConnections;
/**
* Vector3 Class is used for defining objects in a 3D space. Vector3 makes it easier to handle the
@ -219,7 +219,7 @@ public class Vector3 extends Vector2 implements Cloneable
this.z -= amount.z;
}
public void multiply(int amount)
public void multiply(double amount)
{
this.x *= amount;
this.y *= amount;
@ -255,10 +255,8 @@ public class Vector3 extends Vector2 implements Cloneable
/**
* Saves this Vector3 to disk
*
* @param prefix
* - The prefix of this save. Use some unique string.
* @param par1NBTTagCompound
* - The NBT compound object to save the data in
* @param prefix - The prefix of this save. Use some unique string.
* @param par1NBTTagCompound - The NBT compound object to save the data in
*/
public void writeToNBT(String prefix, NBTTagCompound par1NBTTagCompound)
{
@ -290,10 +288,8 @@ public class Vector3 extends Vector2 implements Cloneable
/**
* Gets a position relative to another position's side
*
* @param position
* - The position
* @param side
* - The side. 0-5
* @param position - The position
* @param side - The side. 0-5
* @return The position relative to the original position's side
*/
public void modifyPositionFromSide(ForgeDirection side, double amount)
@ -339,9 +335,9 @@ public class Vector3 extends Vector2 implements Cloneable
{
TileEntity tileEntity = getTileEntityFromSide(world, position, side);
if (tileEntity instanceof IConnector)
if (ElectricityConnections.isConnector(tileEntity))
{
if (((IConnector) tileEntity).canConnect(getOrientationFromSide(side, ForgeDirection.NORTH))) { return tileEntity; }
if (ElectricityConnections.canConnect(tileEntity, getOrientationFromSide(side, ForgeDirection.NORTH))) { return tileEntity; }
}
return null;
@ -353,11 +349,9 @@ public class Vector3 extends Vector2 implements Cloneable
*
* Bottom: 0; Top: 1; Back: 2; Front: 3; Left: 4; Right: 5;
*
* @param front
* - The direction in which this block is facing/front. Use a number between 0 and 5.
* Default is 3.
* @param side
* - The side you are trying to find. A number between 0 and 5.
* @param front - The direction in which this block is facing/front. Use a number between 0 and
* 5. Default is 3.
* @param side - The side you are trying to find. A number between 0 and 5.
* @return The side relative to the facing direction.
*/

View file

@ -30,6 +30,8 @@ public abstract class BlockConductor extends BlockContainer
((IConductor) tileEntity).refreshConnectedBlocks();
}
}
world.scheduleBlockUpdate(x, y, z, this.blockID, this.tickRate());
}
/**

View file

@ -13,7 +13,7 @@ import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
import universalelectricity.core.implement.IItemElectric;
import universalelectricity.prefab.implement.IWrench;
import universalelectricity.prefab.implement.IToolConfigurator;
/**
* A block you may extend from to create your machine blocks! You do not have to extend from this
@ -62,45 +62,50 @@ public abstract class BlockMachine extends BlockContainer
/**
* DO NOT OVERRIDE THIS FUNCTION! 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 this function. Use onMachineActivated instead! (It does the same thing)
*
* @param world The World Object.
* @param x, y, z The coordinate of the block.
* @param side The side the player clicked on.
* @param hitX, hitY, hitZ The position the player clicked on relative to the block.
*/
@Override
public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
int metadata = par1World.getBlockMetadata(x, y, z);
int metadata = world.getBlockMetadata(x, y, z);
/**
* Check if the player is holding a wrench or an electric item. If so, do not open the GUI.
*/
if (par5EntityPlayer.inventory.getCurrentItem() != null)
{
if (par5EntityPlayer.inventory.getCurrentItem().getItem() instanceof IWrench)
if (par5EntityPlayer.inventory.getCurrentItem().getItem() instanceof IToolConfigurator)
{
par1World.notifyBlocksOfNeighborChange(x, y, z, this.blockID);
((IWrench) par5EntityPlayer.inventory.getCurrentItem().getItem()).wrenchUsed(par5EntityPlayer, x, y, z);
world.notifyBlocksOfNeighborChange(x, y, z, this.blockID);
((IToolConfigurator) par5EntityPlayer.inventory.getCurrentItem().getItem()).wrenchUsed(par5EntityPlayer, x, y, z);
if (par5EntityPlayer.isSneaking())
{
return this.onSneakUseWrench(par1World, x, y, z, par5EntityPlayer);
return this.onSneakUseWrench(world, x, y, z, par5EntityPlayer, side, hitX, hitY, hitZ);
}
else
{
return this.onUseWrench(par1World, x, y, z, par5EntityPlayer);
return this.onUseWrench(world, x, y, z, par5EntityPlayer, side, hitX, hitY, hitZ);
}
}
else if (par5EntityPlayer.inventory.getCurrentItem().getItem() instanceof IItemElectric)
{
if (this.onUseElectricItem(par1World, x, y, z, par5EntityPlayer)) { return true; }
if (this.onUseElectricItem(world, x, y, z, par5EntityPlayer, side, hitX, hitY, hitZ)) { return true; }
}
}
if (par5EntityPlayer.isSneaking())
{
return this.onSneakMachineActivated(par1World, x, y, z, par5EntityPlayer);
return this.onSneakMachineActivated(world, x, y, z, par5EntityPlayer, side, hitX, hitY, hitZ);
}
else
{
return this.onMachineActivated(par1World, x, y, z, par5EntityPlayer);
return this.onMachineActivated(world, x, y, z, par5EntityPlayer, side, hitX, hitY, hitZ);
}
}
@ -109,7 +114,7 @@ public abstract class BlockMachine extends BlockContainer
*
* @return True if something happens
*/
public boolean onMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer)
public boolean onMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
return false;
}
@ -119,7 +124,7 @@ public abstract class BlockMachine extends BlockContainer
*
* @return True if something happens
*/
public boolean onSneakMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer)
public boolean onSneakMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
return false;
}
@ -129,7 +134,7 @@ public abstract class BlockMachine extends BlockContainer
*
* @return True if some happens
*/
public boolean onUseElectricItem(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer)
public boolean onUseElectricItem(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
return false;
}
@ -139,7 +144,7 @@ public abstract class BlockMachine extends BlockContainer
*
* @return True if some happens
*/
public boolean onUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer)
public boolean onUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
return false;
}
@ -149,9 +154,9 @@ public abstract class BlockMachine extends BlockContainer
*
* @return True if some happens
*/
public boolean onSneakUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer)
public boolean onSneakUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
return this.onUseWrench(par1World, x, y, z, par5EntityPlayer);
return this.onUseWrench(par1World, x, y, z, par5EntityPlayer, side, hitX, hitY, hitZ);
}
/**

View file

@ -110,8 +110,7 @@ public abstract class ItemElectric extends Item implements IItemElectric
* This function sets the electriicty. Do not directly call this function. Try to use
* onReceiveElectricity or onUseElectricity instead.
*
* @param wattHours
* - The amount of electricity in joules
* @param wattHours - The amount of electricity in joules
*/
@Override
public void setJoules(double wattHours, Object... data)

View file

@ -8,7 +8,6 @@ import net.minecraft.src.CraftingManager;
import net.minecraft.src.IRecipe;
import net.minecraft.src.ItemStack;
import net.minecraftforge.common.Configuration;
import universalelectricity.core.UEConfig;
import cpw.mods.fml.common.registry.GameRegistry;
/**
@ -132,7 +131,8 @@ public class RecipeHelper
}
/**
* Removes all recipes found that has this output.
* Removes all recipes found that has this output. You may use this with Forge Ore Dictionary to
* remove all recipes with the FoD ID.
*
* @return True if successful
*/
@ -170,14 +170,18 @@ public class RecipeHelper
/**
* Use this function if you want to check if the recipe is allowed in the configuration file.
*/
public static void addRecipe(IRecipe recipe, String name, Configuration config, boolean defaultBoolean)
public static void addRecipe(IRecipe recipe, String name, Configuration configuration, boolean defaultBoolean)
{
if (config != null)
if (configuration != null)
{
if (UEConfig.getConfigData(config, "Allow " + name + " Crafting", defaultBoolean))
configuration.load();
if (configuration.get("Crafting", "Allow " + name + " Crafting", defaultBoolean).getBoolean(defaultBoolean))
{
GameRegistry.addRecipe(recipe);
}
configuration.save();
}
}

View file

@ -0,0 +1,113 @@
package universalelectricity.prefab;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import net.minecraft.src.EntityPlayer;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.IPlayerTracker;
import cpw.mods.fml.common.registry.GameRegistry;
/**
* A class used to search online and check for updates for your mod and notify the player.
*
* @author Calclavia
*
*/
public class UpdateNotifier implements IPlayerTracker
{
public static final UpdateNotifier INSTANCE = new UpdateNotifier();
public static boolean isInitialized = false;
public static final HashMap<String, String> modsToUpdate = new HashMap<String, String>();
/**
* Call this in your FML Pre-Initialize Event.
*
* @param modName The name of your mod.
* @param currentVersion The current version of your mod.
* @param updateUrl The web address of your text file containing the latest version number.
* @return The latest version number, empty if fail to check for update.
*/
public final String checkUpdate(String modName, String currentVersion, String updateUrl)
{
if (!isInitialized)
{
GameRegistry.registerPlayerTracker(this);
isInitialized = true;
}
String latestUpdate = getLatestVersion(updateUrl);
if (latestUpdate != null && latestUpdate != "" && !latestUpdate.equals(currentVersion.trim()))
{
modsToUpdate.put(modName, latestUpdate);
}
return latestUpdate;
}
/**
* Allows you to check for updates for your mod.
*
* @param updateUrl The web address of your text file containing the latest version number.
* @return The latest version number, empty if fail to check for update.
*/
public static final String getLatestVersion(String updateUrl)
{
try
{
URL versionFile = new URL(updateUrl);
BufferedReader reader = new BufferedReader(new InputStreamReader(versionFile.openStream()));
return reader.readLine();
}
catch (Exception e)
{
FMLLog.severe("Failed to check for mod updates.");
}
return "";
}
@Override
public void onPlayerLogin(EntityPlayer player)
{
if (modsToUpdate.size() > 0)
{
String notification = "You have " + modsToUpdate.size() + " mod(s) that needs to be updated: ";
Iterator it = modsToUpdate.entrySet().iterator();
while (it.hasNext())
{
Map.Entry pairs = (Map.Entry) it.next();
notification += pairs.getKey() + " [" + pairs.getValue() + "] ";
}
player.addChatMessage(notification);
}
}
@Override
public void onPlayerLogout(EntityPlayer player)
{
}
@Override
public void onPlayerChangedDimension(EntityPlayer player)
{
}
@Override
public void onPlayerRespawn(EntityPlayer player)
{
}
}

View file

@ -18,16 +18,15 @@ public interface IRotatable
* entity.
*
* @return The facing side from 0-5 The full list of which side the number represents is in the
* UniversalElectricity class.
* UniversalElectricity class.
*/
public ForgeDirection getDirection();
/**
* Sets the facing direction of the tile entity.
*
* @param facingDirection
* - A direction from 0-5. The full list of which side the number represents is in
* the UniversalElectricity class.
* @param facingDirection - A direction from 0-5. The full list of which side the number
* represents is in the UniversalElectricity class.
*/
public void setDirection(ForgeDirection facingDirection);
}

View file

@ -18,8 +18,7 @@ public interface ITier
/**
* Sets the tier of the object
*
* @param tier
* - The tier to be set
* @param tier - The tier to be set
*/
public void setTier(int tier);
}

View file

@ -3,21 +3,20 @@ package universalelectricity.prefab.implement;
import net.minecraft.src.EntityPlayer;
/**
* Code written by Buildcraft.
* Code written by Buildcraft. Applied to items that acts as a block configurator such as wrenches,
* screw drivers and such.
*
* @author Buildcraft Team
*/
public interface IWrench
public interface IToolConfigurator
{
/***
* Called to ensure that the wrench can be used. To get the ItemStack that is used, check
* player.inventory.getCurrentItem()
*
* @param player
* - The player doing the wrenching
* @param x
* ,y,z - The coordinates for the block being wrenched
* @param player - The player doing the wrenching
* @param x ,y,z - The coordinates for the block being wrenched
*
* @return true if wrenching is allowed, false if not
*/
@ -27,10 +26,8 @@ public interface IWrench
* Callback after the wrench has been used. This can be used to decrease durability or for other
* purposes. To get the ItemStack that was used, check player.inventory.getCurrentItem()
*
* @param player
* - The player doing the wrenching
* @param x
* ,y,z - The coordinates of the block being wrenched
* @param player - The player doing the wrenching
* @param x ,y,z - The coordinates of the block being wrenched
*/
public void wrenchUsed(EntityPlayer player, int x, int y, int z);
}

View file

@ -0,0 +1,22 @@
package universalelectricity.prefab.modifier;
import net.minecraft.src.ItemStack;
/**
* This must be applied to an item that acts as a modifier or an upgrade.
*
* @author Calclavia
*
*/
public interface IModifier
{
/**
* @return - The name of the modifier.
*/
public String getName(ItemStack itemstack);
/**
* @return - How much effect does this modifier have?
*/
public int getEffectiveness(ItemStack itemstack);
}

View file

@ -0,0 +1,29 @@
package universalelectricity.prefab.modifier;
import net.minecraft.src.IInventory;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Slot;
/**
* This slot should be used by any container that contains an item that is a modifier. An example of
* this would be upgrade slots.
*
* @author Calclavia
*
*/
public class SlotModifier extends Slot
{
public SlotModifier(IInventory par2IInventory, int par3, int par4, int par5)
{
super(par2IInventory, par3, par4, par5);
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
*/
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
return par1ItemStack.getItem() instanceof IModifier;
}
}

View file

@ -15,16 +15,14 @@ public interface IMultiBlock extends IBlockActivate
/**
* Called when this multiblock is created
*
* @param placedPosition
* - The position the block was placed at
* @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
* @param callingBlock - The tile entity who called the onDestroy function
*/
public void onDestroy(TileEntity callingBlock);
}

View file

@ -25,9 +25,9 @@ import cpw.mods.fml.common.network.Player;
* directly use this by registering this packet manager with NetworkMod. Example:
*
* @NetworkMod(channels = { "BasicComponents" }, clientSideRequired = true, serverSideRequired =
* false, packetHandler = PacketManager.class)
* false, packetHandler = PacketManager.class)
*
* Check out {@link #BasicComponents} for better reference.
* Check out {@link #BasicComponents} for better reference.
*
* @author Calclavia
*/

View file

@ -0,0 +1,99 @@
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.Configuration;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.oredict.OreDictionary;
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(Configuration config)
{
this.shouldGenerate = shouldGenerateOre(config, this.name);
return this;
}
public OreGenBase enable()
{
this.enable(UniversalElectricity.CONFIGURATION);
return this;
}
/**
* Checks the config file and see if Universal Electricity should generate this ore
*/
private static boolean shouldGenerateOre(Configuration configuration, String oreName)
{
configuration.load();
boolean shouldGenerate = configuration.get("Ore Generation", "Generate " + oreName, true).getBoolean(true);
configuration.save();
return shouldGenerate;
}
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,126 @@
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,37 @@
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,40 @@
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);
}
}
}

View file

@ -0,0 +1,31 @@
package universalelectricity.prefab.repair;
import net.minecraft.src.EntityPlayer;
/**
* Applied to TileEntities/Machines that can be repaired.
*
* @author Calclavia
*
*/
public interface IRepairable
{
/**
* Called when the machine is being repaired.
*
* @param itemStack - The repairing tool that the player is holding
* @param player - The player who is repairing this machine.
*/
public void onRepair(IToolRepair itemStack, EntityPlayer player);
/**
* @return The maximum possible damage of this machine.
*/
public int getMaxDamage();
/**
* @return How damaged is this machine?
*/
public int getDamage();
}

View file

@ -0,0 +1,19 @@
package universalelectricity.prefab.repair;
import net.minecraft.src.ItemStack;
public interface IToolRepair
{
/**
* A unique ID for mods to recognize what repair tool this is.
*/
public String getID();
/**
* How effective is this repairing tool?
*
* @param itemStack The ItemStack
* @return A effectiveness value.
*/
public int getEffectiveness(ItemStack itemStack);
}

View file

@ -1,15 +1,16 @@
package universalelectricity.prefab.tile;
import java.util.EnumSet;
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.electricity.ElectricityManager;
import universalelectricity.core.electricity.Electricity;
import universalelectricity.core.electricity.ElectricityConnections;
import universalelectricity.core.electricity.ElectricityNetwork;
import universalelectricity.core.implement.IConductor;
import universalelectricity.core.implement.IConnector;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.network.IPacketReceiver;
@ -33,6 +34,7 @@ public abstract class TileEntityConductor extends TileEntityAdvanced implements
public TileEntityConductor()
{
ElectricityConnections.registerConnector(this, EnumSet.range(ForgeDirection.DOWN, ForgeDirection.EAST));
this.reset();
}
@ -51,13 +53,7 @@ public abstract class TileEntityConductor extends TileEntityAdvanced implements
@Override
public TileEntity[] getConnectedBlocks()
{
return connectedBlocks;
}
@Override
public void initiate()
{
this.refreshConnectedBlocks();
return this.connectedBlocks;
}
@Override
@ -65,13 +61,13 @@ public abstract class TileEntityConductor extends TileEntityAdvanced implements
{
if (tileEntity != null)
{
if (tileEntity instanceof IConnector)
if (ElectricityConnections.isConnector(tileEntity))
{
this.connectedBlocks[side.ordinal()] = tileEntity;
if (tileEntity.getClass() == this.getClass())
{
ElectricityManager.instance.mergeConnection(this.getNetwork(), ((TileEntityConductor) tileEntity).getNetwork());
Electricity.instance.mergeConnection(this.getNetwork(), ((TileEntityConductor) tileEntity).getNetwork());
}
return;
@ -82,7 +78,7 @@ public abstract class TileEntityConductor extends TileEntityAdvanced implements
{
if (this.connectedBlocks[side.ordinal()] instanceof IConductor)
{
ElectricityManager.instance.splitConnection(this, (IConductor) this.getConnectedBlocks()[side.ordinal()]);
Electricity.instance.splitConnection(this, (IConductor) this.getConnectedBlocks()[side.ordinal()]);
}
}
@ -94,13 +90,13 @@ public abstract class TileEntityConductor extends TileEntityAdvanced implements
{
if (tileEntity != null)
{
if (tileEntity instanceof IConnector)
if (ElectricityConnections.isConnector(tileEntity))
{
this.connectedBlocks[side.ordinal()] = tileEntity;
if (tileEntity.getClass() == this.getClass())
{
ElectricityManager.instance.mergeConnection(this.getNetwork(), ((TileEntityConductor) tileEntity).getNetwork());
Electricity.instance.mergeConnection(this.getNetwork(), ((TileEntityConductor) tileEntity).getNetwork());
}
return;
@ -119,15 +115,10 @@ public abstract class TileEntityConductor extends TileEntityAdvanced implements
}
}
/**
* Determines if this TileEntity requires update calls.
*
* @return True if you want updateEntity() to be called, false if not
*/
@Override
public boolean canUpdate()
public void initiate()
{
return false;
this.refreshConnectedBlocks();
}
@Override
@ -135,9 +126,9 @@ public abstract class TileEntityConductor extends TileEntityAdvanced implements
{
this.network = null;
if (ElectricityManager.instance != null)
if (Electricity.instance != null)
{
ElectricityManager.instance.registerConductor(this);
Electricity.instance.registerConductor(this);
}
}
@ -152,16 +143,4 @@ public abstract class TileEntityConductor extends TileEntityAdvanced implements
}
}
}
@Override
public World getWorld()
{
return this.worldObj;
}
@Override
public boolean canConnect(ForgeDirection side)
{
return true;
}
}

View file

@ -0,0 +1,40 @@
package universalelectricity.prefab.tile;
import java.util.EnumSet;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.electricity.Electricity;
import universalelectricity.core.electricity.ElectricityConnections;
import universalelectricity.core.implement.IVoltage;
/**
* An easier way to implement the methods from IElectricityReceiver with default values set.
*
* @author Calclavia
*/
public abstract class TileEntityElectricityProducer extends TileEntityDisableable implements IVoltage
{
public TileEntityElectricityProducer()
{
super();
ElectricityConnections.registerConnector(this, EnumSet.range(ForgeDirection.DOWN, ForgeDirection.EAST));
}
@Override
public void updateEntity()
{
super.updateEntity();
}
@Override
public double getVoltage()
{
return 120;
}
@Override
public void invalidate()
{
Electricity.instance.unregister(this);
}
}

View file

@ -1,18 +1,23 @@
package universalelectricity.prefab.tile;
import java.util.EnumSet;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.implement.IElectricityReceiver;
import universalelectricity.core.electricity.Electricity;
import universalelectricity.core.electricity.ElectricityConnections;
import universalelectricity.core.implement.IVoltage;
/**
* An easier way to implement the methods from IElectricityReceiver with default values set.
*
* @author Calclavia
*/
public abstract class TileEntityElectricityReceiver extends TileEntityDisableable implements IElectricityReceiver
public abstract class TileEntityElectricityReceiver extends TileEntityDisableable implements IVoltage
{
public TileEntityElectricityReceiver()
{
super();
ElectricityConnections.registerConnector(this, EnumSet.range(ForgeDirection.DOWN, ForgeDirection.EAST));
}
@Override
@ -20,16 +25,16 @@ public abstract class TileEntityElectricityReceiver extends TileEntityDisableabl
{
super.updateEntity();
}
@Override
public boolean canConnect(ForgeDirection side)
{
return this.canReceiveFromSide(side);
}
@Override
public double getVoltage()
{
return 120;
}
@Override
public void invalidate()
{
Electricity.instance.unregister(this);
}
}