General Update: Untested

really quick update that i should have uploaded 3 days ago but meh.
Anyways no real changes thought i change the task system to inlude the
TE
in the constuction instead of a seperate method. Since i have no way to
test the tasks yet i have yet to know if this will effect anything. Will
add arm to mod by dec 10. For the moment i have other things to do.
This commit is contained in:
Rseifert 2012-11-26 11:58:03 -05:00
parent ce66426131
commit 2ec75ad736
59 changed files with 1331 additions and 419 deletions

View file

@ -1 +1 @@
A mod that brings realistic transportation systems into Minecraft. A mod that brings realistic factory style transportation systems into Minecraft.

Binary file not shown.

View file

@ -1,6 +1,7 @@
package assemblyline.ai; package assemblyline.ai;
import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntity;
import assemblyline.machines.crafter.TileEntityCraftingArm;
/** /**
* An AI Task that is used by TileEntities with * An AI Task that is used by TileEntities with
@ -12,7 +13,11 @@ import net.minecraft.src.TileEntity;
public abstract class Task public abstract class Task
{ {
protected int ticks; protected int ticks;
protected TileEntityCraftingArm tileEntity;
public Task(TileEntityCraftingArm arm)
{
this.tileEntity = arm;
}
/** /**
* Called when a task is being done. * Called when a task is being done.
* *
@ -37,8 +42,6 @@ public abstract class Task
{ {
} }
public abstract void setTileEntity(TileEntity tileEntity);
/** /**
* @return The tick interval of this task. * @return The tick interval of this task.
* Return 0 for no ticks. * Return 0 for no ticks.

View file

@ -1,14 +1,23 @@
package assemblyline.ai; package assemblyline.ai;
import assemblyline.machines.crafter.TileEntityCraftingArm;
import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntity;
public class TaskIdle extends Task public class TaskIdle extends Task
{ {
private TileEntity tileEntity; public TaskIdle(TileEntityCraftingArm arm)
{
@Override super(arm);
public void setTileEntity(TileEntity tileEntity) }
{ protected boolean doTask()
this.tileEntity = tileEntity; {
/**
* randomly move the arm to
* similate life in the arm
* if the arm is powered
*/
return true;
} }
} }

View file

@ -48,7 +48,6 @@ public class TaskManager
public void addTask(TileEntity tileEntity, Task task) public void addTask(TileEntity tileEntity, Task task)
{ {
task.setTileEntity(tileEntity);
task.onTaskStart(); task.onTaskStart();
tasks.add(task); tasks.add(task);
} }

View file

@ -398,7 +398,7 @@ public class TileEntityManipulator extends TileEntityElectricityReceiver impleme
} }
@Override @Override
public void onReceive(TileEntity sender, double amps, double voltage, ForgeDirection side) public void onReceive(Object sender, double amps, double voltage, ForgeDirection side)
{ {
this.wattsReceived += ElectricInfo.getWatts(amps, voltage); this.wattsReceived += ElectricInfo.getWatts(amps, voltage);
} }

View file

@ -342,7 +342,7 @@ public class TileEntityRejector extends TileEntityElectricityReceiver implements
} }
@Override @Override
public void onReceive(TileEntity sender, double amps, double voltage, ForgeDirection side) public void onReceive(Object sender, double amps, double voltage, ForgeDirection side)
{ {
this.wattsReceived += (amps * voltage); this.wattsReceived += (amps * voltage);

View file

@ -85,7 +85,7 @@ public class TileEntityRoboticSorter extends TileEntityElectricityReceiver imple
} }
@Override @Override
public void onReceive(TileEntity sender, double amps, double voltage, ForgeDirection side) public void onReceive(Object sender, double amps, double voltage, ForgeDirection side)
{ {
this.wattsReceived += (amps * voltage); this.wattsReceived += (amps * voltage);

View file

@ -225,7 +225,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem
} }
@Override @Override
public void onReceive(TileEntity sender, double amps, double voltage, ForgeDirection side) public void onReceive(Object sender, double amps, double voltage, ForgeDirection side)
{ {
this.wattsReceived += ElectricInfo.getWatts(amps, voltage); this.wattsReceived += ElectricInfo.getWatts(amps, voltage);
} }

View file

@ -12,16 +12,17 @@ import assemblyline.ai.Task;
*/ */
public class TaskArmCollect extends Task public class TaskArmCollect extends Task
{ {
private TileEntityCraftingArm tileEntity;
/** /**
* The item to be collected. * The item to be collected.
*/ */
private EntityItem entityItem; private EntityItem entityItem;
public TaskArmCollect(EntityItem entityItem) public TaskArmCollect(TileEntityCraftingArm arm,EntityItem entityItem)
{ {
this.entityItem = entityItem; super(arm);
this.entityItem = entityItem;
} }
@Override @Override
@ -38,10 +39,4 @@ public class TaskArmCollect extends Task
return true; return true;
} }
@Override
public void setTileEntity(TileEntity tileEntity)
{
this.tileEntity = (TileEntityCraftingArm) tileEntity;
}
} }

View file

@ -13,7 +13,6 @@ import assemblyline.ai.Task;
*/ */
public class TaskArmSearch extends Task public class TaskArmSearch extends Task
{ {
private TileEntityCraftingArm tileEntity;
/** /**
* The item to be collected. * The item to be collected.
@ -22,14 +21,13 @@ public class TaskArmSearch extends Task
private float searchSpeed; private float searchSpeed;
private World worldObj;
private double radius; private double radius;
private Entity foundEntity; private Entity foundEntity;
public TaskArmSearch(Class<? extends Entity> entityToInclude, double radius, float searchSpeed) public TaskArmSearch(TileEntityCraftingArm arm,Class<? extends Entity> entityToInclude, double radius, float searchSpeed)
{ {
super(arm);
this.entityToInclude = entityToInclude; this.entityToInclude = entityToInclude;
this.radius = radius; this.radius = radius;
this.searchSpeed = searchSpeed; this.searchSpeed = searchSpeed;
@ -38,7 +36,7 @@ public class TaskArmSearch extends Task
@Override @Override
public void onTaskStart() public void onTaskStart()
{ {
this.foundEntity = (Entity) this.worldObj.getEntitiesWithinAABB(this.entityToInclude, AxisAlignedBB.getBoundingBox(this.tileEntity.xCoord - this.radius, this.tileEntity.yCoord - this.radius, this.tileEntity.zCoord - this.radius, this.tileEntity.xCoord + this.radius, this.tileEntity.yCoord + this.radius, this.tileEntity.zCoord + this.radius)).get(0); this.foundEntity = (Entity) this.tileEntity.worldObj.getEntitiesWithinAABB(this.entityToInclude, AxisAlignedBB.getBoundingBox(this.tileEntity.xCoord - this.radius, this.tileEntity.yCoord - this.radius, this.tileEntity.zCoord - this.radius, this.tileEntity.xCoord + this.radius, this.tileEntity.yCoord + this.radius, this.tileEntity.zCoord + this.radius)).get(0);
} }
@Override @Override
@ -56,11 +54,4 @@ public class TaskArmSearch extends Task
return true; return true;
} }
@Override
public void setTileEntity(TileEntity tileEntity)
{
this.tileEntity = (TileEntityCraftingArm) tileEntity;
this.worldObj = this.tileEntity.worldObj;
}
} }

View file

@ -68,7 +68,7 @@ public class TileEntityCraftingArm extends TileEntityElectricityReceiver impleme
* UE methods * UE methods
*/ */
@Override @Override
public void onReceive(TileEntity sender, double amps, double voltage, ForgeDirection side) public void onReceive(Object sender, double amps, double voltage, ForgeDirection side)
{ {
this.jouleReceived = Math.max(jouleReceived + (amps * voltage), maxJoules); this.jouleReceived = Math.max(jouleReceived + (amps * voltage), maxJoules);
@ -258,4 +258,5 @@ public class TileEntityCraftingArm extends TileEntityElectricityReceiver impleme
nbt.setTag("Items", var2); nbt.setTag("Items", var2);
} }
} }

View file

