diff --git a/README.md b/README.md index f817372d..6418f8d6 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -A mod that brings realistic transportation systems into Minecraft. +A mod that brings realistic factory style transportation systems into Minecraft. diff --git a/resources/assemblyline/textures/Thumbs.db b/resources/assemblyline/textures/Thumbs.db new file mode 100644 index 00000000..1205833b Binary files /dev/null and b/resources/assemblyline/textures/Thumbs.db differ diff --git a/src/common/assemblyline/ai/Task.java b/src/common/assemblyline/ai/Task.java index 3f89b439..ed972d86 100644 --- a/src/common/assemblyline/ai/Task.java +++ b/src/common/assemblyline/ai/Task.java @@ -1,6 +1,7 @@ package assemblyline.ai; import net.minecraft.src.TileEntity; +import assemblyline.machines.crafter.TileEntityCraftingArm; /** * An AI Task that is used by TileEntities with @@ -12,7 +13,11 @@ import net.minecraft.src.TileEntity; public abstract class Task { protected int ticks; - + protected TileEntityCraftingArm tileEntity; + public Task(TileEntityCraftingArm arm) + { + this.tileEntity = arm; + } /** * 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 0 for no ticks. diff --git a/src/common/assemblyline/ai/TaskIdle.java b/src/common/assemblyline/ai/TaskIdle.java index b308138c..a52000bd 100644 --- a/src/common/assemblyline/ai/TaskIdle.java +++ b/src/common/assemblyline/ai/TaskIdle.java @@ -1,14 +1,23 @@ package assemblyline.ai; +import assemblyline.machines.crafter.TileEntityCraftingArm; import net.minecraft.src.TileEntity; public class TaskIdle extends Task { - private TileEntity tileEntity; - - @Override - public void setTileEntity(TileEntity tileEntity) - { - this.tileEntity = tileEntity; + public TaskIdle(TileEntityCraftingArm arm) + { + super(arm); + } + protected boolean doTask() + { + /** + * randomly move the arm to + * similate life in the arm + * if the arm is powered + */ + return true; + } + } diff --git a/src/common/assemblyline/ai/TaskManager.java b/src/common/assemblyline/ai/TaskManager.java index f9f9e842..fa43020f 100644 --- a/src/common/assemblyline/ai/TaskManager.java +++ b/src/common/assemblyline/ai/TaskManager.java @@ -48,7 +48,6 @@ public class TaskManager public void addTask(TileEntity tileEntity, Task task) { - task.setTileEntity(tileEntity); task.onTaskStart(); tasks.add(task); } diff --git a/src/common/assemblyline/machine/TileEntityManipulator.java b/src/common/assemblyline/machine/TileEntityManipulator.java index 4075e4ba..fdd5d050 100644 --- a/src/common/assemblyline/machine/TileEntityManipulator.java +++ b/src/common/assemblyline/machine/TileEntityManipulator.java @@ -398,7 +398,7 @@ public class TileEntityManipulator extends TileEntityElectricityReceiver impleme } @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); } diff --git a/src/common/assemblyline/machine/TileEntityRejector.java b/src/common/assemblyline/machine/TileEntityRejector.java index e240997e..87efbd34 100644 --- a/src/common/assemblyline/machine/TileEntityRejector.java +++ b/src/common/assemblyline/machine/TileEntityRejector.java @@ -342,7 +342,7 @@ public class TileEntityRejector extends TileEntityElectricityReceiver implements } @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); diff --git a/src/common/assemblyline/machine/TileEntityRoboticSorter.java b/src/common/assemblyline/machine/TileEntityRoboticSorter.java index 7c95c019..7d53cfa8 100644 --- a/src/common/assemblyline/machine/TileEntityRoboticSorter.java +++ b/src/common/assemblyline/machine/TileEntityRoboticSorter.java @@ -85,7 +85,7 @@ public class TileEntityRoboticSorter extends TileEntityElectricityReceiver imple } @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); diff --git a/src/common/assemblyline/machine/belt/TileEntityConveyorBelt.java b/src/common/assemblyline/machine/belt/TileEntityConveyorBelt.java index e09a5d39..dbbcddbe 100644 --- a/src/common/assemblyline/machine/belt/TileEntityConveyorBelt.java +++ b/src/common/assemblyline/machine/belt/TileEntityConveyorBelt.java @@ -225,7 +225,7 @@ public class TileEntityConveyorBelt extends TileEntityElectricityReceiver implem } @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); } diff --git a/src/common/assemblyline/machines/crafter/TaskArmCollect.java b/src/common/assemblyline/machines/crafter/TaskArmCollect.java index fa9f8afe..1c7f5509 100644 --- a/src/common/assemblyline/machines/crafter/TaskArmCollect.java +++ b/src/common/assemblyline/machines/crafter/TaskArmCollect.java @@ -12,16 +12,17 @@ import assemblyline.ai.Task; */ public class TaskArmCollect extends Task { - private TileEntityCraftingArm tileEntity; + /** * The item to be collected. */ private EntityItem entityItem; - public TaskArmCollect(EntityItem entityItem) + public TaskArmCollect(TileEntityCraftingArm arm,EntityItem entityItem) { - this.entityItem = entityItem; + super(arm); + this.entityItem = entityItem; } @Override @@ -38,10 +39,4 @@ public class TaskArmCollect extends Task return true; } - - @Override - public void setTileEntity(TileEntity tileEntity) - { - this.tileEntity = (TileEntityCraftingArm) tileEntity; - } } diff --git a/src/common/assemblyline/machines/crafter/TaskArmSearch.java b/src/common/assemblyline/machines/crafter/TaskArmSearch.java index b5c7e61c..a3489b7b 100644 --- a/src/common/assemblyline/machines/crafter/TaskArmSearch.java +++ b/src/common/assemblyline/machines/crafter/TaskArmSearch.java @@ -13,7 +13,6 @@ import assemblyline.ai.Task; */ public class TaskArmSearch extends Task { - private TileEntityCraftingArm tileEntity; /** * The item to be collected. @@ -22,14 +21,13 @@ public class TaskArmSearch extends Task private float searchSpeed; - private World worldObj; - private double radius; private Entity foundEntity; - public TaskArmSearch(Class entityToInclude, double radius, float searchSpeed) + public TaskArmSearch(TileEntityCraftingArm arm,Class entityToInclude, double radius, float searchSpeed) { + super(arm); this.entityToInclude = entityToInclude; this.radius = radius; this.searchSpeed = searchSpeed; @@ -38,7 +36,7 @@ public class TaskArmSearch extends Task @Override 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 @@ -56,11 +54,4 @@ public class TaskArmSearch extends Task return true; } - - @Override - public void setTileEntity(TileEntity tileEntity) - { - this.tileEntity = (TileEntityCraftingArm) tileEntity; - this.worldObj = this.tileEntity.worldObj; - } } diff --git a/src/common/assemblyline/machines/crafter/TileEntityCraftingArm.java b/src/common/assemblyline/machines/crafter/TileEntityCraftingArm.java index 19e712a3..6e361d3c 100644 --- a/src/common/assemblyline/machines/crafter/TileEntityCraftingArm.java +++ b/src/common/assemblyline/machines/crafter/TileEntityCraftingArm.java @@ -68,7 +68,7 @@ public class TileEntityCraftingArm extends TileEntityElectricityReceiver impleme * UE methods */ @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); @@ -258,4 +258,5 @@ public class TileEntityCraftingArm extends TileEntityElectricityReceiver impleme nbt.setTag("Items", var2); } + } diff --git a/src/common/universalelectricity/core/UELoader.java b/src/common/universalelectricity/core/UELoader.java index 10454d58..3c7c4f0a 100644 --- a/src/common/universalelectricity/core/UELoader.java +++ b/src/common/universalelectricity/core/UELoader.java @@ -12,8 +12,7 @@ import cpw.mods.fml.common.Side; import cpw.mods.fml.common.registry.TickRegistry; /** - * A class used to load Universal Electricity and - * make it work. + * A class used to load Universal Electricity and make it work. * * @author Calclavia * diff --git a/src/common/universalelectricity/core/UniversalElectricity.java b/src/common/universalelectricity/core/UniversalElectricity.java index 6c069102..661ccc99 100644 --- a/src/common/universalelectricity/core/UniversalElectricity.java +++ b/src/common/universalelectricity/core/UniversalElectricity.java @@ -12,20 +12,14 @@ import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.Loader; /** - * Instructions for using the Universal - * Electricity API. + * Instructions for using the Universal Electricity API. * - * The less you include of the API, the more - * compatible your mod will be for future releases - * of Universal Electricity. + * The less you include of the API, the more compatible your mod will be for future releases of + * Universal Electricity. * - * REQUIRED PACKAGES: "universalelectricity" - * "universalelectricity.electricity" - * "universalelectricity.implements" - Some - * interfaces can be removed if not needed. + * REQUIRED PACKAGE: "universalelectricity.core" OPTIONAL PACKAGE: "universalelectricity.prefab" * - * The rest of the classes should be removed if - * you are not going to use them. + * All classes should be removed if you are not going to use them. * * @author Calclavia * @@ -33,23 +27,20 @@ import cpw.mods.fml.common.Loader; public class UniversalElectricity { /** - * The version of the Universal Electricity - * API. + * 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 = 1; + public static final int REVISION_VERSION = 3; public static final String VERSION = MAJOR_VERSION + "." + MINOR_VERSION + "." + REVISION_VERSION; /** - * The Universal Electricity configuration - * file. + * The Universal Electricity configuration file. */ public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), "UniversalElectricity/UniversalElectricity.cfg")); /** - * Conversion ratios between Buildcraft and - * Industrialcraft energy. + * 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); @@ -59,16 +50,14 @@ public class UniversalElectricity public static final float TO_BC_RATIO = 1 / BC3_RATIO; /** - * Use this material for all your machine - * blocks. It can be breakable by hand. + * Use this material for all your machine blocks. It can be breakable by hand. */ public static final Material machine = new Material(MapColor.ironColor); public static final List mods = new ArrayList(); /** - * You must register your mod with Universal - * Electricity. Call this in your mod's + * You must register your mod with Universal Electricity. Call this in your mod's * pre-initialization stage. */ 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 - * to a specific version of Forge. + * A function that allows you to lock your mod to a specific version of Forge. */ public static void forgeLock(int major, int minor, int revision, boolean strict) { diff --git a/src/common/universalelectricity/core/electricity/ElectricInfo.java b/src/common/universalelectricity/core/electricity/ElectricInfo.java index 4cf5757f..94ea3c28 100644 --- a/src/common/universalelectricity/core/electricity/ElectricInfo.java +++ b/src/common/universalelectricity/core/electricity/ElectricInfo.java @@ -1,8 +1,7 @@ package universalelectricity.core.electricity; /** - * An easy way to display information on - * electricity. + * An easy way to display information on electricity. * * @author Calclavia */ @@ -132,8 +131,7 @@ public class ElectricInfo } /** - * Displays the unit as text. Works only for - * positive numbers. + * Displays the unit as text. Works only for positive numbers. */ 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 - * places + * Rounds a number to a specific number place places * * @param The * number diff --git a/src/common/universalelectricity/core/electricity/ElectricityManager.java b/src/common/universalelectricity/core/electricity/ElectricityManager.java index bbb264b0..9f5d1d0c 100644 --- a/src/common/universalelectricity/core/electricity/ElectricityManager.java +++ b/src/common/universalelectricity/core/electricity/ElectricityManager.java @@ -7,6 +7,7 @@ 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; @@ -16,9 +17,8 @@ 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. + * This class is used to manage electricity transferring and flow. It is also used to call updates + * on UE tile entities. * * @author Calclavia * @@ -26,10 +26,8 @@ import cpw.mods.fml.common.TickType; 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. + * 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; @@ -42,8 +40,7 @@ public class ElectricityManager } /** - * Registers a the conductor into the UE - * electricity net. + * Registers a the conductor into the UE electricity net. * * @param conductor * - The IConductor tile entity. @@ -55,15 +52,12 @@ public class ElectricityManager } /** - * Merges two connection lines together into - * one. + * Merges two connection lines together into one. * * @param networkA - * - The network to be merged into. - * This network will be kept. + * - The network to be merged into. This network will be kept. * @param networkB - * - The network to be merged. This - * network will be deleted. + * - The network to be merged. This network will be deleted. */ public void mergeConnection(ElectricityNetwork networkA, ElectricityNetwork networkB) { @@ -84,11 +78,8 @@ public class ElectricityManager } /** - * 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. + * 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 @@ -123,8 +114,7 @@ public class ElectricityManager } /** - * Clean up and remove all useless and invalid - * connections. + * Clean up and remove all useless and invalid connections. */ public void cleanUpConnections() { @@ -147,25 +137,19 @@ public class ElectricityManager } /** - * Produces electricity into a specific wire - * which will be distributed across the - * electricity network. + * Produces electricity into a specific wire which will be distributed across the electricity + * network. * * @param sender - * The machine sending the - * electricity. + * The machine sending the electricity. * @param targetConductor - * The conductor receiving the - * electricity (or connected to the - * machine). + * The conductor receiving the electricity (or connected to the machine). * @param amps - * The amount of amps this machine - * is sending. + * The amount of amps this machine is sending. * @param voltage - * The amount of volts this machine - * is sending. + * The amount of volts this machine 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) { @@ -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())))); leftOverAmps -= transferAmps; - // Calculate - // electricity - // loss - double distance = Vector3.distance(Vector3.get(sender), Vector3.get((TileEntity) receiver)); - double ampsReceived = transferAmps - (transferAmps * transferAmps * targetConductor.getResistance() * distance) / voltage; - double voltsReceived = voltage - (transferAmps * targetConductor.getResistance() * distance); + 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)); } @@ -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 - * receiver accounting all current electricity + * Gets the actual watt request of an electric receiver accounting all current electricity * packets qued up for it. * * @return - The amount of watts requested. @@ -254,11 +257,9 @@ public class ElectricityManager } /** - * Checks if the current connection line needs - * electricity + * Checks if the current connection line needs electricity * - * @return - The amount of joules this - * connection line needs + * @return - The amount of joules this connection line needs */ public double getElectricityRequired(ElectricityNetwork network) { @@ -323,8 +324,7 @@ public class ElectricityManager } /** - * This function is called to refresh all - * conductors in the world. + * This function is called to refresh all conductors in the world. */ public void refreshConductors() { @@ -345,12 +345,13 @@ public class ElectricityManager public void onTick(EnumSet type, Object... tickData) { + if (ElectricityManagerTicker.inGameTicks % 40 == 0) + { + this.refreshConductors(); + } + if (type.contains(TickType.WORLD) && !type.contains(TickType.WORLDLOAD)) { - if (ElectricityManagerTicker.inGameTicks % 40 == 0) - { - this.refreshConductors(); - } try { diff --git a/src/common/universalelectricity/core/electricity/ElectricityNetwork.java b/src/common/universalelectricity/core/electricity/ElectricityNetwork.java index 2d561cea..b69672f5 100644 --- a/src/common/universalelectricity/core/electricity/ElectricityNetwork.java +++ b/src/common/universalelectricity/core/electricity/ElectricityNetwork.java @@ -29,8 +29,7 @@ public class ElectricityNetwork } /** - * Get only the electric units that can - * receive electricity from the given side. + * Get only the electric units that can receive electricity from the given side. */ public List getConnectedReceivers() { @@ -110,8 +109,7 @@ public class ElectricityNetwork } /** - * This function is called to refresh all - * conductors in this network + * This function is called to refresh all conductors in this network */ public void refreshConductors() { diff --git a/src/common/universalelectricity/core/electricity/ElectricityTransferData.java b/src/common/universalelectricity/core/electricity/ElectricityTransferData.java index 7e657ac1..332765c3 100644 --- a/src/common/universalelectricity/core/electricity/ElectricityTransferData.java +++ b/src/common/universalelectricity/core/electricity/ElectricityTransferData.java @@ -1,12 +1,11 @@ package universalelectricity.core.electricity; -import net.minecraft.src.TileEntity; import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.implement.IElectricityReceiver; public class ElectricityTransferData { - public TileEntity sender; + public Object sender; public IElectricityReceiver receiver; public ElectricityNetwork network; public double amps; @@ -15,20 +14,17 @@ public class ElectricityTransferData /** * @param sender - * - Tile that's sending - * electricity. + * - Tile that's sending electricity. * @param receiver - * - Receiver that's receiving - * electricity + * - Receiver that's receiving electricity * @param conductor - * - Conductor that is conducting - * the electricity + * - Conductor that is conducting the electricity * @param side * - * @param amps * @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.receiver = receiver; diff --git a/src/common/universalelectricity/core/implement/IConductor.java b/src/common/universalelectricity/core/implement/IConductor.java index 18a5c344..f74c16f6 100644 --- a/src/common/universalelectricity/core/implement/IConductor.java +++ b/src/common/universalelectricity/core/implement/IConductor.java @@ -6,8 +6,7 @@ import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.electricity.ElectricityNetwork; /** - * Must be applied to all tile entities that are - * conductors. + * Must be applied to all tile entities that are conductors. * * @author Calclavia * @@ -15,63 +14,54 @@ import universalelectricity.core.electricity.ElectricityNetwork; public interface IConductor extends IConnector { /** - * The electrical network this conductor is - * on. + * The electrical network this conductor is on. */ public ElectricityNetwork getNetwork(); public void setNetwork(ElectricityNetwork network); /** - * The UE tile entities that this conductor is - * connected to. + * The UE tile entities that this conductor is connected to. * * @return */ public TileEntity[] getConnectedBlocks(); /** - * Gets the resistance of the conductor. Used - * to calculate energy loss. A higher - * resistance means a higher energy loss. + * Gets the resistance of the conductor. Used to calculate energy loss. A higher resistance + * means a higher energy loss. * * @return The amount of Ohm's of resistance. */ public double getResistance(); /** - * The maximum amount of amps this conductor - * can handle before melting down. This is - * calculating PER TICK! + * The maximum amount of amps this conductor can handle before melting down. This is calculating + * PER TICK! * * @return The amount of amps in volts */ public double getMaxAmps(); /** - * Called when the electricity passing through - * exceeds the maximum voltage. + * Called when the electricity passing through exceeds the maximum voltage. */ public void onOverCharge(); /** - * Resets the conductor and recalculate - * connection IDs again + * Resets the conductor and recalculate connection IDs again */ public void reset(); public World getWorld(); /** - * Adds a connection between this conductor - * and a UE unit + * Adds a connection between this conductor and a UE unit * * @param tileEntity - * - Must be either a producer, - * consumer or a conductor + * - Must be either a producer, consumer or a conductor * @param side - * - side in which the connection - * is coming from + * - side in which the connection is coming from */ public void updateConnection(TileEntity tileEntity, ForgeDirection side); diff --git a/src/common/universalelectricity/core/implement/IConnector.java b/src/common/universalelectricity/core/implement/IConnector.java index 04482e09..882c9ae3 100644 --- a/src/common/universalelectricity/core/implement/IConnector.java +++ b/src/common/universalelectricity/core/implement/IConnector.java @@ -3,8 +3,7 @@ package universalelectricity.core.implement; import net.minecraftforge.common.ForgeDirection; /** - * Applied to a TileEntity that can connect to UE - * wires. + * Applied to a TileEntity that can connect to UE wires. * * @author Calclavia * @@ -12,12 +11,10 @@ import net.minecraftforge.common.ForgeDirection; public interface IConnector { /** - * Can this TileEntity visually connect to a - * wire on this specific side? + * Can this TileEntity visually connect to a wire on this specific side? * * @param side - * - The side in which the - * connection is coming from. + * - The side in which the connection is coming from. * @return - True if so. */ public boolean canConnect(ForgeDirection side); diff --git a/src/common/universalelectricity/core/implement/IDisableable.java b/src/common/universalelectricity/core/implement/IDisableable.java index dcd28964..41af02bd 100644 --- a/src/common/universalelectricity/core/implement/IDisableable.java +++ b/src/common/universalelectricity/core/implement/IDisableable.java @@ -1,9 +1,8 @@ package universalelectricity.core.implement; /** - * This class should be applied to all tile - * entities (mainly machines) that can be disabled - * (by things like EMP, short circuit etc.). + * This class should be applied to all tile entities (mainly machines) that can be disabled (by + * things like EMP, short circuit etc.). * * @author Calclavia * @@ -11,21 +10,17 @@ package universalelectricity.core.implement; public interface IDisableable { /** - * This is called when the tile entity is to - * be disabled. + * This is called when the tile entity is to be disabled. * * @param duration - * - The duration of the disable in - * ticks. + * - The duration of the disable in ticks. */ public void onDisable(int duration); /** - * Called to see if this tile entity is - * disabled. + * Called to see if this tile entity is disabled. * - * @return True if the tile entity is - * disabled. + * @return True if the tile entity is disabled. */ public boolean isDisabled(); } diff --git a/src/common/universalelectricity/core/implement/IElectricityProducer.java b/src/common/universalelectricity/core/implement/IElectricityProducer.java index 3e55cef3..bae82f9d 100644 --- a/src/common/universalelectricity/core/implement/IElectricityProducer.java +++ b/src/common/universalelectricity/core/implement/IElectricityProducer.java @@ -1,10 +1,8 @@ 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. + * 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 */ diff --git a/src/common/universalelectricity/core/implement/IElectricityReceiver.java b/src/common/universalelectricity/core/implement/IElectricityReceiver.java index e481c278..52a77d5e 100644 --- a/src/common/universalelectricity/core/implement/IElectricityReceiver.java +++ b/src/common/universalelectricity/core/implement/IElectricityReceiver.java @@ -1,12 +1,10 @@ package universalelectricity.core.implement; -import net.minecraft.src.TileEntity; import net.minecraftforge.common.ForgeDirection; /** - * The IElectricityReceiver interface is an - * interface that must be applied to all tile - * entities that can receive electricity. + * The IElectricityReceiver interface is an interface that must be applied to all TileEntities or + * Entities that can receive electricity. * * @author Calclavia * @@ -16,32 +14,27 @@ 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. + * - 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. + * - 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. + * - The side of the block in which 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 - * need this tick? Recommended for you to - * return the max electricity storage of this - * machine (if there is one). + * 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? + * Can this unit receive electricity from this specific side? */ public boolean canReceiveFromSide(ForgeDirection side); } \ No newline at end of file diff --git a/src/common/universalelectricity/core/implement/IItemElectric.java b/src/common/universalelectricity/core/implement/IItemElectric.java index 9eeab06c..e8ac29a5 100644 --- a/src/common/universalelectricity/core/implement/IItemElectric.java +++ b/src/common/universalelectricity/core/implement/IItemElectric.java @@ -10,25 +10,21 @@ public interface IItemElectric extends IJouleStorage, IVoltage public double onReceive(double amps, double voltage, ItemStack itemStack); /** - * Called when something requests electricity - * from this item. + * Called when something requests electricity from this item. * * @return - The amount of given joules */ public double onUse(double joulesNeeded, ItemStack itemStack); /** - * @return Returns true or false if this - * consumer can receive electricity at - * this given tick or moment. + * @return Returns true or false if this consumer can receive electricity at this given tick or + * moment. */ public boolean canReceiveElectricity(); /** - * Can this item give out electricity when - * placed in an tile entity? Electric items - * like batteries should be able to produce - * electricity (if they are rechargeable). + * Can this item give out electricity when placed in an tile entity? Electric items like + * batteries should be able to produce electricity (if they are rechargeable). * * @return - True or False. */ diff --git a/src/common/universalelectricity/core/implement/IJouleStorage.java b/src/common/universalelectricity/core/implement/IJouleStorage.java index 182d6030..f2932a5c 100644 --- a/src/common/universalelectricity/core/implement/IJouleStorage.java +++ b/src/common/universalelectricity/core/implement/IJouleStorage.java @@ -1,28 +1,24 @@ package universalelectricity.core.implement; /** - * This interface is to be applied to all tile - * entities which stores energy within them. + * This interface is to be applied to all tile entities which stores energy within them. * * @author Calclavia */ public interface IJouleStorage { /** - * Returns the amount of joules this unit has - * stored. + * Returns the amount of joules this unit has stored. */ public double getJoules(Object... data); /** - * Sets the amount of joules this unit has - * stored. + * Sets the amount of joules this unit has stored. */ - public void setJoules(double wattHours, Object... data); + public void setJoules(double joules, Object... data); /** - * Gets the maximum amount of joules this unit - * can store. + * Gets the maximum amount of joules this unit can store. */ public double getMaxJoules(Object... data); } diff --git a/src/common/universalelectricity/core/implement/IVoltage.java b/src/common/universalelectricity/core/implement/IVoltage.java index 3e90673c..f178e06a 100644 --- a/src/common/universalelectricity/core/implement/IVoltage.java +++ b/src/common/universalelectricity/core/implement/IVoltage.java @@ -11,8 +11,7 @@ public interface IVoltage /** * Gets the voltage of this object. * - * @return The amount of volts. E.g 120v or - * 240v + * @return The amount of volts. E.g 120v or 240v */ public double getVoltage(); } diff --git a/src/common/universalelectricity/core/vector/Vector2.java b/src/common/universalelectricity/core/vector/Vector2.java index cc0b76e9..752d9f23 100644 --- a/src/common/universalelectricity/core/vector/Vector2.java +++ b/src/common/universalelectricity/core/vector/Vector2.java @@ -3,11 +3,9 @@ package universalelectricity.core.vector; import net.minecraft.src.MathHelper; /** - * Vector2 Class is used for defining objects in a - * 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 stored in one class. Vector3.x, Vector3.y. + * Vector2 Class is used for defining objects in a 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 + * stored in one class. Vector3.x, Vector3.y. * * @author Calclavia */ @@ -46,8 +44,7 @@ public class Vector2 implements Cloneable } /** - * Makes a new copy of this Vector. Prevents - * variable referencing problems. + * Makes a new copy of this Vector. Prevents variable referencing problems. */ @Override public Vector2 clone() @@ -80,7 +77,7 @@ public class Vector2 implements Cloneable this.x += par1; this.y += par1; } - + public void substract(Vector2 par1) { this.x -= par1.x; @@ -106,6 +103,6 @@ public class Vector2 implements Cloneable @Override public String toString() { - return "Vector2: " + this.x + "," + this.y; + return "Vector2 [" + this.x + "," + this.y + "]"; } } \ No newline at end of file diff --git a/src/common/universalelectricity/core/vector/Vector3.java b/src/common/universalelectricity/core/vector/Vector3.java index 2b25fea9..d4890fdc 100644 --- a/src/common/universalelectricity/core/vector/Vector3.java +++ b/src/common/universalelectricity/core/vector/Vector3.java @@ -1,5 +1,8 @@ package universalelectricity.core.vector; +import java.util.List; + +import net.minecraft.src.AxisAlignedBB; import net.minecraft.src.ChunkCoordinates; import net.minecraft.src.Entity; import net.minecraft.src.IBlockAccess; @@ -13,12 +16,9 @@ import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.implement.IConnector; /** - * Vector3 Class is used for defining objects in a - * 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 are stored in one class. Vector3.x, - * Vector3.y, Vector3.z. + * Vector3 Class is used for defining objects in a 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 + * are stored in one class. Vector3.x, Vector3.y, Vector3.z. * * @author Calclavia */ @@ -65,8 +65,7 @@ public class Vector3 extends Vector2 implements Cloneable } /** - * Makes a new copy of this Vector. Prevents - * variable referencing problems. + * Makes a new copy of this Vector. Prevents variable referencing problems. */ @Override public Vector3 clone() @@ -139,8 +138,7 @@ public class Vector3 extends Vector2 implements Cloneable } /** - * Converts this Vector3 into a Vector2 by - * dropping the Y axis. + * Converts this Vector3 into a Vector2 by dropping the Y axis. */ public Vector2 toVector2() { @@ -148,8 +146,7 @@ public class Vector3 extends Vector2 implements Cloneable } /** - * Converts this vector three into a Minecraft - * Vec3 object + * Converts this vector three into a Minecraft Vec3 object */ public Vec3 toVec3() { @@ -157,8 +154,7 @@ public class Vector3 extends Vector2 implements Cloneable } /** - * Compares two vectors and see if they are - * equal. True if so. + * Compares two vectors and see if they are equal. True if so. */ public boolean isEqual(Vector3 vector3) { @@ -223,14 +219,28 @@ public class Vector3 extends Vector2 implements Cloneable 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) @@ -246,11 +256,9 @@ public class Vector3 extends Vector2 implements Cloneable * Saves this Vector3 to disk * * @param prefix - * - The prefix of this save. Use - * some unique string. + * - The prefix of this save. Use some unique string. * @param par1NBTTagCompound - * - The NBT compound object to - * save the data in + * - The NBT compound object to save the data in */ 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)); } - /** - * Gets a position relative to another - * position's side + * Gets all entities inside of this position in block space. + */ + public List getEntitiesWithin(World worldObj, Class par1Class) + { + return (List) 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 * - The position * @param side * - The side. 0-5 - * @return The position relative to the - * original position's side + * @return The position relative to the original position's side */ - public void modifyPositionFromSide(ForgeDirection side) + public void modifyPositionFromSide(ForgeDirection side, double amount) { switch (side.ordinal()) { case 0: - this.y -= 1; + this.y -= amount; break; case 1: - this.y += 1; + this.y += amount; break; case 2: - this.z -= 1; + this.z -= amount; break; case 3: - this.z += 1; + this.z += amount; break; case 4: - this.x -= 1; + this.x -= amount; break; case 5: - this.x += 1; + this.x += amount; break; } } + public void modifyPositionFromSide(ForgeDirection side) + { + this.modifyPositionFromSide(side, 1); + } + public static TileEntity getTileEntityFromSide(World world, Vector3 position, ForgeDirection side) { position.modifyPositionFromSide(side); @@ -315,8 +333,7 @@ public class Vector3 extends Vector2 implements Cloneable } /** - * Gets a connector unit based on the given - * side. + * Gets a connector unit based on the given 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 - * facing direction from the given side. The - * side numbers are compatible with the - * function - * "getBlockTextureFromSideAndMetadata". + * Finds the side of a block depending on it's facing direction from the given side. The side + * numbers are compatible with the function "getBlockTextureFromSideAndMetadata". * - * Bottom: 0; Top: 1; Back: 2; Front: 3; Left: - * 4; Right: 5; + * 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. + * - 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. + * - The side you are trying to find. A number between 0 and 5. + * @return The side relative to the facing direction. */ public static ForgeDirection getOrientationFromSide(ForgeDirection front, ForgeDirection side) @@ -447,10 +456,10 @@ public class Vector3 extends Vector2 implements Cloneable return ForgeDirection.UNKNOWN; } - + @Override public String toString() { - return "Vector3: " + this.x + "," + this.y + "," + this.z; + return "Vector3 [" + this.x + "," + this.y + "," + this.z + "]"; } } \ No newline at end of file diff --git a/src/common/universalelectricity/prefab/BlockConductor.java b/src/common/universalelectricity/prefab/BlockConductor.java new file mode 100644 index 00000000..3512aa62 --- /dev/null +++ b/src/common/universalelectricity/prefab/BlockConductor.java @@ -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); + } +} diff --git a/src/common/universalelectricity/prefab/BlockMachine.java b/src/common/universalelectricity/prefab/BlockMachine.java index ce276eb5..24a6c0a1 100644 --- a/src/common/universalelectricity/prefab/BlockMachine.java +++ b/src/common/universalelectricity/prefab/BlockMachine.java @@ -13,14 +13,12 @@ import net.minecraft.src.NBTTagCompound; import net.minecraft.src.TileEntity; import net.minecraft.src.World; import universalelectricity.core.implement.IItemElectric; -import buildcraft.api.tools.IToolWrench; +import universalelectricity.prefab.implement.IWrench; /** - * A block you may extend from to create your - * machine blocks! You do not have to extend from - * this block if you do not want to. It's optional - * but it comes with some useful functions that - * will make coding easier for you. + * A block you may extend from to create your machine blocks! You do not have to extend from this + * block if you do not want to. It's optional but it comes with some useful functions that will make + * coding easier for you. */ public abstract class BlockMachine extends BlockContainer { @@ -44,8 +42,7 @@ public abstract class BlockMachine extends BlockContainer } /** - * Returns the quantity of items to drop on - * block destruction. + * Returns the quantity of items to drop on block destruction. */ @Override public int quantityDropped(Random par1Random) @@ -54,8 +51,7 @@ public abstract class BlockMachine extends BlockContainer } /** - * Returns the ID of the items to drop on - * destruction. + * Returns the ID of the items to drop on destruction. */ @Override 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 - * 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) + * 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 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); /** - * Check if the player is holding a wrench - * or an electric item. If so, do not open - * the GUI. + * 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 IToolWrench) + if (par5EntityPlayer.inventory.getCurrentItem().getItem() instanceof IWrench) { 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()) { @@ -115,8 +105,7 @@ public abstract class BlockMachine extends BlockContainer } /** - * Called when the machine is right clicked by - * the player + * Called when the machine is right clicked by the player * * @return True if something happens */ @@ -126,8 +115,7 @@ public abstract class BlockMachine extends BlockContainer } /** - * Called when the machine is right clicked by - * the player while sneaking (shift clicking) + * Called when the machine is right clicked by the player while sneaking (shift clicking) * * @return True if something happens */ @@ -137,8 +125,7 @@ public abstract class BlockMachine extends BlockContainer } /** - * Called when a player uses an electric item - * on the machine + * Called when a player uses an electric item on the machine * * @return True if some happens */ @@ -148,8 +135,7 @@ public abstract class BlockMachine extends BlockContainer } /** - * Called when a player uses a wrench on the - * machine + * Called when a player uses a wrench on the machine * * @return True if some happens */ @@ -159,8 +145,7 @@ public abstract class BlockMachine extends BlockContainer } /** - * Called when a player uses a wrench on the - * machine while sneaking + * Called when a player uses a wrench on the machine while sneaking * * @return True if some happens */ @@ -170,10 +155,8 @@ public abstract class BlockMachine extends BlockContainer } /** - * Returns the TileEntity used by this block. - * You should use the metadata sensitive - * version of this to get the maximum - * optimization! + * Returns the TileEntity used by this block. You should use the metadata sensitive version of + * this to get the maximum optimization! */ @Override public TileEntity createNewTileEntity(World var1) @@ -182,9 +165,8 @@ public abstract class BlockMachine extends BlockContainer } /** - * Override this if you don't need it. This - * will eject all items out of this machine if - * it has an inventory + * Override this if you don't need it. This will eject all items out of this machine if it has + * an inventory */ @Override public void breakBlock(World par1World, int x, int y, int z, int par5, int par6) diff --git a/src/common/universalelectricity/prefab/ItemElectric.java b/src/common/universalelectricity/prefab/ItemElectric.java new file mode 100644 index 00000000..a88cbc57 --- /dev/null +++ b/src/common/universalelectricity/prefab/ItemElectric.java @@ -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); + } +} diff --git a/src/common/universalelectricity/prefab/RecipeHelper.java b/src/common/universalelectricity/prefab/RecipeHelper.java new file mode 100644 index 00000000..9fbcedd9 --- /dev/null +++ b/src/common/universalelectricity/prefab/RecipeHelper.java @@ -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 getRecipesByOutput(ItemStack output) + { + List list = new ArrayList(); + + 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); + } +} diff --git a/src/common/universalelectricity/prefab/SlotElectricItem.java b/src/common/universalelectricity/prefab/SlotElectricItem.java new file mode 100644 index 00000000..45956e2f --- /dev/null +++ b/src/common/universalelectricity/prefab/SlotElectricItem.java @@ -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; + } +} diff --git a/src/common/universalelectricity/prefab/UEDamageSource.java b/src/common/universalelectricity/prefab/UEDamageSource.java new file mode 100644 index 00000000..90ad5500 --- /dev/null +++ b/src/common/universalelectricity/prefab/UEDamageSource.java @@ -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 damageSources = new ArrayList(); + + /** + * 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); + } +} diff --git a/src/common/universalelectricity/prefab/implement/IRedstoneProvider.java b/src/common/universalelectricity/prefab/implement/IRedstoneProvider.java index b839f1f5..3b03e9b4 100644 --- a/src/common/universalelectricity/prefab/implement/IRedstoneProvider.java +++ b/src/common/universalelectricity/prefab/implement/IRedstoneProvider.java @@ -3,8 +3,7 @@ package universalelectricity.prefab.implement; import net.minecraftforge.common.ForgeDirection; /** - * This should be applied on tile entities that - * can provide redstone power + * This should be applied on tile entities that can provide redstone power * * @author Calclavia * diff --git a/src/common/universalelectricity/prefab/implement/IRedstoneReceptor.java b/src/common/universalelectricity/prefab/implement/IRedstoneReceptor.java index ab1105b6..0ad177a1 100644 --- a/src/common/universalelectricity/prefab/implement/IRedstoneReceptor.java +++ b/src/common/universalelectricity/prefab/implement/IRedstoneReceptor.java @@ -1,8 +1,7 @@ package universalelectricity.prefab.implement; /** - * This interface should be applied onto all tile - * entities that needs to receive redstone power. + * This interface should be applied onto all tile entities that needs to receive redstone power. * Look at TileEntityBatteryBox for reference. * * @author Calclavia @@ -11,14 +10,12 @@ package universalelectricity.prefab.implement; public interface IRedstoneReceptor { /** - * Called when the block is powered on by - * redstone + * Called when the block is powered on by redstone */ public void onPowerOn(); /** - * Called when the block is powered off by - * redstone + * Called when the block is powered off by redstone */ public void onPowerOff(); } diff --git a/src/common/universalelectricity/prefab/implement/IRotatable.java b/src/common/universalelectricity/prefab/implement/IRotatable.java index e8b2bbc8..77228a53 100644 --- a/src/common/universalelectricity/prefab/implement/IRotatable.java +++ b/src/common/universalelectricity/prefab/implement/IRotatable.java @@ -3,10 +3,8 @@ package universalelectricity.prefab.implement; import net.minecraftforge.common.ForgeDirection; /** - * This interface should be applied onto all tile - * 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 + * This interface should be applied onto all tile 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 * easier for you to code. * * @author Calclavia @@ -16,26 +14,20 @@ import net.minecraftforge.common.ForgeDirection; public interface IRotatable { /** - * Gets the facing direction of the tile - * entity. Always returns the front side of - * the tile entity. + * Gets the facing direction of the tile entity. Always returns the front side of the tile + * entity. * - * @return The facing side from 0-5 The full - * list of which side the number - * represents is in the + * @return The facing side from 0-5 The full list of which side the number represents is in the * UniversalElectricity class. */ public ForgeDirection getDirection(); /** - * Sets the facing direction of the tile - * entity. + * 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. + * - A direction from 0-5. The full list of which side the number represents is in + * the UniversalElectricity class. */ public void setDirection(ForgeDirection facingDirection); } diff --git a/src/common/universalelectricity/prefab/implement/ITier.java b/src/common/universalelectricity/prefab/implement/ITier.java index a7ec663f..2cd0b60a 100644 --- a/src/common/universalelectricity/prefab/implement/ITier.java +++ b/src/common/universalelectricity/prefab/implement/ITier.java @@ -1,8 +1,7 @@ package universalelectricity.prefab.implement; /** - * This interface should be applied to all things - * that has a tier/level. + * This interface should be applied to all things that has a tier/level. * * @author Calclavia * diff --git a/src/common/universalelectricity/prefab/implement/IWrench.java b/src/common/universalelectricity/prefab/implement/IWrench.java new file mode 100644 index 00000000..ce3cebf3 --- /dev/null +++ b/src/common/universalelectricity/prefab/implement/IWrench.java @@ -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); +} diff --git a/src/common/universalelectricity/prefab/modifier/IModifier.java b/src/common/universalelectricity/prefab/modifier/IModifier.java new file mode 100644 index 00000000..e95cfd96 --- /dev/null +++ b/src/common/universalelectricity/prefab/modifier/IModifier.java @@ -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); +} diff --git a/src/common/universalelectricity/prefab/modifier/SlotModifier.java b/src/common/universalelectricity/prefab/modifier/SlotModifier.java new file mode 100644 index 00000000..fab96f3b --- /dev/null +++ b/src/common/universalelectricity/prefab/modifier/SlotModifier.java @@ -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; + } +} diff --git a/src/common/universalelectricity/prefab/multiblock/BlockMulti.java b/src/common/universalelectricity/prefab/multiblock/BlockMulti.java index 1a97cec0..acc5be5f 100644 --- a/src/common/universalelectricity/prefab/multiblock/BlockMulti.java +++ b/src/common/universalelectricity/prefab/multiblock/BlockMulti.java @@ -36,12 +36,9 @@ public class BlockMulti extends BlockContainer } /** - * 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) + * Called when the block is right clicked by the player. This modified version detects electric + * items and wrench actions on your machine block. Do not override this function. Use + * machineActivated instead! (It does the same thing) */ @Override public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) @@ -51,8 +48,7 @@ public class BlockMulti extends BlockContainer } /** - * Returns the quantity of items to drop on - * block destruction. + * Returns the quantity of items to drop on block destruction. */ @Override public int quantityDropped(Random par1Random) diff --git a/src/common/universalelectricity/prefab/multiblock/IBlockActivate.java b/src/common/universalelectricity/prefab/multiblock/IBlockActivate.java index 0003fe93..bbac0a96 100644 --- a/src/common/universalelectricity/prefab/multiblock/IBlockActivate.java +++ b/src/common/universalelectricity/prefab/multiblock/IBlockActivate.java @@ -3,8 +3,7 @@ package universalelectricity.prefab.multiblock; import net.minecraft.src.EntityPlayer; /** - * A general interface to be implemented by - * anything that needs it. + * A general interface to be implemented by anything that needs it. * * @author Calclavia * diff --git a/src/common/universalelectricity/prefab/multiblock/IMultiBlock.java b/src/common/universalelectricity/prefab/multiblock/IMultiBlock.java index 9671cbe8..52d786ce 100644 --- a/src/common/universalelectricity/prefab/multiblock/IMultiBlock.java +++ b/src/common/universalelectricity/prefab/multiblock/IMultiBlock.java @@ -4,9 +4,8 @@ import net.minecraft.src.TileEntity; import universalelectricity.core.vector.Vector3; /** - * Interface to be applied to tile entity blocks - * that occupies more than one block space. Useful - * for large machines. + * Interface to be applied to tile entity blocks that occupies more than one block space. Useful for + * large machines. * * @author Calclavia * @@ -17,18 +16,15 @@ public interface IMultiBlock extends IBlockActivate * Called when this multiblock is created * * @param placedPosition - * - The position the block was - * placed at + * - The position the block was placed at */ public void onCreate(Vector3 placedPosition); /** - * Called when one of the multiblocks of this - * block is destroyed + * Called when one of the multiblocks of this block is destroyed * * @param callingBlock - * - The tile entity who called the - * onDestroy function + * - The tile entity who called the onDestroy function */ public void onDestroy(TileEntity callingBlock); } diff --git a/src/common/universalelectricity/prefab/multiblock/TileEntityMulti.java b/src/common/universalelectricity/prefab/multiblock/TileEntityMulti.java index 77901181..efe5152a 100644 --- a/src/common/universalelectricity/prefab/multiblock/TileEntityMulti.java +++ b/src/common/universalelectricity/prefab/multiblock/TileEntityMulti.java @@ -14,8 +14,7 @@ import universalelectricity.prefab.network.PacketManager; import com.google.common.io.ByteArrayDataInput; /** - * This is a multiblock to be used for blocks that - * are bigger than one block. + * This is a multiblock to be used for blocks that are bigger than one block. * * @author Calclavia * @@ -97,11 +96,9 @@ public class TileEntityMulti extends TileEntity implements IPacketReceiver } /** - * Determines if this TileEntity requires - * update calls. + * Determines if this TileEntity requires update calls. * - * @return True if you want updateEntity() to - * be called, false if not + * @return True if you want updateEntity() to be called, false if not */ public boolean canUpdate() { diff --git a/src/common/universalelectricity/prefab/network/ISimpleConnectionHandler.java b/src/common/universalelectricity/prefab/network/ISimpleConnectionHandler.java index b5072346..6a95dd78 100644 --- a/src/common/universalelectricity/prefab/network/ISimpleConnectionHandler.java +++ b/src/common/universalelectricity/prefab/network/ISimpleConnectionHandler.java @@ -5,9 +5,7 @@ import universalelectricity.prefab.network.ConnectionHandler.ConnectionType; public interface ISimpleConnectionHandler { /** - * Called when a player logs in. Use this to - * reset some tile entities variables if you - * need to. + * Called when a player logs in. Use this to reset some tile entities variables if you need to. * * @param player */ diff --git a/src/common/universalelectricity/prefab/network/PacketManager.java b/src/common/universalelectricity/prefab/network/PacketManager.java index acdb8cc5..5a9fb717 100644 --- a/src/common/universalelectricity/prefab/network/PacketManager.java +++ b/src/common/universalelectricity/prefab/network/PacketManager.java @@ -21,20 +21,13 @@ import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.common.network.Player; /** - * This class is used for sending and receiving - * packets between the server and the client. You - * can directly use this by registering this - * packet manager with NetworkMod. Example: + * This class is used for sending and receiving packets between the server and the client. You can + * directly use this by registering this packet manager with NetworkMod. Example: * - * @NetworkMod(channels = { "BasicComponents" }, - * clientSideRequired = true, - * serverSideRequired = - * false, packetHandler = - * PacketManager.class) + * @NetworkMod(channels = { "BasicComponents" }, clientSideRequired = true, serverSideRequired = + * false, packetHandler = PacketManager.class) * - * Check out - * {@link #BasicComponents} - * for better reference. + * Check out {@link #BasicComponents} for better reference. * * @author Calclavia */ @@ -60,7 +53,6 @@ public class PacketManager implements IPacketHandler, IPacketReceiver try { data.writeInt(id); - data = encodeDataStream(data, sendData); Packet250CustomPayload packet = new Packet250CustomPayload(); @@ -121,10 +113,8 @@ public class PacketManager implements IPacketHandler, IPacketReceiver } /** - * Sends packets to clients around a specific - * coordinate. A wrapper using Vector3. See - * {@PacketDispatcher} for - * detailed information. + * Sends packets to clients around a specific coordinate. A wrapper using Vector3. See + * {@PacketDispatcher} for detailed information. */ 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 - * server. + * Sends a packet to all the clients on this server. */ public static void sendPacketToClients(Packet packet, World worldObj) { diff --git a/src/common/universalelectricity/prefab/ore/OreGenBase.java b/src/common/universalelectricity/prefab/ore/OreGenBase.java new file mode 100644 index 00000000..ea9e7be0 --- /dev/null +++ b/src/common/universalelectricity/prefab/ore/OreGenBase.java @@ -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); +} diff --git a/src/common/universalelectricity/prefab/ore/OreGenReplace.java b/src/common/universalelectricity/prefab/ore/OreGenReplace.java new file mode 100644 index 00000000..979a4787 --- /dev/null +++ b/src/common/universalelectricity/prefab/ore/OreGenReplace.java @@ -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)); + } +} diff --git a/src/common/universalelectricity/prefab/ore/OreGenReplaceStone.java b/src/common/universalelectricity/prefab/ore/OreGenReplaceStone.java new file mode 100644 index 00000000..463fa2bc --- /dev/null +++ b/src/common/universalelectricity/prefab/ore/OreGenReplaceStone.java @@ -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); + } +} \ No newline at end of file diff --git a/src/common/universalelectricity/prefab/ore/OreGenerator.java b/src/common/universalelectricity/prefab/ore/OreGenerator.java new file mode 100644 index 00000000..68a1a1df --- /dev/null +++ b/src/common/universalelectricity/prefab/ore/OreGenerator.java @@ -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 ORES_TO_GENERATE = new ArrayList(); + + /** + * 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); + } + + } + } +} diff --git a/src/common/universalelectricity/prefab/potion/CustomPotion.java b/src/common/universalelectricity/prefab/potion/CustomPotion.java new file mode 100644 index 00000000..fc13deb9 --- /dev/null +++ b/src/common/universalelectricity/prefab/potion/CustomPotion.java @@ -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; + } +} diff --git a/src/common/universalelectricity/prefab/potion/CustomPotionEffect.java b/src/common/universalelectricity/prefab/potion/CustomPotionEffect.java new file mode 100644 index 00000000..fedd88cc --- /dev/null +++ b/src/common/universalelectricity/prefab/potion/CustomPotionEffect.java @@ -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 curativeItems) + { + super(potionID, duration, amplifier); + + if (curativeItems == null) + { + this.setCurativeItems(new ArrayList()); + } + else + { + this.setCurativeItems(curativeItems); + } + } +} diff --git a/src/common/universalelectricity/prefab/tile/TileEntityAdvanced.java b/src/common/universalelectricity/prefab/tile/TileEntityAdvanced.java index f36eeb0a..c005fa53 100644 --- a/src/common/universalelectricity/prefab/tile/TileEntityAdvanced.java +++ b/src/common/universalelectricity/prefab/tile/TileEntityAdvanced.java @@ -4,8 +4,7 @@ import net.minecraft.src.Block; import net.minecraft.src.TileEntity; /** - * A TileEntity with some pre-added - * functionalities. + * A TileEntity with some pre-added functionalities. * * @author Calclavia * diff --git a/src/common/universalelectricity/prefab/tile/TileEntityConductor.java b/src/common/universalelectricity/prefab/tile/TileEntityConductor.java index 3aacb1c1..d73833cf 100644 --- a/src/common/universalelectricity/prefab/tile/TileEntityConductor.java +++ b/src/common/universalelectricity/prefab/tile/TileEntityConductor.java @@ -16,8 +16,7 @@ import universalelectricity.prefab.network.IPacketReceiver; import com.google.common.io.ByteArrayDataInput; /** - * This tile entity pre-fabricated for all - * conductors. + * This tile entity pre-fabricated for all conductors. * * @author Calclavia * @@ -27,8 +26,7 @@ public abstract class TileEntityConductor extends TileEntityAdvanced implements private ElectricityNetwork network; /** - * Stores information on the blocks that this - * conductor is connected to + * Stores information on the blocks that this conductor is connected to */ public TileEntity[] connectedBlocks = { null, null, null, null, null, null }; @@ -122,11 +120,9 @@ public abstract class TileEntityConductor extends TileEntityAdvanced implements } /** - * Determines if this TileEntity requires - * update calls. + * Determines if this TileEntity requires update calls. * - * @return True if you want updateEntity() to - * be called, false if not + * @return True if you want updateEntity() to be called, false if not */ @Override public boolean canUpdate() diff --git a/src/common/universalelectricity/prefab/tile/TileEntityDisableable.java b/src/common/universalelectricity/prefab/tile/TileEntityDisableable.java index 0b6deba1..ecf58e2d 100644 --- a/src/common/universalelectricity/prefab/tile/TileEntityDisableable.java +++ b/src/common/universalelectricity/prefab/tile/TileEntityDisableable.java @@ -3,9 +3,7 @@ package universalelectricity.prefab.tile; import universalelectricity.core.implement.IDisableable; /** - * An easier way to implement the methods from - * IElectricityDisableable with default values - * set. + * An easier way to implement the methods from IElectricityDisableable with default values set. * * @author Calclavia */ @@ -27,8 +25,7 @@ public abstract class TileEntityDisableable extends TileEntityAdvanced implement } /** - * Called every tick while this tile entity is - * disabled. + * Called every tick while this tile entity is disabled. */ protected void whileDisable() { diff --git a/src/common/universalelectricity/prefab/tile/TileEntityElectricityReceiver.java b/src/common/universalelectricity/prefab/tile/TileEntityElectricityReceiver.java index d8722544..187fc5af 100644 --- a/src/common/universalelectricity/prefab/tile/TileEntityElectricityReceiver.java +++ b/src/common/universalelectricity/prefab/tile/TileEntityElectricityReceiver.java @@ -4,8 +4,7 @@ import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.implement.IElectricityReceiver; /** - * An easier way to implement the methods from - * IElectricityReceiver with default values set. + * An easier way to implement the methods from IElectricityReceiver with default values set. * * @author Calclavia */ diff --git a/src/common/universalelectricity/core/vector/Region2.java b/src/common/universalelectricity/prefab/vector/Region2.java similarity index 73% rename from src/common/universalelectricity/core/vector/Region2.java rename to src/common/universalelectricity/prefab/vector/Region2.java index d38d8875..6d52a746 100644 --- a/src/common/universalelectricity/core/vector/Region2.java +++ b/src/common/universalelectricity/prefab/vector/Region2.java @@ -1,4 +1,6 @@ -package universalelectricity.core.vector; +package universalelectricity.prefab.vector; + +import universalelectricity.core.vector.Vector2; public class Region2 { @@ -17,8 +19,7 @@ public class Region2 } /** - * Checks if a point is located inside a - * region + * Checks if a point is located inside a region */ public boolean isIn(Vector2 point) { @@ -26,8 +27,7 @@ public class Region2 } /** - * Returns whether the given region intersects - * with this one. + * Returns whether the given region intersects with this one. */ public boolean isIn(Region2 region) { diff --git a/src/common/universalelectricity/core/vector/Region3.java b/src/common/universalelectricity/prefab/vector/Region3.java similarity index 93% rename from src/common/universalelectricity/core/vector/Region3.java rename to src/common/universalelectricity/prefab/vector/Region3.java index 81515425..8ee10851 100644 --- a/src/common/universalelectricity/core/vector/Region3.java +++ b/src/common/universalelectricity/prefab/vector/Region3.java @@ -1,4 +1,4 @@ -package universalelectricity.core.vector; +package universalelectricity.prefab.vector; import java.util.ArrayList; import java.util.List; @@ -6,6 +6,7 @@ import java.util.List; import net.minecraft.src.AxisAlignedBB; import net.minecraft.src.Entity; import net.minecraft.src.World; +import universalelectricity.core.vector.Vector3; /** * A cubical region class. @@ -44,8 +45,7 @@ public class Region3 } /** - * Checks if a point is located inside a - * region + * Checks if a point is located inside a region */ public boolean isIn(Vector3 point) { @@ -53,8 +53,7 @@ public class Region3 } /** - * Returns whether the given region intersects - * with this one. + * Returns whether the given region intersects with this one. */ public boolean isIn(Region3 region) {