@ -12,8 +12,7 @@ import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.registry.TickRegistry; import cpw.mods.fml.common.registry.TickRegistry;
/** /**
* A class used to load Universal Electricity and * A class used to load Universal Electricity and make it work.
* make it work.
* *
* @author Calclavia * @author Calclavia
* *

View file

@ -12,20 +12,14 @@ import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Loader;
/** /**
* Instructions for using the Universal * Instructions for using the Universal Electricity API.
* Electricity API.
* *
* The less you include of the API, the more * The less you include of the API, the more compatible your mod will be for future releases of
* compatible your mod will be for future releases * Universal Electricity.
* of Universal Electricity.
* *
* REQUIRED PACKAGES: "universalelectricity" * REQUIRED PACKAGE: "universalelectricity.core" OPTIONAL PACKAGE: "universalelectricity.prefab"
* "universalelectricity.electricity"
* "universalelectricity.implements" - Some
* interfaces can be removed if not needed.
* *
* The rest of the classes should be removed if * All classes should be removed if you are not going to use them.
* you are not going to use them.
* *
* @author Calclavia * @author Calclavia
* *
@ -33,23 +27,20 @@ import cpw.mods.fml.common.Loader;
public class UniversalElectricity public class UniversalElectricity
{ {
/** /**
* The version of the Universal Electricity * The version of the Universal Electricity API.
* API.
*/ */
public static final int MAJOR_VERSION = 1; public static final int MAJOR_VERSION = 1;
public static final int MINOR_VERSION = 1; public static final int MINOR_VERSION = 1;
public static final int REVISION_VERSION = 1; public static final int REVISION_VERSION = 3;
public static final String VERSION = MAJOR_VERSION + "." + MINOR_VERSION + "." + REVISION_VERSION; public static final String VERSION = MAJOR_VERSION + "." + MINOR_VERSION + "." + REVISION_VERSION;
/** /**
* The Universal Electricity configuration * The Universal Electricity configuration file.
* file.
*/ */
public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), "UniversalElectricity/UniversalElectricity.cfg")); public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), "UniversalElectricity/UniversalElectricity.cfg"));
/** /**
* Conversion ratios between Buildcraft and * Conversion ratios between Buildcraft and Industrialcraft energy.
* Industrialcraft energy.
*/ */
// EU to Watts ratio // EU to Watts ratio
public static final float IC2_RATIO = (float) UEConfig.getConfigData(CONFIGURATION, "IndustrialCraft Conversion Ratio", 7); public static final float IC2_RATIO = (float) UEConfig.getConfigData(CONFIGURATION, "IndustrialCraft Conversion Ratio", 7);
@ -59,16 +50,14 @@ public class UniversalElectricity
public static final float TO_BC_RATIO = 1 / BC3_RATIO; public static final float TO_BC_RATIO = 1 / BC3_RATIO;
/** /**
* Use this material for all your machine * Use this material for all your machine blocks. It can be breakable by hand.
* blocks. It can be breakable by hand.
*/ */
public static final Material machine = new Material(MapColor.ironColor); public static final Material machine = new Material(MapColor.ironColor);
public static final List<Object> mods = new ArrayList<Object>(); public static final List<Object> mods = new ArrayList<Object>();
/** /**
* You must register your mod with Universal * You must register your mod with Universal Electricity. Call this in your mod's
* Electricity. Call this in your mod's
* pre-initialization stage. * pre-initialization stage.
*/ */
public static void register(Object mod, int major, int minor, int revision, boolean strict) public static void register(Object mod, int major, int minor, int revision, boolean strict)
@ -97,8 +86,7 @@ public class UniversalElectricity
} }
/** /**
* A function that allows you to lock your mod * A function that allows you to lock your mod to a specific version of Forge.
* to a specific version of Forge.
*/ */
public static void forgeLock(int major, int minor, int revision, boolean strict) public static void forgeLock(int major, int minor, int revision, boolean strict)
{ {

View file

@ -1,8 +1,7 @@
package universalelectricity.core.electricity; package universalelectricity.core.electricity;
/** /**
* An easy way to display information on * An easy way to display information on electricity.
* electricity.
* *
* @author Calclavia * @author Calclavia
*/ */
@ -132,8 +131,7 @@ public class ElectricInfo
} }
/** /**
* Displays the unit as text. Works only for * Displays the unit as text. Works only for positive numbers.
* positive numbers.
*/ */
public static String getDisplay(double value, ElectricUnit unit, int significantFigures, boolean isShort) public static String getDisplay(double value, ElectricUnit unit, int significantFigures, boolean isShort)
{ {
@ -186,8 +184,7 @@ public class ElectricInfo
} }
/** /**
* Rounds a number to a specific number place * Rounds a number to a specific number place places
* places
* *
* @param The * @param The
* number * number

View file

@ -7,6 +7,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.minecraft.src.Entity;
import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.implement.IConductor; import universalelectricity.core.implement.IConductor;
@ -16,9 +17,8 @@ import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.TickType; import cpw.mods.fml.common.TickType;
/** /**
* This class is used to manage electricity * This class is used to manage electricity transferring and flow. It is also used to call updates
* transferring and flow. It is also used to call * on UE tile entities.
* updates on UE tile entities.
* *
* @author Calclavia * @author Calclavia
* *
@ -26,10 +26,8 @@ import cpw.mods.fml.common.TickType;
public class ElectricityManager public class ElectricityManager
{ {
/** /**
* ElectricityManager exists on both client * ElectricityManager exists on both client and server side. Rely on the server side one as it
* and server side. Rely on the server side * is more accurate! Client side only simulates.
* one as it is more accurate! Client side
* only simulates.
*/ */
public static ElectricityManager instance; public static ElectricityManager instance;
@ -42,8 +40,7 @@ public class ElectricityManager
} }
/** /**
* Registers a the conductor into the UE * Registers a the conductor into the UE electricity net.
* electricity net.
* *
* @param conductor * @param conductor
* - The IConductor tile entity. * - The IConductor tile entity.
@ -55,15 +52,12 @@ public class ElectricityManager
} }
/** /**
* Merges two connection lines together into * Merges two connection lines together into one.
* one.
* *
* @param networkA * @param networkA
* - The network to be merged into. * - The network to be merged into. This network will be kept.
* This network will be kept.
* @param networkB * @param networkB
* - The network to be merged. This * - The network to be merged. This network will be deleted.
* network will be deleted.
*/ */
public void mergeConnection(ElectricityNetwork networkA, ElectricityNetwork networkB) public void mergeConnection(ElectricityNetwork networkA, ElectricityNetwork networkB)
{ {
@ -84,11 +78,8 @@ public class ElectricityManager
} }
/** /**
* Separate one connection line into two * Separate one connection line into two different ones between two conductors. This function
* different ones between two conductors. This * does this by resetting all wires in the connection line and making them each reconnect.
* function does this by resetting all wires
* in the connection line and making them each
* reconnect.
* *
* @param conductorA * @param conductorA
* - existing conductor * - existing conductor
@ -123,8 +114,7 @@ public class ElectricityManager
} }
/** /**
* Clean up and remove all useless and invalid * Clean up and remove all useless and invalid connections.
* connections.
*/ */
public void cleanUpConnections() public void cleanUpConnections()
{ {
@ -147,25 +137,19 @@ public class ElectricityManager
} }
/** /**
* Produces electricity into a specific wire * Produces electricity into a specific wire which will be distributed across the electricity
* which will be distributed across the * network.
* electricity network.
* *
* @param sender * @param sender
* The machine sending the * The machine sending the electricity.
* electricity.
* @param targetConductor * @param targetConductor
* The conductor receiving the * The conductor receiving the electricity (or connected to the machine).
* electricity (or connected to the
* machine).
* @param amps * @param amps
* The amount of amps this machine * The amount of amps this machine is sending.
* is sending.
* @param voltage * @param voltage
* The amount of volts this machine * The amount of volts this machine is sending.
* is sending.
*/ */
public void produceElectricity(TileEntity sender, IConductor targetConductor, double amps, double voltage) public void produceElectricity(Object sender, IConductor targetConductor, double amps, double voltage)
{ {
if (targetConductor != null && amps > 0 && voltage > 0) if (targetConductor != null && amps > 0 && voltage > 0)
{ {
@ -197,12 +181,16 @@ public class ElectricityManager
double transferAmps = Math.max(0, Math.min(leftOverAmps, Math.min(amps / allElectricUnitsInLine.size(), ElectricInfo.getAmps(this.getActualWattRequest(receiver), receiver.getVoltage())))); double transferAmps = Math.max(0, Math.min(leftOverAmps, Math.min(amps / allElectricUnitsInLine.size(), ElectricInfo.getAmps(this.getActualWattRequest(receiver), receiver.getVoltage()))));
leftOverAmps -= transferAmps; leftOverAmps -= transferAmps;
// Calculate double ampsReceived = transferAmps;
// electricity double voltsReceived = voltage;
// loss
double distance = Vector3.distance(Vector3.get(sender), Vector3.get((TileEntity) receiver)); if (sender instanceof TileEntity)
double ampsReceived = transferAmps - (transferAmps * transferAmps * targetConductor.getResistance() * distance) / voltage; {
double voltsReceived = voltage - (transferAmps * targetConductor.getResistance() * distance); // 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)); this.electricityTransferQueue.add(new ElectricityTransferData(sender, receiver, electricityNetwork, ForgeDirection.getOrientation(i).getOpposite(), ampsReceived, voltsReceived));
} }
@ -218,9 +206,24 @@ public class ElectricityManager
} }
} }
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 * Gets the actual watt request of an electric receiver accounting all current electricity
* receiver accounting all current electricity
* packets qued up for it. * packets qued up for it.
* *
* @return - The amount of watts requested. * @return - The amount of watts requested.
@ -254,11 +257,9 @@ public class ElectricityManager
} }
/** /**
* Checks if the current connection line needs * Checks if the current connection line needs electricity
* electricity
* *
* @return - The amount of joules this * @return - The amount of joules this connection line needs
* connection line needs
*/ */
public double getElectricityRequired(ElectricityNetwork network) public double getElectricityRequired(ElectricityNetwork network)
{ {
@ -323,8 +324,7 @@ public class ElectricityManager
} }
/** /**
* This function is called to refresh all * This function is called to refresh all conductors in the world.
* conductors in the world.
*/ */
public void refreshConductors() public void refreshConductors()
{ {
@ -345,12 +345,13 @@ public class ElectricityManager
public void onTick(EnumSet<TickType> type, Object... tickData) public void onTick(EnumSet<TickType> type, Object... tickData)
{ {
if (ElectricityManagerTicker.inGameTicks % 40 == 0)
{
this.refreshConductors();
}
if (type.contains(TickType.WORLD) && !type.contains(TickType.WORLDLOAD)) if (type.contains(TickType.WORLD) && !type.contains(TickType.WORLDLOAD))
{ {
if (ElectricityManagerTicker.inGameTicks % 40 == 0)
{
this.refreshConductors();
}
try try
{ {

View file

@ -29,8 +29,7 @@ public class ElectricityNetwork
} }
/** /**
* Get only the electric units that can * Get only the electric units that can receive electricity from the given side.
* receive electricity from the given side.
*/ */
public List<IElectricityReceiver> getConnectedReceivers() public List<IElectricityReceiver> getConnectedReceivers()
{ {
@ -110,8 +109,7 @@ public class ElectricityNetwork
} }
/** /**
* This function is called to refresh all * This function is called to refresh all conductors in this network
* conductors in this network
*/ */
public void refreshConductors() public void refreshConductors()
{ {

View file

@ -1,12 +1,11 @@
package universalelectricity.core.electricity; package universalelectricity.core.electricity;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.implement.IElectricityReceiver; import universalelectricity.core.implement.IElectricityReceiver;
public class ElectricityTransferData public class ElectricityTransferData
{ {
public TileEntity sender; public Object sender;
public IElectricityReceiver receiver; public IElectricityReceiver receiver;
public ElectricityNetwork network; public ElectricityNetwork network;
public double amps; public double amps;
@ -15,20 +14,17 @@ public class ElectricityTransferData
/** /**
* @param sender * @param sender
* - Tile that's sending * - Tile that's sending electricity.
* electricity.
* @param receiver * @param receiver
* - Receiver that's receiving * - Receiver that's receiving electricity
* electricity
* @param conductor * @param conductor
* - Conductor that is conducting * - Conductor that is conducting the electricity
* the electricity
* @param side * @param side
* - * -
* @param amps * @param amps
* @param voltage * @param voltage
*/ */
public ElectricityTransferData(TileEntity sender, IElectricityReceiver receiver, ElectricityNetwork network, ForgeDirection side, double amps, double voltage) public ElectricityTransferData(Object sender, IElectricityReceiver receiver, ElectricityNetwork network, ForgeDirection side, double amps, double voltage)
{ {
this.sender = sender; this.sender = sender;
this.receiver = receiver; this.receiver = receiver;

View file

@ -6,8 +6,7 @@ import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.electricity.ElectricityNetwork; import universalelectricity.core.electricity.ElectricityNetwork;
/** /**
* Must be applied to all tile entities that are * Must be applied to all tile entities that are conductors.
* conductors.
* *
* @author Calclavia * @author Calclavia
* *
@ -15,63 +14,54 @@ import universalelectricity.core.electricity.ElectricityNetwork;
public interface IConductor extends IConnector public interface IConductor extends IConnector
{ {
/** /**
* The electrical network this conductor is * The electrical network this conductor is on.
* on.
*/ */
public ElectricityNetwork getNetwork(); public ElectricityNetwork getNetwork();
public void setNetwork(ElectricityNetwork network); public void setNetwork(ElectricityNetwork network);
/** /**
* The UE tile entities that this conductor is * The UE tile entities that this conductor is connected to.
* connected to.
* *
* @return * @return
*/ */
public TileEntity[] getConnectedBlocks(); public TileEntity[] getConnectedBlocks();
/** /**
* Gets the resistance of the conductor. Used * Gets the resistance of the conductor. Used to calculate energy loss. A higher resistance
* to calculate energy loss. A higher * means a higher energy loss.
* resistance means a higher energy loss.
* *
* @return The amount of Ohm's of resistance. * @return The amount of Ohm's of resistance.
*/ */
public double getResistance(); public double getResistance();
/** /**
* The maximum amount of amps this conductor * The maximum amount of amps this conductor can handle before melting down. This is calculating
* can handle before melting down. This is * PER TICK!
* calculating PER TICK!
* *
* @return The amount of amps in volts * @return The amount of amps in volts
*/ */
public double getMaxAmps(); public double getMaxAmps();
/** /**
* Called when the electricity passing through * Called when the electricity passing through exceeds the maximum voltage.
* exceeds the maximum voltage.
*/ */
public void onOverCharge(); public void onOverCharge();
/** /**
* Resets the conductor and recalculate * Resets the conductor and recalculate connection IDs again
* connection IDs again
*/ */
public void reset(); public void reset();
public World getWorld(); public World getWorld();
/** /**
* Adds a connection between this conductor * Adds a connection between this conductor and a UE unit
* and a UE unit
* *
* @param tileEntity * @param tileEntity
* - Must be either a producer, * - Must be either a producer, consumer or a conductor
* consumer or a conductor
* @param side * @param side
* - side in which the connection * - side in which the connection is coming from
* is coming from
*/ */
public void updateConnection(TileEntity tileEntity, ForgeDirection side); public void updateConnection(TileEntity tileEntity, ForgeDirection side);

View file

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

View file

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

View file

@ -1,10 +1,8 @@
package universalelectricity.core.implement; package universalelectricity.core.implement;
/** /**
* Applied to TileEntities that can produces * Applied to TileEntities that can produces electricity. Of course, you will still need to call
* electricity. Of course, you will still need to * ElectricityManager.instance.produce() to actually output the electricity.
* call ElectricityManager.instance.produce() to
* actually output the electricity.
* *
* @author Calclavia * @author Calclavia
*/ */

View file

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

View file

@ -10,25 +10,21 @@ public interface IItemElectric extends IJouleStorage, IVoltage
public double onReceive(double amps, double voltage, ItemStack itemStack); public double onReceive(double amps, double voltage, ItemStack itemStack);
/** /**
* Called when something requests electricity * Called when something requests electricity from this item.
* from this item.
* *
* @return - The amount of given joules * @return - The amount of given joules
*/ */
public double onUse(double joulesNeeded, ItemStack itemStack); public double onUse(double joulesNeeded, ItemStack itemStack);
/** /**
* @return Returns true or false if this * @return Returns true or false if this consumer can receive electricity at this given tick or
* consumer can receive electricity at * moment.
* this given tick or moment.
*/ */
public boolean canReceiveElectricity(); public boolean canReceiveElectricity();
/** /**
* Can this item give out electricity when * Can this item give out electricity when placed in an tile entity? Electric items like
* placed in an tile entity? Electric items * batteries should be able to produce electricity (if they are rechargeable).
* like batteries should be able to produce
* electricity (if they are rechargeable).
* *
* @return - True or False. * @return - True or False.
*/ */

View file

@ -1,28 +1,24 @@
package universalelectricity.core.implement; package universalelectricity.core.implement;
/** /**
* This interface is to be applied to all tile * This interface is to be applied to all tile entities which stores energy within them.
* entities which stores energy within them.
* *
* @author Calclavia * @author Calclavia
*/ */
public interface IJouleStorage public interface IJouleStorage
{ {
/** /**
* Returns the amount of joules this unit has * Returns the amount of joules this unit has stored.
* stored.
*/ */
public double getJoules(Object... data); public double getJoules(Object... data);
/** /**
* Sets the amount of joules this unit has * Sets the amount of joules this unit has stored.
* stored.
*/ */
public void setJoules(double wattHours, Object... data); public void setJoules(double joules, Object... data);
/** /**
* Gets the maximum amount of joules this unit * Gets the maximum amount of joules this unit can store.
* can store.
*/ */
public double getMaxJoules(Object... data); public double getMaxJoules(Object... data);
} }

View file

@ -11,8 +11,7 @@ public interface IVoltage
/** /**
* Gets the voltage of this object. * Gets the voltage of this object.
* *
* @return The amount of volts. E.g 120v or * @return The amount of volts. E.g 120v or 240v
* 240v
*/ */
public double getVoltage(); public double getVoltage();
} }

View file

@ -3,11 +3,9 @@ package universalelectricity.core.vector;
import net.minecraft.src.MathHelper; import net.minecraft.src.MathHelper;
/** /**
* Vector2 Class is used for defining objects in a * Vector2 Class is used for defining objects in a 2D space. Vector2 makes it easier to handle the
* 2D space. Vector2 makes it easier to handle the * coordinates of objects. Instead of fumbling with x and y variables, all x and y variables are
* coordinates of objects. Instead of fumbling * stored in one class. Vector3.x, Vector3.y.
* with x and y variables, all x and y variables
* are stored in one class. Vector3.x, Vector3.y.
* *
* @author Calclavia * @author Calclavia
*/ */
@ -46,8 +44,7 @@ public class Vector2 implements Cloneable
} }
/** /**
* Makes a new copy of this Vector. Prevents * Makes a new copy of this Vector. Prevents variable referencing problems.
* variable referencing problems.
*/ */
@Override @Override
public Vector2 clone() public Vector2 clone()
@ -80,7 +77,7 @@ public class Vector2 implements Cloneable
this.x += par1; this.x += par1;
this.y += par1; this.y += par1;
} }
public void substract(Vector2 par1) public void substract(Vector2 par1)
{ {
this.x -= par1.x; this.x -= par1.x;
@ -106,6 +103,6 @@ public class Vector2 implements Cloneable
@Override @Override
public String toString() public String toString()
{ {
return "Vector2: " + this.x + "," + this.y; return "Vector2 [" + this.x + "," + this.y + "]";
} }
} }

View file

@ -1,5 +1,8 @@
package universalelectricity.core.vector; package universalelectricity.core.vector;
import java.util.List;
import net.minecraft.src.AxisAlignedBB;
import net.minecraft.src.ChunkCoordinates; import net.minecraft.src.ChunkCoordinates;
import net.minecraft.src.Entity; import net.minecraft.src.Entity;
import net.minecraft.src.IBlockAccess; import net.minecraft.src.IBlockAccess;
@ -13,12 +16,9 @@ import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.implement.IConnector; import universalelectricity.core.implement.IConnector;
/** /**
* Vector3 Class is used for defining objects in a * Vector3 Class is used for defining objects in a 3D space. Vector3 makes it easier to handle the
* 3D space. Vector3 makes it easier to handle the * coordinates of objects. Instead of fumbling with x, y and z variables, all x, y and z variables
* coordinates of objects. Instead of fumbling * are stored in one class. Vector3.x, Vector3.y, Vector3.z.
* with x, y and z variables, all x, y and z
* variables are stored in one class. Vector3.x,
* Vector3.y, Vector3.z.
* *
* @author Calclavia * @author Calclavia
*/ */
@ -65,8 +65,7 @@ public class Vector3 extends Vector2 implements Cloneable
} }
/** /**
* Makes a new copy of this Vector. Prevents * Makes a new copy of this Vector. Prevents variable referencing problems.
* variable referencing problems.
*/ */
@Override @Override
public Vector3 clone() public Vector3 clone()
@ -139,8 +138,7 @@ public class Vector3 extends Vector2 implements Cloneable
} }
/** /**
* Converts this Vector3 into a Vector2 by * Converts this Vector3 into a Vector2 by dropping the Y axis.
* dropping the Y axis.
*/ */
public Vector2 toVector2() public Vector2 toVector2()
{ {
@ -148,8 +146,7 @@ public class Vector3 extends Vector2 implements Cloneable
} }
/** /**
* Converts this vector three into a Minecraft * Converts this vector three into a Minecraft Vec3 object
* Vec3 object
*/ */
public Vec3 toVec3() public Vec3 toVec3()
{ {
@ -157,8 +154,7 @@ public class Vector3 extends Vector2 implements Cloneable
} }
/** /**
* Compares two vectors and see if they are * Compares two vectors and see if they are equal. True if so.
* equal. True if so.
*/ */
public boolean isEqual(Vector3 vector3) public boolean isEqual(Vector3 vector3)
{ {
@ -223,14 +219,28 @@ public class Vector3 extends Vector2 implements Cloneable
this.z -= amount.z; this.z -= amount.z;
} }
public static Vector3 multiply(Vector3 par1, Vector3 par2) public void multiply(int amount)
{ {
return new Vector3(par1.x * par2.x, par1.y * par2.y, par1.z * par2.z); this.x *= amount;
this.y *= amount;
this.z *= amount;
} }
public static Vector3 multiply(Vector3 par1, double par2) public void multiply(Vector3 vec)
{ {
return new Vector3(par1.x * par2, par1.y * par2, par1.z * par2); this.x *= vec.x;
this.y *= vec.y;
this.z *= vec.z;
}
public static Vector3 multiply(Vector3 vec1, Vector3 vec2)
{
return new Vector3(vec1.x * vec2.x, vec1.y * vec2.y, vec1.z * vec2.z);
}
public static Vector3 multiply(Vector3 vec1, double vec2)
{
return new Vector3(vec1.x * vec2, vec1.y * vec2, vec1.z * vec2);
} }
public static Vector3 readFromNBT(String prefix, NBTTagCompound par1NBTTagCompound) public static Vector3 readFromNBT(String prefix, NBTTagCompound par1NBTTagCompound)
@ -246,11 +256,9 @@ public class Vector3 extends Vector2 implements Cloneable
* Saves this Vector3 to disk * Saves this Vector3 to disk
* *
* @param prefix * @param prefix
* - The prefix of this save. Use * - The prefix of this save. Use some unique string.
* some unique string.
* @param par1NBTTagCompound * @param par1NBTTagCompound
* - The NBT compound object to * - The NBT compound object to save the data in
* save the data in
*/ */
public void writeToNBT(String prefix, NBTTagCompound par1NBTTagCompound) public void writeToNBT(String prefix, NBTTagCompound par1NBTTagCompound)
{ {
@ -270,44 +278,54 @@ public class Vector3 extends Vector2 implements Cloneable
{ {
return new Vector3(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z)); return new Vector3(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z));
} }
/** /**
* Gets a position relative to another * Gets all entities inside of this position in block space.
* position's side */
public List<Entity> getEntitiesWithin(World worldObj, Class<? extends Entity> par1Class)
{
return (List<Entity>) worldObj.getEntitiesWithinAABB(par1Class, AxisAlignedBB.getBoundingBox(this.intX(), this.intY(), this.intZ(), this.intX() + 1, this.intY() + 1, this.intZ() + 1));
}
/**
* Gets a position relative to another position's side
* *
* @param position * @param position
* - The position * - The position
* @param side * @param side
* - The side. 0-5 * - The side. 0-5
* @return The position relative to the * @return The position relative to the original position's side
* original position's side
*/ */
public void modifyPositionFromSide(ForgeDirection side) public void modifyPositionFromSide(ForgeDirection side, double amount)
{ {
switch (side.ordinal()) switch (side.ordinal())
{ {
case 0: case 0:
this.y -= 1; this.y -= amount;
break; break;
case 1: case 1:
this.y += 1; this.y += amount;
break; break;
case 2: case 2:
this.z -= 1; this.z -= amount;
break; break;
case 3: case 3:
this.z += 1; this.z += amount;
break; break;
case 4: case 4:
this.x -= 1; this.x -= amount;
break; break;
case 5: case 5:
this.x += 1; this.x += amount;
break; break;
} }
} }
public void modifyPositionFromSide(ForgeDirection side)
{
this.modifyPositionFromSide(side, 1);
}
public static TileEntity getTileEntityFromSide(World world, Vector3 position, ForgeDirection side) public static TileEntity getTileEntityFromSide(World world, Vector3 position, ForgeDirection side)
{ {
position.modifyPositionFromSide(side); position.modifyPositionFromSide(side);
@ -315,8 +333,7 @@ public class Vector3 extends Vector2 implements Cloneable
} }
/** /**
* Gets a connector unit based on the given * Gets a connector unit based on the given side.
* side.
*/ */
public static TileEntity getConnectorFromSide(World world, Vector3 position, ForgeDirection side) public static TileEntity getConnectorFromSide(World world, Vector3 position, ForgeDirection side)
{ {
@ -331,25 +348,17 @@ public class Vector3 extends Vector2 implements Cloneable
} }
/** /**
* Finds the side of a block depending on it's * Finds the side of a block depending on it's facing direction from the given side. The side
* facing direction from the given side. The * numbers are compatible with the function "getBlockTextureFromSideAndMetadata".
* side numbers are compatible with the
* function
* "getBlockTextureFromSideAndMetadata".
* *
* Bottom: 0; Top: 1; Back: 2; Front: 3; Left: * Bottom: 0; Top: 1; Back: 2; Front: 3; Left: 4; Right: 5;
* 4; Right: 5;
* *
* @param front * @param front
* - The direction in which this * - The direction in which this block is facing/front. Use a number between 0 and 5.
* block is facing/front. Use a * Default is 3.
* number between 0 and 5. Default
* is 3.
* @param side * @param side
* - The side you are trying to * - The side you are trying to find. A number between 0 and 5.
* find. A number between 0 and 5. * @return The side relative to the facing direction.
* @return The side relative to the facing
* direction.
*/ */
public static ForgeDirection getOrientationFromSide(ForgeDirection front, ForgeDirection side) public static ForgeDirection getOrientationFromSide(ForgeDirection front, ForgeDirection side)
@ -447,10 +456,10 @@ public class Vector3 extends Vector2 implements Cloneable
return ForgeDirection.UNKNOWN; return ForgeDirection.UNKNOWN;
} }
@Override @Override
public String toString() public String toString()
{ {
return "Vector3: " + this.x + "," + this.y + "," + this.z; return "Vector3 [" + this.x + "," + this.y + "," + this.z + "]";
} }
} }

View file

@ -0,0 +1,54 @@
package universalelectricity.prefab;
import net.minecraft.src.BlockContainer;
import net.minecraft.src.Material;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
import universalelectricity.core.implement.IConductor;
public abstract class BlockConductor extends BlockContainer
{
public BlockConductor(int id, Material material)
{
super(id, material);
}
/**
* Called whenever the block is added into the world. Args: world, x, y, z
*/
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
super.onBlockAdded(world, x, y, z);
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity != null)
{
if (tileEntity instanceof IConductor)
{
((IConductor) tileEntity).refreshConnectedBlocks();
}
}
}
/**
* Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed
* (coordinates passed are their own) Args: x, y, z, neighbor blockID
*/
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int blockID)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity != null)
{
if (tileEntity instanceof IConductor)
{
((IConductor) tileEntity).refreshConnectedBlocks();
}
}
world.markBlockForUpdate(x, y, z);
}
}

View file

@ -13,14 +13,12 @@ import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntity;
import net.minecraft.src.World; import net.minecraft.src.World;
import universalelectricity.core.implement.IItemElectric; import universalelectricity.core.implement.IItemElectric;
import buildcraft.api.tools.IToolWrench; import universalelectricity.prefab.implement.IWrench;
/** /**
* A block you may extend from to create your * A block you may extend from to create your machine blocks! You do not have to extend from this
* machine blocks! You do not have to extend from * block if you do not want to. It's optional but it comes with some useful functions that will make
* this block if you do not want to. It's optional * coding easier for you.
* but it comes with some useful functions that
* will make coding easier for you.
*/ */
public abstract class BlockMachine extends BlockContainer public abstract class BlockMachine extends BlockContainer
{ {
@ -44,8 +42,7 @@ public abstract class BlockMachine extends BlockContainer
} }
/** /**
* Returns the quantity of items to drop on * Returns the quantity of items to drop on block destruction.
* block destruction.
*/ */
@Override @Override
public int quantityDropped(Random par1Random) public int quantityDropped(Random par1Random)
@ -54,8 +51,7 @@ public abstract class BlockMachine extends BlockContainer
} }
/** /**
* Returns the ID of the items to drop on * Returns the ID of the items to drop on destruction.
* destruction.
*/ */
@Override @Override
public int idDropped(int par1, Random par2Random, int par3) public int idDropped(int par1, Random par2Random, int par3)
@ -64,13 +60,9 @@ public abstract class BlockMachine extends BlockContainer
} }
/** /**
* DO NOT OVERRIDE THIS FUNCTION! Called when * DO NOT OVERRIDE THIS FUNCTION! Called when the block is right clicked by the player. This
* the block is right clicked by the player. * modified version detects electric items and wrench actions on your machine block. Do not
* This modified version detects electric * override this function. Use machineActivated instead! (It does the same thing)
* items and wrench actions on your machine
* block. Do not override this function. Use
* machineActivated instead! (It does the same
* thing)
*/ */
@Override @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 par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
@ -78,16 +70,14 @@ public abstract class BlockMachine extends BlockContainer
int metadata = par1World.getBlockMetadata(x, y, z); int metadata = par1World.getBlockMetadata(x, y, z);
/** /**
* Check if the player is holding a wrench * Check if the player is holding a wrench or an electric item. If so, do not open the GUI.
* or an electric item. If so, do not open
* the GUI.
*/ */
if (par5EntityPlayer.inventory.getCurrentItem() != null) if (par5EntityPlayer.inventory.getCurrentItem() != null)
{ {
if (par5EntityPlayer.inventory.getCurrentItem().getItem() instanceof IToolWrench) if (par5EntityPlayer.inventory.getCurrentItem().getItem() instanceof IWrench)
{ {
par1World.notifyBlocksOfNeighborChange(x, y, z, this.blockID); par1World.notifyBlocksOfNeighborChange(x, y, z, this.blockID);
((IToolWrench) par5EntityPlayer.inventory.getCurrentItem().getItem()).wrenchUsed(par5EntityPlayer, x, y, z); ((IWrench) par5EntityPlayer.inventory.getCurrentItem().getItem()).wrenchUsed(par5EntityPlayer, x, y, z);
if (par5EntityPlayer.isSneaking()) if (par5EntityPlayer.isSneaking())
{ {
@ -115,8 +105,7 @@ public abstract class BlockMachine extends BlockContainer
} }
/** /**
* Called when the machine is right clicked by * Called when the machine is right clicked by the player
* the player
* *
* @return True if something happens * @return True if something happens
*/ */
@ -126,8 +115,7 @@ public abstract class BlockMachine extends BlockContainer
} }
/** /**
* Called when the machine is right clicked by * Called when the machine is right clicked by the player while sneaking (shift clicking)
* the player while sneaking (shift clicking)
* *
* @return True if something happens * @return True if something happens
*/ */
@ -137,8 +125,7 @@ public abstract class BlockMachine extends BlockContainer
} }
/** /**
* Called when a player uses an electric item * Called when a player uses an electric item on the machine
* on the machine
* *
* @return True if some happens * @return True if some happens
*/ */
@ -148,8 +135,7 @@ public abstract class BlockMachine extends BlockContainer
} }
/** /**
* Called when a player uses a wrench on the * Called when a player uses a wrench on the machine
* machine
* *
* @return True if some happens * @return True if some happens
*/ */
@ -159,8 +145,7 @@ public abstract class BlockMachine extends BlockContainer
} }
/** /**
* Called when a player uses a wrench on the * Called when a player uses a wrench on the machine while sneaking
* machine while sneaking
* *
* @return True if some happens * @return True if some happens
*/ */
@ -170,10 +155,8 @@ public abstract class BlockMachine extends BlockContainer
} }
/** /**
* Returns the TileEntity used by this block. * Returns the TileEntity used by this block. You should use the metadata sensitive version of
* You should use the metadata sensitive * this to get the maximum optimization!
* version of this to get the maximum
* optimization!
*/ */
@Override @Override
public TileEntity createNewTileEntity(World var1) public TileEntity createNewTileEntity(World var1)
@ -182,9 +165,8 @@ public abstract class BlockMachine extends BlockContainer
} }
/** /**
* Override this if you don't need it. This * Override this if you don't need it. This will eject all items out of this machine if it has
* will eject all items out of this machine if * an inventory
* it has an inventory
*/ */
@Override @Override
public void breakBlock(World par1World, int x, int y, int z, int par5, int par6) public void breakBlock(World par1World, int x, int y, int z, int par5, int par6)

View file

@ -0,0 +1,205 @@
package universalelectricity.prefab;
import java.util.List;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.NBTTagFloat;
import net.minecraft.src.World;
import universalelectricity.core.electricity.ElectricInfo;
import universalelectricity.core.electricity.ElectricInfo.ElectricUnit;
import universalelectricity.core.implement.IItemElectric;
/**
* Extend from this class if your item requires electricity or to be charged. Optionally, you can
* implement IItemElectric instead.
*
* @author Calclavia
*
*/
public abstract class ItemElectric extends Item implements IItemElectric
{
public ItemElectric(int id)
{
super(id);
this.setMaxStackSize(1);
this.setMaxDamage((int) this.getMaxJoules());
this.setNoRepair();
}
/**
* Allows items to add custom lines of information to the mouseover description. If you want to
* add more information to your item, you can super.addInformation() to keep the electiricty
* info in the item info bar.
*/
@Override
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{
String color = "";
double joules = this.getJoules(par1ItemStack);
if (joules <= this.getMaxJoules() / 3)
{
color = "\u00a74";
}
else if (joules > this.getMaxJoules() * 2 / 3)
{
color = "\u00a72";
}
else
{
color = "\u00a76";
}
par3List.add(color + ElectricInfo.getDisplay(joules, ElectricUnit.JOULES) + " - " + Math.round((joules / this.getMaxJoules()) * 100) + "%");
}
/**
* Make sure you super this method!
*/
@Override
public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5)
{
// Makes sure the damage is set correctly
// for this electric item!
ItemElectric item = ((ItemElectric) par1ItemStack.getItem());
item.setJoules(item.getJoules(par1ItemStack), par1ItemStack);
}
/**
* Makes sure the item is uncharged when it is crafted and not charged. Change this if you do
* not want this to happen!
*/
@Override
public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
par1ItemStack = this.getUncharged();
}
@Override
public double onReceive(double amps, double voltage, ItemStack itemStack)
{
double rejectedElectricity = Math.max((this.getJoules(itemStack) + ElectricInfo.getJoules(amps, voltage, 1)) - this.getMaxJoules(), 0);
this.setJoules(this.getJoules(itemStack) + ElectricInfo.getJoules(amps, voltage, 1) - rejectedElectricity, itemStack);
return rejectedElectricity;
}
@Override
public double onUse(double joulesNeeded, ItemStack itemStack)
{
double electricityToUse = Math.min(this.getJoules(itemStack), joulesNeeded);
this.setJoules(this.getJoules(itemStack) - electricityToUse, itemStack);
return electricityToUse;
}
public boolean canReceiveElectricity()
{
return true;
}
public boolean canProduceElectricity()
{
return false;
}
/**
* 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
*/
@Override
public void setJoules(double wattHours, Object... data)
{
if (data[0] instanceof ItemStack)
{
ItemStack itemStack = (ItemStack) data[0];
// Saves the frequency in the
// itemstack
if (itemStack.stackTagCompound == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
double electricityStored = Math.max(Math.min(wattHours, this.getMaxJoules()), 0);
itemStack.stackTagCompound.setDouble("electricity", electricityStored);
itemStack.setItemDamage((int) (getMaxJoules() - electricityStored));
}
}
/**
* This function is called to get the electricity stored in this item
*
* @return - The amount of electricity stored in watts
*/
@Override
public double getJoules(Object... data)
{
if (data[0] instanceof ItemStack)
{
ItemStack itemStack = (ItemStack) data[0];
if (itemStack.stackTagCompound == null) { return 0; }
double electricityStored = 0;
if (itemStack.stackTagCompound.getTag("electricity") instanceof NBTTagFloat)
{
electricityStored = itemStack.stackTagCompound.getFloat("electricity");
}
else
{
electricityStored = itemStack.stackTagCompound.getDouble("electricity");
}
itemStack.setItemDamage((int) (getMaxJoules() - electricityStored));
return electricityStored;
}
return -1;
}
/**
* Returns an uncharged version of the electric item. Use this if you want the crafting recipe
* to use a charged version of the electric item instead of an empty version of the electric
* item
*
* @return The ItemStack of a fully charged electric item
*/
public ItemStack getUncharged()
{
ItemStack chargedItem = new ItemStack(this);
chargedItem.setItemDamage((int) this.getMaxJoules());
return chargedItem;
}
public static ItemStack getUncharged(ItemStack itemStack)
{
if (itemStack.getItem() instanceof IItemElectric)
{
ItemStack chargedItem = itemStack.copy();
chargedItem.setItemDamage((int) ((IItemElectric) itemStack.getItem()).getMaxJoules());
return chargedItem;
}
return null;
}
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
// Add an uncharged version of the
// electric item
ItemStack unchargedItem = new ItemStack(this, 1);
unchargedItem.setItemDamage((int) this.getMaxJoules());
par3List.add(unchargedItem);
// Add an electric item to the creative
// list that is fully charged
ItemStack chargedItem = new ItemStack(this, 1);
this.setJoules(((IItemElectric) chargedItem.getItem()).getMaxJoules(), chargedItem);
par3List.add(chargedItem);
}
}

View file

@ -0,0 +1,188 @@
package universalelectricity.prefab;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
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;
/**
* This class is used to replace recipes that are already added in the existing recipe pool for
* crafting and smelting. All recipe functions take account of the Forge Ore Dictionary. It also
* includes some recipe helper functions to shorten some of your function calls.
*
* @author Calclavia
*
*/
public class RecipeHelper
{
public static List<IRecipe> getRecipesByOutput(ItemStack output)
{
List<IRecipe> list = new ArrayList<IRecipe>();
for (Object obj : CraftingManager.getInstance().getRecipeList())
{
if (obj instanceof IRecipe)
{
if (((IRecipe) obj).getRecipeOutput() == output)
{
list.add((IRecipe) obj);
}
}
}
return list;
}
/**
* Replaces a recipe with a new IRecipe.
*
* @return True if successful
*/
public static boolean replaceRecipe(IRecipe recipe, IRecipe newRecipe)
{
for (Object obj : CraftingManager.getInstance().getRecipeList())
{
if (obj instanceof IRecipe)
{
if (((IRecipe) obj).equals(recipe) || obj == recipe)
{
CraftingManager.getInstance().getRecipeList().remove(obj);
CraftingManager.getInstance().getRecipeList().add(newRecipe);
return true;
}
}
}
return false;
}
/**
* Replaces a recipe with the resulting ItemStack with a new IRecipe.
*
* @return True if successful
*/
public static boolean replaceRecipe(ItemStack recipe, IRecipe newRecipe)
{
if (removeRecipe(recipe))
{
CraftingManager.getInstance().getRecipeList().add(newRecipe);
return true;
}
return false;
}
/**
* Removes a recipe by its IRecipe class.
*
* @return True if successful
*/
public static boolean removeRecipe(IRecipe recipe)
{
for (Object obj : CraftingManager.getInstance().getRecipeList())
{
if (obj != null)
{
if (obj instanceof IRecipe)
{
if (((IRecipe) obj).equals(recipe) || obj == recipe)
{
CraftingManager.getInstance().getRecipeList().remove(obj);
return true;
}
}
}
}
return false;
}
/**
* Removes the first recipe found by its output.
*
* @return True if successful
*/
public static boolean removeRecipe(ItemStack stack)
{
for (Object obj : CraftingManager.getInstance().getRecipeList())
{
if (obj != null)
{
if (obj instanceof IRecipe)
{
if (((IRecipe) obj).getRecipeOutput() != null)
{
if (((IRecipe) obj).getRecipeOutput().isItemEqual(stack))
{
CraftingManager.getInstance().getRecipeList().remove(obj);
return true;
}
}
}
}
}
return false;
}
/**
* Removes all recipes found that has this output.
*
* @return True if successful
*/
public static boolean removeRecipes(ItemStack... itemStacks)
{
boolean didRemove = false;
for (Iterator itr = CraftingManager.getInstance().getRecipeList().iterator(); itr.hasNext();)
{
Object obj = itr.next();
if (obj != null)
{
if (obj instanceof IRecipe)
{
if (((IRecipe) obj).getRecipeOutput() != null)
{
for (ItemStack itemStack : itemStacks)
{
if (((IRecipe) obj).getRecipeOutput().isItemEqual(itemStack))
{
itr.remove();
didRemove = true;
break;
}
}
}
}
}
}
return didRemove;
}
/**
* 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)
{
if (config != null)
{
if (UEConfig.getConfigData(config, "Allow " + name + " Crafting", defaultBoolean))
{
GameRegistry.addRecipe(recipe);
}
}
}
public static void addRecipe(IRecipe recipe, Configuration config, boolean defaultBoolean)
{
addRecipe(recipe, recipe.getRecipeOutput().getItemName(), config, defaultBoolean);
}
}

View file

@ -0,0 +1,29 @@
package universalelectricity.prefab;
import net.minecraft.src.IInventory;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Slot;
import universalelectricity.core.implement.IItemElectric;
/**
* This slot should be used by any container that needs the slot for an electric items only.
*
* @author Calclavia
*
*/
public class SlotElectricItem extends Slot
{
public SlotElectricItem(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 IItemElectric;
}
}

View file

@ -0,0 +1,57 @@
package universalelectricity.prefab;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.src.DamageSource;
import cpw.mods.fml.common.registry.LanguageRegistry;
public class UEDamageSource extends DamageSource
{
public static final List<UEDamageSource> damageSources = new ArrayList<UEDamageSource>();
/**
* Use this damage source for all types of electrical attacks.
*/
public static final UEDamageSource electrocution = (UEDamageSource) new UEDamageSource("electrocution", "%1$s got electrocuted!").setDamageBypassesArmor();
public String deathMessage;
public UEDamageSource(String damageType)
{
super(damageType);
damageSources.add(this);
}
public UEDamageSource(String damageType, String deathMessage)
{
this(damageType);
this.setDeathMessage(deathMessage);
}
public UEDamageSource setDeathMessage(String deathMessage)
{
this.deathMessage = deathMessage;
return this;
}
public DamageSource setDamageBypassesArmor()
{
return super.setDamageBypassesArmor();
}
public DamageSource setDamageAllowedInCreativeMode()
{
return super.setDamageAllowedInCreativeMode();
}
public DamageSource setFireDamage()
{
return super.setFireDamage();
}
public void registerDeathMessage()
{
LanguageRegistry.instance().addStringLocalization("death." + this.damageType, this.deathMessage);
}
}

View file

@ -3,8 +3,7 @@ package universalelectricity.prefab.implement;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
/** /**
* This should be applied on tile entities that * This should be applied on tile entities that can provide redstone power
* can provide redstone power
* *
* @author Calclavia * @author Calclavia
* *

View file

@ -1,8 +1,7 @@
package universalelectricity.prefab.implement; package universalelectricity.prefab.implement;
/** /**
* This interface should be applied onto all tile * This interface should be applied onto all tile entities that needs to receive redstone power.
* entities that needs to receive redstone power.
* Look at TileEntityBatteryBox for reference. * Look at TileEntityBatteryBox for reference.
* *
* @author Calclavia * @author Calclavia
@ -11,14 +10,12 @@ package universalelectricity.prefab.implement;
public interface IRedstoneReceptor public interface IRedstoneReceptor
{ {
/** /**
* Called when the block is powered on by * Called when the block is powered on by redstone
* redstone
*/ */
public void onPowerOn(); public void onPowerOn();
/** /**
* Called when the block is powered off by * Called when the block is powered off by redstone
* redstone
*/ */
public void onPowerOff(); public void onPowerOff();
} }

View file

@ -3,10 +3,8 @@ package universalelectricity.prefab.implement;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
/** /**
* This interface should be applied onto all tile * This interface should be applied onto all tile entities that are rotatable. This interface
* entities that are rotatable. This interface * however is optional and you do not need it for your add-on to function. It just makes things
* however is optional and you do not need it for
* your add-on to function. It just makes things
* easier for you to code. * easier for you to code.
* *
* @author Calclavia * @author Calclavia
@ -16,26 +14,20 @@ import net.minecraftforge.common.ForgeDirection;
public interface IRotatable public interface IRotatable
{ {
/** /**
* Gets the facing direction of the tile * Gets the facing direction of the tile entity. Always returns the front side of the tile
* entity. Always returns the front side of * entity.
* the tile entity.
* *
* @return The facing side from 0-5 The full * @return The facing side from 0-5 The full list of which side the number represents is in the
* list of which side the number
* represents is in the
* UniversalElectricity class. * UniversalElectricity class.
*/ */
public ForgeDirection getDirection(); public ForgeDirection getDirection();
/** /**
* Sets the facing direction of the tile * Sets the facing direction of the tile entity.
* entity.
* *
* @param facingDirection * @param facingDirection
* - A direction from 0-5. The full * - A direction from 0-5. The full list of which side the number represents is in
* list of which side the number * the UniversalElectricity class.
* represents is in the
* UniversalElectricity class.
*/ */
public void setDirection(ForgeDirection facingDirection); public void setDirection(ForgeDirection facingDirection);
} }

View file

@ -1,8 +1,7 @@
package universalelectricity.prefab.implement; package universalelectricity.prefab.implement;
/** /**
* This interface should be applied to all things * This interface should be applied to all things that has a tier/level.
* that has a tier/level.
* *
* @author Calclavia * @author Calclavia
* *

View file

@ -0,0 +1,36 @@
package universalelectricity.prefab.implement;
import net.minecraft.src.EntityPlayer;
/**
* Code written by Buildcraft.
*
* @author Buildcraft Team
*/
public interface IWrench
{
/***
* 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
*
* @return true if wrenching is allowed, false if not
*/
public boolean canWrench(EntityPlayer player, int x, int y, int z);
/***
* 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
*/
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

@ -36,12 +36,9 @@ public class BlockMulti extends BlockContainer
} }
/** /**
* Called when the block is right clicked by * Called when the block is right clicked by the player. This modified version detects electric
* the player. This modified version detects * items and wrench actions on your machine block. Do not override this function. Use
* electric items and wrench actions on your * machineActivated instead! (It does the same thing)
* machine block. Do not override this
* function. Use machineActivated instead! (It
* does the same thing)
*/ */
@Override @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 par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
@ -51,8 +48,7 @@ public class BlockMulti extends BlockContainer
} }
/** /**
* Returns the quantity of items to drop on * Returns the quantity of items to drop on block destruction.
* block destruction.
*/ */
@Override @Override
public int quantityDropped(Random par1Random) public int quantityDropped(Random par1Random)

View file

@ -3,8 +3,7 @@ package universalelectricity.prefab.multiblock;
import net.minecraft.src.EntityPlayer; import net.minecraft.src.EntityPlayer;
/** /**
* A general interface to be implemented by * A general interface to be implemented by anything that needs it.
* anything that needs it.
* *
* @author Calclavia * @author Calclavia
* *

View file

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

View file

@ -14,8 +14,7 @@ import universalelectricity.prefab.network.PacketManager;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
/** /**
* This is a multiblock to be used for blocks that * This is a multiblock to be used for blocks that are bigger than one block.
* are bigger than one block.
* *
* @author Calclavia * @author Calclavia
* *
@ -97,11 +96,9 @@ public class TileEntityMulti extends TileEntity implements IPacketReceiver
} }
/** /**
* Determines if this TileEntity requires * Determines if this TileEntity requires update calls.
* update calls.
* *
* @return True if you want updateEntity() to * @return True if you want updateEntity() to be called, false if not
* be called, false if not
*/ */
public boolean canUpdate() public boolean canUpdate()
{ {

View file

@ -5,9 +5,7 @@ import universalelectricity.prefab.network.ConnectionHandler.ConnectionType;
public interface ISimpleConnectionHandler public interface ISimpleConnectionHandler
{ {
/** /**
* Called when a player logs in. Use this to * Called when a player logs in. Use this to reset some tile entities variables if you need to.
* reset some tile entities variables if you
* need to.
* *
* @param player * @param player
*/ */

View file

@ -21,20 +21,13 @@ import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player; import cpw.mods.fml.common.network.Player;
/** /**
* This class is used for sending and receiving * This class is used for sending and receiving packets between the server and the client. You can
* packets between the server and the client. You * directly use this by registering this packet manager with NetworkMod. Example:
* can directly use this by registering this
* packet manager with NetworkMod. Example:
* *
* @NetworkMod(channels = { "BasicComponents" }, * @NetworkMod(channels = { "BasicComponents" }, clientSideRequired = true, serverSideRequired =
* clientSideRequired = true, * false, packetHandler = PacketManager.class)
* serverSideRequired =
* false, packetHandler =
* PacketManager.class)
* *
* Check out * Check out {@link #BasicComponents} for better reference.
* {@link #BasicComponents}
* for better reference.
* *
* @author Calclavia * @author Calclavia
*/ */
@ -60,7 +53,6 @@ public class PacketManager implements IPacketHandler, IPacketReceiver
try try
{ {
data.writeInt(id); data.writeInt(id);
data = encodeDataStream(data, sendData); data = encodeDataStream(data, sendData);
Packet250CustomPayload packet = new Packet250CustomPayload(); Packet250CustomPayload packet = new Packet250CustomPayload();
@ -121,10 +113,8 @@ public class PacketManager implements IPacketHandler, IPacketReceiver
} }
/** /**
* Sends packets to clients around a specific * Sends packets to clients around a specific coordinate. A wrapper using Vector3. See
* coordinate. A wrapper using Vector3. See * {@PacketDispatcher} for detailed information.
* {@PacketDispatcher} for
* detailed information.
*/ */
public static void sendPacketToClients(Packet packet, World worldObj, Vector3 position, double range) public static void sendPacketToClients(Packet packet, World worldObj, Vector3 position, double range)
{ {
@ -140,8 +130,7 @@ public class PacketManager implements IPacketHandler, IPacketReceiver
} }
/** /**
* Sends a packet to all the clients on this * Sends a packet to all the clients on this server.
* server.
*/ */
public static void sendPacketToClients(Packet packet, World worldObj) public static void sendPacketToClients(Packet packet, World worldObj)
{ {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -4,8 +4,7 @@ import net.minecraft.src.Block;
import net.minecraft.src.TileEntity; import net.minecraft.src.TileEntity;
/** /**
* A TileEntity with some pre-added * A TileEntity with some pre-added functionalities.
* functionalities.
* *
* @author Calclavia * @author Calclavia
* *

View file

@ -16,8 +16,7 @@ import universalelectricity.prefab.network.IPacketReceiver;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
/** /**
* This tile entity pre-fabricated for all * This tile entity pre-fabricated for all conductors.
* conductors.
* *
* @author Calclavia * @author Calclavia
* *
@ -27,8 +26,7 @@ public abstract class TileEntityConductor extends TileEntityAdvanced implements
private ElectricityNetwork network; private ElectricityNetwork network;
/** /**
* Stores information on the blocks that this * Stores information on the blocks that this conductor is connected to
* conductor is connected to
*/ */
public TileEntity[] connectedBlocks = public TileEntity[] connectedBlocks =
{ null, null, null, null, null, null }; { null, null, null, null, null, null };
@ -122,11 +120,9 @@ public abstract class TileEntityConductor extends TileEntityAdvanced implements
} }
/** /**
* Determines if this TileEntity requires * Determines if this TileEntity requires update calls.
* update calls.
* *
* @return True if you want updateEntity() to * @return True if you want updateEntity() to be called, false if not
* be called, false if not
*/ */
@Override @Override
public boolean canUpdate() public boolean canUpdate()

View file

@ -3,9 +3,7 @@ package universalelectricity.prefab.tile;
import universalelectricity.core.implement.IDisableable; import universalelectricity.core.implement.IDisableable;
/** /**
* An easier way to implement the methods from * An easier way to implement the methods from IElectricityDisableable with default values set.
* IElectricityDisableable with default values
* set.
* *
* @author Calclavia * @author Calclavia
*/ */
@ -27,8 +25,7 @@ public abstract class TileEntityDisableable extends TileEntityAdvanced implement
} }
/** /**
* Called every tick while this tile entity is * Called every tick while this tile entity is disabled.
* disabled.
*/ */
protected void whileDisable() protected void whileDisable()
{ {

View file

@ -4,8 +4,7 @@ import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.implement.IElectricityReceiver; import universalelectricity.core.implement.IElectricityReceiver;
/** /**
* An easier way to implement the methods from * An easier way to implement the methods from IElectricityReceiver with default values set.
* IElectricityReceiver with default values set.
* *
* @author Calclavia * @author Calclavia
*/ */

View file

@ -1,4 +1,6 @@
package universalelectricity.core.vector; package universalelectricity.prefab.vector;
import universalelectricity.core.vector.Vector2;
public class Region2 public class Region2
{ {
@ -17,8 +19,7 @@ public class Region2
} }
/** /**
* Checks if a point is located inside a * Checks if a point is located inside a region
* region
*/ */
public boolean isIn(Vector2 point) public boolean isIn(Vector2 point)
{ {
@ -26,8 +27,7 @@ public class Region2
} }
/** /**
* Returns whether the given region intersects * Returns whether the given region intersects with this one.
* with this one.
*/ */
public boolean isIn(Region2 region) public boolean isIn(Region2 region)
{ {

View file

@ -1,4 +1,4 @@
package universalelectricity.core.vector; package universalelectricity.prefab.vector;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -6,6 +6,7 @@ import java.util.List;
import net.minecraft.src.AxisAlignedBB; import net.minecraft.src.AxisAlignedBB;
import net.minecraft.src.Entity; import net.minecraft.src.Entity;
import net.minecraft.src.World; import net.minecraft.src.World;
import universalelectricity.core.vector.Vector3;
/** /**
* A cubical region class. * A cubical region class.
@ -44,8 +45,7 @@ public class Region3
} }
/** /**
* Checks if a point is located inside a * Checks if a point is located inside a region
* region
*/ */
public boolean isIn(Vector3 point) public boolean isIn(Vector3 point)
{ {
@ -53,8 +53,7 @@ public class Region3
} }
/** /**
* Returns whether the given region intersects * Returns whether the given region intersects with this one.
* with this one.
*/ */
public boolean isIn(Region3 region) public boolean isIn(Region3 region)
{ {