Update every applicable API, remove some unused imports

This commit is contained in:
Ben Spiers 2013-09-30 22:37:16 +01:00
parent 9c0b2a56b5
commit e05479a909
63 changed files with 1058 additions and 520 deletions

View file

@ -23,7 +23,7 @@ public final class PowerHandler {
case STORAGE:
return true;
default:
return false;
return false;
}
}
@ -33,11 +33,16 @@ public final class PowerHandler {
case STORAGE:
return true;
default:
return false;
return false;
}
}
}
/**
* Extend this class to create custom Perdition algorithms (its not final).
*
* NOTE: It is not possible to create a Zero perdition algorithm.
*/
public static class PerditionCalculator {
public static final float DEFAULT_POWERLOSS = 1F;
@ -48,6 +53,11 @@ public final class PowerHandler {
powerLoss = DEFAULT_POWERLOSS;
}
/**
* Simple constructor for simple Perdition per tick.
*
* @param powerLoss power loss per tick
*/
public PerditionCalculator(float powerLoss) {
if (powerLoss < MIN_POWERLOSS) {
powerLoss = MIN_POWERLOSS;
@ -72,6 +82,17 @@ public final class PowerHandler {
}
return current;
}
/**
* Taxes a flat rate on all incoming power.
*
* Defaults to 0% tax rate.
*
* @return percent of input to tax
*/
public float getTaxPercent() {
return 0;
}
}
public static final PerditionCalculator DEFAULT_PERDITION = new PerditionCalculator();
private float minEnergyReceived;
@ -337,6 +358,8 @@ public final class PowerHandler {
}
updateSources(from);
used -= used * getPerdition().getTaxPercent();
used = addEnergy(used);

View file

@ -6,6 +6,7 @@
package dan200.computer.api;
import java.lang.reflect.Method;
import net.minecraft.world.World;
/**
* The static entry point to the ComputerCraft API.
@ -14,6 +15,86 @@ import java.lang.reflect.Method;
*/
public class ComputerCraftAPI
{
/**
* Creates a numbered directory in a subfolder of the save directory for a given world, and returns that number.<br>
* Use in conjuction with createSaveDirMount() to create a unique place for your peripherals or media items to store files.<br>
* @param world The world for which the save dir should be created. This should be the serverside world object.
* @param parentSubPath The folder path within the save directory where the new directory should be created. eg: "computer/disk"
* @return The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason.<br>
* eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now available for writing.
* @see #createSaveDirMount(World, String)
*/
public static int createUniqueNumberedSaveDir( World world, String parentSubPath )
{
findCC();
if( computerCraft_createUniqueNumberedSaveDir != null )
{
try {
return ((Integer)computerCraft_createUniqueNumberedSaveDir.invoke( null, world, parentSubPath )).intValue();
} catch (Exception e){
// It failed
}
}
return -1;
}
/**
* Creates a file system mount that maps to a subfolder of the save directory for a given world, and returns it.<br>
* Use in conjuction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the
* users save directory onto a computers file system.<br>
* @param world The world for which the save dir can be found. This should be the serverside world object.
* @param subPath The folder path within the save directory that the mount should map to. eg: "computer/disk/42".<br>
* Use createUniqueNumberedSaveDir() to create a new numbered folder to use.
* @param capacity The ammount of data that can be stored in the directory before it fills up, in bytes.
* @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable()
* to mount this on a Computers' file system.
* @see #createUniqueNumberedSaveDir(World, String)
* @see IComputerAccess#mount(String, IMount)
* @see IComputerAccess#mountWritable(String, IWritableMount)
* @see IMount
* @see IMountWritable
*/
public static IWritableMount createSaveDirMount( World world, String subPath, long capacity )
{
findCC();
if( computerCraft_createSaveDirMount != null )
{
try {
return (IWritableMount)computerCraft_createSaveDirMount.invoke( null, world, subPath, capacity );
} catch (Exception e){
// It failed
}
}
return null;
}
/**
* Creates a file system mount to a resource folder, and returns it.<br>
* Use in conjuction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a resource folder onto a computers file system.<br>
* The files in this mount will be a combination of files in the specified mod jar, and resource packs that contain resources with the same domain and path.<br>
* @param class A class in whose jar to look first for the resources to mount. Using your main mod class is recommended. eg: MyMod.class
* @param domain The domain under which to look for resources. eg: "mymod"
* @param subPath The domain under which to look for resources. eg: "mymod/lua/myfiles"
* @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable()
* to mount this on a Computers' file system.
* @see IComputerAccess#mount(String, IMount)
* @see IComputerAccess#mountWritable(String, IMountWritable)
* @see IMount
*/
public static IMount createResourceMount( Class modClass, String domain, String subPath )
{
findCC();
if( computerCraft_createResourceMount != null )
{
try {
return (IMount)computerCraft_createResourceMount.invoke( null, modClass, domain, subPath );
} catch (Exception e){
// It failed
}
}
return null;
}
/**
* Registers a peripheral handler for a TileEntity that you do not have access to. Only
* use this if you want to expose IPeripheral on a TileEntity from another mod. For your own
@ -43,11 +124,20 @@ public class ComputerCraftAPI
if( !ccSearched ) {
try {
computerCraft = Class.forName( "dan200.ComputerCraft" );
computerCraft_createUniqueNumberedSaveDir = findCCMethod( "createUniqueNumberedSaveDir", new Class[] {
World.class, String.class
} );
computerCraft_createSaveDirMount = findCCMethod( "createSaveDirMount", new Class[] {
World.class, String.class, Long.TYPE
} );
computerCraft_createResourceMount = findCCMethod( "createResourceMount", new Class[] {
Class.class, String.class, String.class
} );
computerCraft_registerExternalPeripheral = findCCMethod( "registerExternalPeripheral", new Class[] {
Class.class, IPeripheralHandler.class
} );
} catch( Exception e ) {
System.out.println("ComputerCraftAPI: ComputerCraft not found.");
net.minecraft.server.MinecraftServer.getServer().logInfo( "ComputerCraftAPI: ComputerCraft not found." );
} finally {
ccSearched = true;
}
@ -58,14 +148,16 @@ public class ComputerCraftAPI
{
try {
return computerCraft.getMethod( name, args );
} catch( NoSuchMethodException e ) {
System.out.println("ComputerCraftAPI: ComputerCraft method " + name + " not found.");
net.minecraft.server.MinecraftServer.getServer().logInfo( "ComputerCraftAPI: ComputerCraft method " + name + " not found." );
return null;
}
}
private static boolean ccSearched = false;
private static Class computerCraft = null;
private static Method computerCraft_createUniqueNumberedSaveDir = null;
private static Method computerCraft_createSaveDirMount = null;
private static Method computerCraft_createResourceMount = null;
private static Method computerCraft_registerExternalPeripheral = null;
}

View file

@ -14,78 +14,41 @@ package dan200.computer.api;
public interface IComputerAccess
{
/**
* Creates a new numbered directory in a subPath of the users game save, and return that number. To be used with mountSaveDir.<br>
* For example: n = createNewSaveDir( "computer/cdrom" ), will create a new
* numbered folder in the "computer/cdrom" subdirectory of the users save file, and return that number.
* mountSaveDir( "computer/rom", n ) could then be used to mount that folder onto the computers directory
* structure, and the value n could be saved out and used again in future to give the peripheral
* persistant storage.
* @param subPath A relative file path from the users world save, where the directory should be located.
* @return The numeric represenation of the name of the folder created. Will be positive.
* @see #mountSaveDir(String, String, int, boolean, long)
* Mount a mount onto the computers' file system in a read only mode.<br>
* @param desiredLoction The location on the computer's file system where you would like the mount to be mounted.
* @param mount The mount object to mount on the computer. These can be obtained by calling ComputerCraftAPI.createSaveDirMount(), ComputerCraftAPI.createResourceMount() or by creating your own objects that implement the IMount interface.
* @return The location on the computer's file system where you the mount mounted, or null if there was already a file in the desired location. Store this value if you wish to unmount the mount later.
* @see ComputerCraftAPI#createSaveDirMount(World, String)
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
* @see #mountWritable(String, IWritableMount)
* @see #unmount(String)
* @see IMount
*/
public int createNewSaveDir( String subPath );
public String mount( String desiredLocation, IMount mount );
/**
* Mounts a directory into the computers file system, from a real directory a subPath of the users game save,
* with a numerical name. To be used with createNewSaveDir.<br>
* For example: n = createNewSaveDir( "computer/cdrom" ), will create a new
* numbered folder in the "computer/cdrom" subdirectory of the users save file, and return that number.
* mountSaveDir( "computer/rom", n ) could then be used to mount that folder onto the computers directory
* structure, and the value n can be saved out by the peripheral and used again, to give the peripheral
* persistant storage.<br>
* When a directory is mounted, it will appear in the computers file system, and the user will be
* able to use file operation to read from and write to the directory (unless readOnly, then only writes will be allowed).
* @param desiredLocation The desired location in the computers file system where you would like the directory to appear.
* If this location already exists, a number will be appended until a free name is found, and the
* actual location will be returned. eg: "cdrom" can become "cdrom2" if two peripherals attempt to
* mount "cdrom", or a "cdrom" folder already exists.
* @param subPath The real relative file path from the users world save, where the directory to mount can be located.
* @param id The numerical name of the folder to mount from the subPath: ex: mountSaveDir( "cdrom", "computer/cdrom", 7 )
* will mount the directory "computer/cdrom/7". Use createNewSaveDir to obtain a unique directory id.
* @param readOnly Whether the computer will be disallowed from making changes to the mounted directory and modifing or creating files therin.
* @param spaceLimit The size limit of the mount, in bytes. Specify 0 to have unlimited capacity.
* @return The location in the computers file system where the directory was mounted. This may differ from "desiredLocation", so the
* return value should be kept track of so the folder can be unmounted later.
* @see #createNewSaveDir(String)
* @see #mountFixedDir(String, String, boolean, long)
* @see #unmount(String)
* Mount a mount onto the computers' file system in a writable mode.<br>
* @param desiredLoction The location on the computer's file system where you would like the mount to be mounted.
* @param mount The mount object to mount on the computer. These can be obtained by calling ComputerCraftAPI.createSaveDirMount() or by creating your own objects that implement the IWritableMount interface.
* @return The location on the computer's file system where you the mount mounted, or null if there was already a file in the desired location. Store this value if you wish to unmount the mount later.
* @see ComputerCraftAPI#createSaveDirMount(World, String)
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
* @see #mount(String, IMount)
* @see #unmount(String)
* @see IMount
*/
public String mountSaveDir( String desiredLocation, String subPath, int id, boolean readOnly, long spaceLimit );
public String mountWritable( String desiredLocation, IWritableMount mount );
/**
* Mounts a directory into the computers file system, from a real directory in the Minecraft install folder.<br>
* For example: mountFixedDir( "stuff", "mods/mymod/lua/stuff", true ), will mount the "lua/stuff" folder from
* your mod's directory into the computers filesystem at the location "stuff", with readonly permission, giving the
* computer access to those files.<br>
* When a directory is mounted, it will appear in the computers file system, and the user will be
* able to use file operation to read from and write to the directory (unless readOnly, then only writes will be allowed).<br>
* mountFixedDir can also be used to mount files, for example: mountFixedDir( "rom/apis/myapi", "mods/mymod/lua/myapi.lua", true ) can
* be used to have the peripheral install an API onto the computer it attaches to.
* @param desiredLocation The desired location in the computers file system where you would like the directory to appear.
* If this location already exists, a number will be appended until a free name is found, and the
* actual location will be returned. eg: "cdrom" can become "cdrom2" if two peripherals attempt to
* mount "cdrom", or a "cdrom" folder already exists.
* @param subPath The real relative file path from the minecraft install root, where the directory to mount can be located.
* @param readOnly Whether the computer will be disallowed from making changes to the mounted directory and modifing or creating files therin.
* @param spaceLimit The size limit of the mount, in bytes. Specify 0 to have unlimited capacity.
* @return The location in the computers file system where the directory was mounted. This may differ from "desiredLocation", so the
* return value should be kept track of so the folder can be unmounted later.
* @see #mountSaveDir(String, String, int, boolean, long)
* @see #unmount(String)
*/
public String mountFixedDir( String desiredLocation, String path, boolean readOnly, long spaceLimit );
/**
* Unmounts a directory previously mounted onto the computers file system by mountSaveDir or mountFixedDir.<br>
* Unmounts a directory previously mounted onto the computers file system by mount() or mountWritable().<br>
* When a directory is unmounted, it will disappear from the computers file system, and the user will no longer be able to
* access it. All directories mounted by a mountFixedDir or mountSaveDir are automatically unmounted when the peripheral
* access it. All directories mounted by a mount or mountWritable are automatically unmounted when the peripheral
* is attached if they have not been explicitly unmounted.
* @param location The desired location in the computers file system of the directory to unmount.
* This must be the location of a directory previously mounted by mountFixedDir() or mountSaveDir(), as
* This must be the location of a directory previously mounted by mount() or mountWritable(), as
* indicated by their return value.
* @see #mountSaveDir(String, String, int, boolean, long)
* @see #mountFixedDir(String, String, boolean, long)
* @see #mount(String, IMount)
* @see #mountWritable(String, IWritableMount)
*/
public void unmount( String location );

View file

@ -0,0 +1,45 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computer.api;
/**
* An interface passed to peripherals and ILuaObjects' by computers or turtles, providing methods
* that allow the peripheral call to wait for events before returning, just like in lua.
* This is very useful if you need to signal work to be performed on the main thread, and don't want to return
* until the work has been completed.
*/
public interface ILuaContext
{
/**
* Wait for an event to occur on the computer, suspending the thread until it arises. This method is exactly equivalent to os.pullEvent() in lua.
* @param filter A specific event to wait for, or null to wait for any event
* @return An object array containing the name of the event that occurred, and any event parameters
* @throws Exception If the user presses CTRL+T to terminate the current program while pullEvent() is waiting for an event, a "Terminated" exception will be thrown here.
* Do not attempt to block this exception, unless you wish to prevent termination, which is not recommended.
* @throws InterruptedException If the user shuts down or reboots the computer while pullEvent() is waiting for an event, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computer will leak memory and end up in a broken state.
*/
public Object[] pullEvent( String filter ) throws Exception, InterruptedException;
/**
* The same as pullEvent(), except "terminated" events are ignored. Only use this if you want to prevent program termination, which is not recommended. This method is exactly equivalent to os.pullEventRaw() in lua.
* @param filter A specific event to wait for, or null to wait for any event
* @return An object array containing the name of the event that occurred, and any event parameters
* @throws InterruptedException If the user shuts down or reboots the computer while pullEventRaw() is waiting for an event, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computer will leak memory and end up in a broken state.
* @see #pullEvent(String)
*/
public Object[] pullEventRaw( String filter ) throws InterruptedException;
/**
* Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to coroutine.yield() in lua. Use pullEvent() if you wish to wait for events.
* @param arguments An object array containing the arguments to pass to coroutine.yield()
* @return An object array containing the return values from coroutine.yield()
* @throws InterruptedException If the user shuts down or reboots the computer the coroutine is suspended, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computer will leak memory and end up in a broken state.
* @see #pullEvent(String)
*/
public Object[] yield( Object[] arguments ) throws InterruptedException;
}

View file

@ -0,0 +1,26 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computer.api;
/**
* An interface for representing custom objects returned by IPeripheral.callMethod() calls.
* Return objects implementing this interface to expose objects with methods to lua.
*/
public interface ILuaObject
{
/**
* Get the names of the methods that this object implements. This works the same as IPeripheral.getMethodNames(). See that method for detailed documentation.
* @see IPeripheral#getMethodNames()
*/
public String[] getMethodNames();
/**
* Called when a user calls one of the methods that this object implements. This works the same as IPeripheral.callMethod(). See that method for detailed documentation.
* @see IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])
*/
public Object[] callMethod( ILuaContext context, int method, Object[] arguments ) throws Exception;
}

View file

@ -5,17 +5,53 @@
*/
package dan200.computer.api;
import net.minecraft.world.World;
import net.minecraft.item.ItemStack;
/**
* TODO: Document me
* Represents an item that can be placed in a disk drive and used by a Computer.
* Implement this interface on your Item class to allow it to be used in the drive.
*/
public interface IMedia
{
public String getLabel( net.minecraft.item.ItemStack stack );
public boolean setLabel( net.minecraft.item.ItemStack stack, String label );
/**
* Get a string representing the label of this item. Will be called vi disk.getLabel() in lua.
* @param stack The itemstack to inspect
* @return The label. ie: "Dan's Programs"
*/
public String getLabel( ItemStack stack );
/**
* Set a string representing the label of this item. Will be called vi disk.setLabel() in lua.
* @param stack The itemstack to modify.
* @param label The string to set the label to.
* @return true if the label was updated, false if the label may not be modified.
*/
public boolean setLabel( ItemStack stack, String label );
public String getAudioTitle( net.minecraft.item.ItemStack stack );
public String getAudioRecordName( net.minecraft.item.ItemStack stack );
/**
* If this disk represents an item with audio (like a record), get the readable name of the audio track. ie: "Jonathon Coulton - Still Alive"
* @param stack The itemstack to inspect.
* @return The name, or null if this item does not represent an item with audio.
*/
public String getAudioTitle( ItemStack stack );
/**
* If this disk represents an item with audio (like a record), get the resource name of the audio track to play.
* @param stack The itemstack to inspect.
* @return The name, or null if this item does not represent an item with audio.
*/
public String getAudioRecordName( ItemStack stack );
public String mountData( net.minecraft.item.ItemStack stack, IComputerAccess computer );
/**
* If this disk represents an item with data (like a floppy disk), get a mount representing it's contents. This will be mounted onto the filesystem of the computer while the media is in the disk drive.
* @param stack The itemstack to inspect.
* @param world The world in which the item and disk drive reside.
* @return The mount, or null if this item does not represent an item with data. If the IMount returned also implements IWritableMount, it will mounted using mountWritable()
* @see IMount
* @see IWritableMount
* @see ComputerCraftAPI#createSaveDirMount(World, String)
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
*/
public IMount createDataMount( ItemStack stack, World world );
}

View file

@ -0,0 +1,57 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computer.api;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* Represents a read only part of a virtual filesystem that can be mounted onto a computer using IComputerAccess.mount().
* Ready made implementations of this interface can be created using ComputerCraftAPI.createSaveDirMount() or ComputerCraftAPI.createResourceMount(), or you're free to implement it yourselves!
* @see ComputerCraftAPI#createSaveDirMount(World, String)
* @see ComputerCraftAPI#createResourceMount(Class, String, String)
* @see IComputerAccess#mount(String, IMount)
* @see IWritableMount
*/
public interface IMount
{
/**
* Returns whether a file with a given path exists or not.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram"
* @return true if the file exists, false otherwise
*/
public boolean exists( String path ) throws IOException;
/**
* Returns whether a file with a given path is a directory or not.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms"
* @return true if the file exists and is a directory, false otherwise
*/
public boolean isDirectory( String path ) throws IOException;
/**
* Returns the file names of all the files in a directory.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms"
* @param contents A list of strings. Add all the file names to this list
*/
public void list( String path, List<String> contents ) throws IOException;
/**
* Returns the size of a file with a given path, in bytes
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram"
* @return the size of the file, in bytes
*/
public long getSize( String path ) throws IOException;
/**
* Opens a file with a given path, and returns an inputstream representing it's contents.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram"
* @return a stream representing the contents of the file
*/
public InputStream openForRead( String path ) throws IOException;
}

View file

@ -37,6 +37,8 @@ public interface IPeripheral
* when interacting with minecraft objects.
* @param computer The interface to the computer that is making the call. Remember that multiple
* computers can be attached to a peripheral at once.
* @param context The context of the currently running lua thread. This can be used to wait for events
* or otherwise yield.
* @param method An integer identifying which of the methods from getMethodNames() the computer
* wishes to call. The integer indicates the index into the getMethodNames() table
* that corresponds to the string passed into peripheral.call()
@ -55,7 +57,7 @@ public interface IPeripheral
* arguments are supplied to your method.
* @see #getMethodNames
*/
public Object[] callMethod( IComputerAccess computer, int method, Object[] arguments ) throws Exception;
public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws Exception;
/**
* Is called before the computer attempts to attach to the peripheral, and should return whether to allow

View file

@ -0,0 +1,53 @@
/**
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2013. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computer.api;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
/**
* Represents a part of a virtual filesystem that can be mounted onto a computer using IComputerAccess.mount() or IComputerAccess.mountWritable(), that can also be written to.
* Ready made implementations of this interface can be created using ComputerCraftAPI.createSaveDirMount(), or you're free to implement it yourselves!
* @see ComputerCraftAPI#createSaveDirMount(World, String)
* @see IComputerAccess#mountWritable(String, IMount)
* @see IMount
*/
public interface IWritableMount extends IMount
{
/**
* Creates a directory at a given path inside the virtual file system.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/mynewprograms"
*/
public void makeDirectory( String path ) throws IOException;
/**
* Deletes a directory at a given path inside the virtual file system.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myoldprograms"
*/
public void delete( String path ) throws IOException;
/**
* Opens a file with a given path, and returns an outputstream for writing to it.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram"
* @return a stream for writing to
*/
public OutputStream openForWrite( String path ) throws IOException;
/**
* Opens a file with a given path, and returns an outputstream for appending to it.
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram"
* @return a stream for writing to
*/
public OutputStream openForAppend( String path ) throws IOException;
/**
* Get the ammount of free space on the mount, in bytes. You should decrease this value as the user writes to the mount, and write operations should fail once it reaches zero.
* @return The ammount of free space, in bytes.
*/
public long getRemainingSpace() throws IOException;
}

View file

@ -4,7 +4,6 @@ import mekanism.common.inventory.container.ContainerEnergyCube;
import mekanism.common.tileentity.TileEntityEnergyCube;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.StatCollector;

View file

@ -4,7 +4,6 @@ import java.util.HashSet;
import java.util.Set;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
public abstract class GuiMekanism extends GuiContainer

View file

@ -6,12 +6,10 @@ import mekanism.api.Object3D;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.inventory.container.ContainerMetallurgicInfuser;
import mekanism.common.network.PacketRemoveUpgrade;
import mekanism.common.network.PacketTileEntity;
import mekanism.common.tileentity.TileEntityMetallurgicInfuser;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import org.lwjgl.opengl.GL11;

View file

@ -1,7 +1,5 @@
package mekanism.client.gui;
import java.lang.reflect.Method;
import mekanism.api.Object3D;
import mekanism.common.IRedstoneControl;
import mekanism.common.IRedstoneControl.RedstoneControl;
@ -10,7 +8,6 @@ import mekanism.common.PacketHandler.Transmission;
import mekanism.common.network.PacketRedstoneControl;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;

View file

@ -8,7 +8,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import mekanism.client.render.MekanismRenderer;
import mekanism.client.render.MekanismRenderer.BooleanArray;
import mekanism.client.render.MekanismRenderer.DisplayInteger;
import net.minecraft.client.model.ModelBase;

View file

@ -11,7 +11,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import mekanism.api.Object3D;
import mekanism.api.energy.IStrictEnergyAcceptor;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.ITransmitter;

View file

@ -13,7 +13,7 @@ import mekanism.api.energy.IEnergizedItem;
import mekanism.common.item.ItemConfigurator;
import mekanism.common.item.ItemRobit;
import mekanism.common.tileentity.TileEntityChargepad;
import micdoodle8.mods.galacticraft.API.IEntityBreathable;
import micdoodle8.mods.galacticraft.api.entity.IEntityBreathable;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAILookIdle;

View file

@ -4,10 +4,8 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import mekanism.api.Object3D;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.ITransmitter;
import mekanism.api.transmitters.TransmissionType;

View file

@ -2,7 +2,6 @@ package mekanism.common;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.recipe.RecipeInputItemStack;
import ic2.api.recipe.RecipeInputOreDict;
import ic2.api.recipe.Recipes;

View file

@ -1,5 +1,8 @@
package mekanism.common.block;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.tile.IEnergyTile;
import java.util.List;
import java.util.Random;
@ -7,7 +10,6 @@ import mekanism.api.energy.IEnergizedItem;
import mekanism.common.IEnergyCube;
import mekanism.common.ISustainedInventory;
import mekanism.common.Mekanism;
import mekanism.common.Tier;
import mekanism.common.Tier.EnergyCubeTier;
import mekanism.common.item.ItemBlockEnergyCube;
import mekanism.common.tileentity.TileEntityBasicBlock;
@ -27,6 +29,7 @@ import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import buildcraft.api.tools.IToolWrench;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -308,4 +311,15 @@ public class BlockEnergyCube extends BlockContainer
TileEntityEnergyCube tileEntity = (TileEntityEnergyCube)world.getBlockTileEntity(x, y, z);
return tileEntity.getRedstoneLevel();
}
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if(!world.isRemote && tileEntity instanceof TileEntityEnergyCube)
{
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile)tileEntity));
}
}
}

View file

@ -1,5 +1,8 @@
package mekanism.common.block;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.tile.IEnergyTile;
import java.util.List;
import java.util.Random;
@ -19,7 +22,6 @@ import mekanism.common.PacketHandler;
import mekanism.common.Tier;
import mekanism.common.IFactory.RecipeType;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.Tier.FactoryTier;
import mekanism.common.network.PacketElectricChest;
import mekanism.common.network.PacketElectricChest.ElectricChestPacketType;
import mekanism.common.tileentity.TileEntityAdvancedFactory;
@ -60,6 +62,7 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.MinecraftForge;
import buildcraft.api.tools.IToolWrench;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -857,4 +860,15 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds
{
return false;
}
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if(!world.isRemote && tileEntity instanceof IEnergyTile)
{
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile)tileEntity));
}
}
}

View file

@ -3,7 +3,6 @@ package mekanism.common.inventory.container;
import mekanism.api.IStorageTank;
import mekanism.common.Mekanism;
import mekanism.common.RecipeHandler;
import mekanism.common.inventory.slot.SlotEnergy;
import mekanism.common.inventory.slot.SlotMachineUpgrade;
import mekanism.common.inventory.slot.SlotOutput;
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;

View file

@ -2,7 +2,6 @@ package mekanism.common.inventory.container;
import mekanism.common.IElectricChest;
import mekanism.common.inventory.slot.SlotElectricChest;
import mekanism.common.inventory.slot.SlotEnergy;
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
import mekanism.common.tileentity.TileEntityElectricChest;
import mekanism.common.util.ChargeUtils;

View file

@ -1,7 +1,6 @@
package mekanism.common.inventory.container;
import mekanism.common.RecipeHandler;
import mekanism.common.inventory.slot.SlotEnergy;
import mekanism.common.inventory.slot.SlotMachineUpgrade;
import mekanism.common.inventory.slot.SlotOutput;
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;

View file

@ -1,6 +1,5 @@
package mekanism.common.inventory.container;
import mekanism.common.inventory.slot.SlotEnergy;
import mekanism.common.inventory.slot.SlotOutput;
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
import mekanism.common.tileentity.TileEntityElectricPump;

View file

@ -1,7 +1,6 @@
package mekanism.common.inventory.container;
import ic2.api.item.IElectricItem;
import mekanism.common.inventory.slot.SlotEnergy;
import mekanism.common.inventory.slot.SlotEnergy.SlotCharge;
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
import mekanism.common.tileentity.TileEntityEnergyCube;

View file

@ -1,11 +1,9 @@
package mekanism.common.inventory.container;
import mekanism.common.IFactory;
import mekanism.common.Tier;
import mekanism.common.IFactory.RecipeType;
import mekanism.common.Tier.FactoryTier;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.inventory.slot.SlotEnergy;
import mekanism.common.inventory.slot.SlotMachineUpgrade;
import mekanism.common.inventory.slot.SlotOutput;
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;

View file

@ -4,7 +4,6 @@ import mekanism.api.infuse.InfuseRegistry;
import mekanism.api.infuse.InfusionInput;
import mekanism.common.RecipeHandler;
import mekanism.common.RecipeHandler.Recipe;
import mekanism.common.inventory.slot.SlotEnergy;
import mekanism.common.inventory.slot.SlotMachineUpgrade;
import mekanism.common.inventory.slot.SlotOutput;
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;

View file

@ -1,7 +1,6 @@
package mekanism.common.inventory.container;
import mekanism.common.EntityRobit;
import mekanism.common.inventory.slot.SlotEnergy;
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;

View file

@ -1,6 +1,5 @@
package mekanism.common.inventory.container;
import mekanism.common.inventory.slot.SlotEnergy;
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
import mekanism.common.tileentity.TileEntityTeleporter;
import mekanism.common.util.ChargeUtils;

View file

@ -12,7 +12,6 @@ import mekanism.common.IEnergyCube;
import mekanism.common.ISustainedInventory;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.Tier;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.Tier.EnergyCubeTier;
import mekanism.common.network.PacketTileEntity;

View file

@ -13,9 +13,7 @@ import mekanism.common.ISustainedInventory;
import mekanism.common.ISustainedTank;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.IFactory.RecipeType;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.block.BlockMachine;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.inventory.InventoryElectricChest;
import mekanism.common.network.PacketElectricChest;

View file

@ -18,6 +18,7 @@ import net.minecraft.util.ResourceLocation;
import com.google.common.io.ByteArrayDataInput;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicMachine
{
@ -287,7 +288,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
}
@Override
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
switch(method)
{

View file

@ -5,7 +5,6 @@ import ic2.api.energy.tile.IEnergySink;
import java.util.ArrayList;
import mekanism.api.IConfigurable;
import mekanism.api.IUpgradeManagement;
import mekanism.api.Object3D;
import mekanism.api.SideData;
import mekanism.api.energy.IStrictEnergyAcceptor;
@ -17,7 +16,6 @@ import mekanism.common.IUpgradeTile;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.TileComponentUpgrade;
import mekanism.common.IRedstoneControl.RedstoneControl;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.network.PacketTileEntity;
import mekanism.common.util.MekanismUtils;

View file

@ -10,6 +10,7 @@ import mekanism.common.util.MekanismUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
{
@ -171,7 +172,7 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
}
@Override
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
switch(method)
{

View file

@ -14,8 +14,6 @@ import mekanism.api.energy.IStrictEnergyAcceptor;
import mekanism.api.transmitters.TransmissionType;
import mekanism.common.IRedstoneControl;
import mekanism.common.Mekanism;
import mekanism.common.Tier;
import mekanism.common.IRedstoneControl.RedstoneControl;
import mekanism.common.Tier.EnergyCubeTier;
import mekanism.common.util.CableUtils;
import mekanism.common.util.ChargeUtils;
@ -36,6 +34,7 @@ import buildcraft.api.power.PowerHandler.Type;
import com.google.common.io.ByteArrayDataInput;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
import dan200.computer.api.IPeripheral;
public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEnergySink, IEnergySource, IEnergyStorage, IPowerReceptor, IPeripheral, ICableOutputter, IStrictEnergyAcceptor, IRedstoneControl
@ -324,7 +323,7 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
}
@Override
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
switch(method)
{

View file

@ -6,24 +6,19 @@ import java.util.ArrayList;
import mekanism.api.EnumColor;
import mekanism.api.IConfigurable;
import mekanism.api.IUpgradeManagement;
import mekanism.api.Object3D;
import mekanism.api.SideData;
import mekanism.api.energy.IStrictEnergyAcceptor;
import mekanism.client.sound.IHasSound;
import mekanism.common.IActiveState;
import mekanism.common.IFactory;
import mekanism.common.IRedstoneControl;
import mekanism.common.IUpgradeTile;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.Tier;
import mekanism.common.TileComponentUpgrade;
import mekanism.common.IFactory.RecipeType;
import mekanism.common.IRedstoneControl.RedstoneControl;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.Tier.FactoryTier;
import mekanism.common.block.BlockMachine;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity;
import mekanism.common.util.ChargeUtils;
@ -36,6 +31,7 @@ import net.minecraftforge.common.ForgeDirection;
import com.google.common.io.ByteArrayDataInput;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
import dan200.computer.api.IPeripheral;
public class TileEntityFactory extends TileEntityElectricBlock implements IEnergySink, IPeripheral, IActiveState, IConfigurable, IUpgradeTile, IHasSound, IStrictEnergyAcceptor, IRedstoneControl
@ -537,7 +533,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
}
@Override
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
switch(method)
{

View file

@ -10,7 +10,6 @@ import mekanism.api.gas.IGasAcceptor;
import mekanism.api.gas.IGasStorage;
import mekanism.api.gas.ITubeConnection;
import mekanism.common.IRedstoneControl;
import mekanism.common.IRedstoneControl.RedstoneControl;
import mekanism.common.util.MekanismUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;

View file

@ -6,7 +6,6 @@ import java.util.ArrayList;
import mekanism.api.EnumColor;
import mekanism.api.IConfigurable;
import mekanism.api.IUpgradeManagement;
import mekanism.api.Object3D;
import mekanism.api.SideData;
import mekanism.api.energy.IStrictEnergyAcceptor;
@ -23,7 +22,6 @@ import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.RecipeHandler;
import mekanism.common.TileComponentUpgrade;
import mekanism.common.IRedstoneControl.RedstoneControl;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.RecipeHandler.Recipe;
import mekanism.common.block.BlockMachine.MachineType;
@ -38,6 +36,7 @@ import net.minecraftforge.common.ForgeDirection;
import com.google.common.io.ByteArrayDataInput;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
import dan200.computer.api.IPeripheral;
public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implements IEnergySink, IPeripheral, IActiveState, IConfigurable, IUpgradeTile, IHasSound, IStrictEnergyAcceptor, IRedstoneControl
@ -450,7 +449,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
}
@Override
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
switch(method)
{

View file

@ -12,7 +12,6 @@ import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.Teleporter;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.Teleporter.Code;
import mekanism.common.network.PacketPortalFX;
import mekanism.common.util.ChargeUtils;
import net.minecraft.entity.Entity;
@ -27,6 +26,7 @@ import net.minecraftforge.common.ForgeDirection;
import com.google.common.io.ByteArrayDataInput;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
import dan200.computer.api.IPeripheral;
public class TileEntityTeleporter extends TileEntityElectricBlock implements IEnergySink, IPeripheral, IStrictEnergyAcceptor
@ -400,7 +400,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
}
@Override
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
switch(method)
{

View file

@ -22,12 +22,10 @@ import mekanism.common.IRedstoneControl;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.Teleporter;
import mekanism.common.Tier;
import mekanism.common.Version;
import mekanism.common.IFactory.RecipeType;
import mekanism.common.IRedstoneControl.RedstoneControl;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.Teleporter.Code;
import mekanism.common.Tier.EnergyCubeTier;
import mekanism.common.Tier.FactoryTier;
import mekanism.common.inventory.container.ContainerElectricChest;

View file

@ -23,6 +23,7 @@ import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
public class TileEntityBioGenerator extends TileEntityGenerator implements IFluidHandler
{
@ -255,7 +256,7 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements IFlui
}
@Override
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
switch(method)
{

View file

@ -39,6 +39,7 @@ import net.minecraftforge.fluids.IFluidHandler;
import com.google.common.io.ByteArrayDataInput;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
import dan200.computer.api.IPeripheral;
public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock implements IGasStorage, IEnergySink, IFluidHandler, IPeripheral, ITubeConnection, IStrictEnergyAcceptor, ISustainedTank
@ -532,7 +533,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
}
@Override
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
switch(method)
{

View file

@ -21,6 +21,7 @@ import net.minecraftforge.fluids.IFluidHandler;
import com.google.common.io.ByteArrayDataInput;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
public class TileEntityHeatGenerator extends TileEntityGenerator implements IFluidHandler
{
@ -246,7 +247,7 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements IFlu
}
@Override
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
switch(method)
{

View file

@ -17,6 +17,7 @@ import net.minecraftforge.common.ForgeDirection;
import com.google.common.io.ByteArrayDataInput;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
public class TileEntityHydrogenGenerator extends TileEntityGenerator implements IGasAcceptor, IGasStorage, ITubeConnection
{
@ -158,7 +159,7 @@ public class TileEntityHydrogenGenerator extends TileEntityGenerator implements
}
@Override
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
switch(method)
{

View file

@ -7,13 +7,14 @@ import mekanism.common.util.ChargeUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.generators.common.MekanismGenerators;
import mekanism.generators.common.block.BlockGenerator.GeneratorType;
import micdoodle8.mods.galacticraft.API.ISolarLevel;
import micdoodle8.mods.galacticraft.api.world.ISolarLevel;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import com.google.common.io.ByteArrayDataInput;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
public class TileEntitySolarGenerator extends TileEntityGenerator
{
@ -139,7 +140,7 @@ public class TileEntitySolarGenerator extends TileEntityGenerator
}
@Override
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
switch(method)
{

View file

@ -7,6 +7,7 @@ import mekanism.common.util.MekanismUtils;
import mekanism.generators.common.MekanismGenerators;
import net.minecraft.item.ItemStack;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
public class TileEntityWindTurbine extends TileEntityGenerator implements IBoundingBlock
{
@ -58,7 +59,7 @@ public class TileEntityWindTurbine extends TileEntityGenerator implements IBound
}
@Override
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
switch(method)
{

View file

@ -1,6 +0,0 @@
package micdoodle8.mods.galacticraft.API;
public interface IEntityBreathable
{
public boolean canBreath();
}

View file

@ -1,6 +0,0 @@
package micdoodle8.mods.galacticraft.API;
public interface ISolarLevel
{
public double getSolarEnergyMultiplier();
}

View file

@ -0,0 +1,13 @@
package micdoodle8.mods.galacticraft.api.entity;
/**
* Implement into entities that are living, but can breath without oxygen
*/
public interface IEntityBreathable
{
/**
* Whether or not this entity can currently breathe without oxygen in it's
* vicinity
*/
public boolean canBreath();
}

View file

@ -0,0 +1,18 @@
package micdoodle8.mods.galacticraft.api.world;
/**
* Used to change the solar multiplier of certain world providers
*
* If you have a solar feature in your mod, check whether the world's provider
* inherits this class and multiply the solar generation by the solar multiplier
* double
*
* for example:
*
* if (worldObj.provider instanceof ISolarLevel) solarStrength *= ((ISolarLevel)
* worldObj.provider).getSolarEnergyMultiplier();
*/
public interface ISolarLevel
{
public double getSolarEnergyMultiplier();
}

View file

@ -2,9 +2,11 @@ package rebelkeithy.mods.metallurgy.api;
import java.util.Map;
public interface IMetalSet
public interface IMetalSet
{
public IOreInfo getOreInfo(String name);
public IOreInfo getOreInfo(int metadata);
public Map<String, IOreInfo> getOreList();
public IOreInfo getOreInfo(int metadata);
public IOreInfo getOreInfo(String name);
public Map<String, IOreInfo> getOreList();
}

View file

@ -2,30 +2,38 @@ package rebelkeithy.mods.metallurgy.api;
import net.minecraft.item.ItemStack;
public interface IOreInfo
public interface IOreInfo
{
public String getName();
public OreType getType();
public boolean isEnabled();
public ItemStack getOre();
public ItemStack getBlock();
public ItemStack getBrick();
// Returns an array of OreDictionary keys of the dusts the make this if it's
// an alloy
// if it's not an alloy, this returns null
public String[] getAlloyRecipe();
// Returns the itemstack of dust this ore crushes into, if no dust exists, returns null
public ItemStack getDust();
public ItemStack getBlock();
// Returns the itemstack of ingot for this ore, if no ingot exists, returns null
public ItemStack getIngot();
// If this ore drops something other than itself, this returns the ItemStack
// of the drop, otherwise returns null
public ItemStack getDrop();
public int getDropAmountMin();
public int getDropAmountMax();
// Returns an array of OreDictionary keys of the dusts the make this if it's an alloy
// if it's not an alloy, this returns null
public String[] getAlloyRecipe();
public ItemStack getBrick();
// If this ore drops something other than itself, this returns the ItemStack
// of the drop, otherwise returns null
public ItemStack getDrop();
public int getDropAmountMax();
public int getDropAmountMin();
// Returns the itemstack of dust this ore crushes into, if no dust exists,
// returns null
public ItemStack getDust();
// Returns the itemstack of ingot for this ore, if no ingot exists, returns
// null
public ItemStack getIngot();
public String getName();
public ItemStack getOre();
public OreType getType();
public boolean isEnabled();
}

View file

@ -2,39 +2,48 @@ package rebelkeithy.mods.metallurgy.api;
import java.lang.reflect.Field;
public class MetallurgyAPI
public class MetallurgyAPI
{
// Values for name: "base", "precious", "nether", "fantasy", "ender", "utility"
public static IMetalSet getMetalSet(String name)
{
try {
Class metallurgyMetals = Class.forName("rebelkeithy.mods.metallurgy.metals.MetallurgyMetals");
Field set = metallurgyMetals.getField(name + "Set");
return (IMetalSet) set.get(null);
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static String[] getMetalSetNames()
{
// TODO maybe put something to get runtime list here
String[] names = {"base", "precious", "nether", "fantasy", "ender", "utility"};
return names;
}
// Values for name: "base", "precious", "nether", "fantasy", "ender",
// "utility"
public static IMetalSet getMetalSet(String name)
{
try
{
final Class metallurgyMetals = Class.forName("rebelkeithy.mods.metallurgy.metals.MetallurgyMetals");
final Field set = metallurgyMetals.getField(name + "Set");
return (IMetalSet) set.get(null);
} catch (final NoSuchFieldException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final SecurityException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final ClassNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final IllegalArgumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final IllegalAccessException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static String[] getMetalSetNames()
{
// TODO maybe put something to get runtime list here
final String[] names =
{ "base", "precious", "nether", "fantasy", "ender", "utility" };
return names;
}
}

View file

@ -1,18 +1,19 @@
package rebelkeithy.mods.metallurgy.api;
public enum OreType {
ORE(true), CATALYST(true), ALLOY(false), RESPAWN(true), DROP(true);
private boolean generates;
public enum OreType
{
OreType(boolean generates)
{
this.generates = generates;
}
public boolean generates()
{
return generates;
}
ORE(true), CATALYST(true), ALLOY(false), RESPAWN(true), DROP(true);
private boolean generates;
OreType(boolean generates)
{
this.generates = generates;
}
public boolean generates()
{
return generates;
}
}

View file

@ -5,52 +5,76 @@ import universalelectricity.core.electricity.NetworkLoader;
import cpw.mods.fml.common.Loader;
/**
* The Universal Electricity compatiblity module allows your mod to be compatible with most major
* The Universal Electricity compatibility module allows your mod to be compatible with most major
* power systems in Minecraft.
*
* @author Calclavia, Micdoodle
*
*/
public class Compatibility
{
/**
* Universal Electricity measures in Kilowatts.
*
* Multiply this to convert foreign energy into UE Joules.
*/
/** Version of build craft api compiled with */
public static String BCx_VERSION = "@BCxVersion@";
/** Version of industrial craft api compiled with */
public static String ICx_VERSION = "@ICxVersion@";
/** Version of thermal expansion api compiled with */
public static String TEx_VERSION = "@TExVersion@";
/** Has the initiate method been called */
public static boolean INIT = false;
/** Ratio of Build craft(MJ) power to UE power(KW). Multiply BC3 power by this to convert to UE */
public static float BC3_RATIO = 1;
public static float IC2_RATIO = 0.4f;
/**
* Ratio of Industrial craft(EU) power to UE power(KW). Multiply IC2 power by this to convert to
* UE
*/
public static float IC2_RATIO = 0.04f;
/**
* Multiply this to convert UE Joules into foreign energy. The reciprocal conversion ratio.
* Ratio of UE power(KW) to Industrial craft(EU) power. Multiply UE power by this to convert it
* to IC2 power
*/
public static float TO_IC2_RATIO = 1 / IC2_RATIO;
/**
* Ratio of UE power(KW) to Build craft(MJ) power. Multiply UE power by this to convert it to
* BC3 power
*/
public static float TO_BC_RATIO = 1 / BC3_RATIO;
/**
* You must call this function to enable the Universal Network module.
*/
/** You must call this function to enable the Universal Network module. */
public static void initiate()
{
/**
* Loads the configuration and sets all the values.
*/
UniversalElectricity.CONFIGURATION.load();
IC2_RATIO = (float) UniversalElectricity.CONFIGURATION.get("Compatiblity", "IndustrialCraft Conversion Ratio", IC2_RATIO).getDouble(IC2_RATIO);
BC3_RATIO = (float) UniversalElectricity.CONFIGURATION.get("Compatiblity", "BuildCraft Conversion Ratio", BC3_RATIO).getDouble(BC3_RATIO);
TO_IC2_RATIO = 1 / IC2_RATIO;
TO_BC_RATIO = 1 / BC3_RATIO;
UniversalElectricity.CONFIGURATION.save();
NetworkLoader.setNetworkClass(UniversalNetwork.class);
if (!INIT)
{
/** Outputs basic version information */
System.out.println("[UniversalElectricity] Loading compatibility API version " + UniversalElectricity.VERSION);
System.out.println("[UniversalElectricity] Compiled with IndustrialCraft API version " + Compatibility.ICx_VERSION);
System.out.println("[UniversalElectricity] Compiled with BuildCraft API version " + Compatibility.BCx_VERSION);
System.out.println("[UniversalElectricity] Compiled with ThermalExpansion API version " + Compatibility.TEx_VERSION);
/** Loads the configuration and sets all the values. */
UniversalElectricity.CONFIGURATION.load();
IC2_RATIO = (float) UniversalElectricity.CONFIGURATION.get("Compatiblity", "IndustrialCraft Conversion Ratio", IC2_RATIO).getDouble(IC2_RATIO);
BC3_RATIO = (float) UniversalElectricity.CONFIGURATION.get("Compatiblity", "BuildCraft Conversion Ratio", BC3_RATIO).getDouble(BC3_RATIO);
TO_IC2_RATIO = 1 / IC2_RATIO;
TO_BC_RATIO = 1 / BC3_RATIO;
UniversalElectricity.CONFIGURATION.save();
NetworkLoader.setNetworkClass(UniversalNetwork.class);
}
}
/** Checks using the FML loader too see if IC2 is loaded */
public static boolean isIndustrialCraft2Loaded()
{
return Loader.isModLoaded("IC2");
}
/** Checks using the FML loader too see if BC3 is loaded */
public static boolean isBuildcraftLoaded()
{
return Loader.isModLoaded("BuildCraft|Energy");
}
// TODO add Thermal expansion isLoaded check
}

View file

@ -6,7 +6,12 @@ import ic2.api.energy.tile.IEnergyAcceptor;
import ic2.api.energy.tile.IEnergyEmitter;
import ic2.api.energy.tile.IEnergySink;
import ic2.api.energy.tile.IEnergyTile;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.MinecraftForge;
import universalelectricity.core.block.IConnector;
@ -15,6 +20,9 @@ import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
import universalelectricity.prefab.tile.TileEntityConductor;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
/**
* A universal conductor class.
@ -22,15 +30,22 @@ import buildcraft.api.power.IPowerReceptor;
* Extend this class or use as a reference for your own implementation of compatible conductor
* tiles.
*
* TODO: Need working BuildCraft support!
*
* @author micdoodle8
* @author Calclavia, micdoodle8
*
*/
public abstract class TileEntityUniversalConductor extends TileEntityConductor implements IEnergySink
public abstract class TileEntityUniversalConductor extends TileEntityConductor implements IEnergySink, IPowerReceptor
{
protected boolean isAddedToEnergyNet;
protected boolean isAddedToEnergyNet;
public PowerHandler powerHandler;
public float buildcraftBuffer = Compatibility.BC3_RATIO * 50;
public TileEntityUniversalConductor()
{
this.powerHandler = new PowerHandler(this, Type.PIPE);
this.powerHandler.configure(0, this.buildcraftBuffer, this.buildcraftBuffer, this.buildcraftBuffer * 2);
this.powerHandler.configurePowerPerdition(0, 0);
}
@Override
public TileEntity[] getAdjacentConnections()
{
@ -62,19 +77,22 @@ public abstract class TileEntityUniversalConductor extends TileEntityConductor i
}
if (tileEntity instanceof IEnergyEmitter)
{
if (((IEnergyEmitter) tileEntity).emitsEnergyTo(tileEntity, side.getOpposite()))
{
this.adjacentConnections[i] = tileEntity;
continue;
}
}
{
if (((IEnergyEmitter) tileEntity).emitsEnergyTo(tileEntity, side.getOpposite()))
{
this.adjacentConnections[i] = tileEntity;
continue;
}
}
this.adjacentConnections[i] = tileEntity;
}
else if (Compatibility.isBuildcraftLoaded() && tileEntity instanceof IPowerReceptor)
{
this.adjacentConnections[i] = tileEntity;
if (((IPowerReceptor) tileEntity).getPowerReceiver(side.getOpposite()) != null)
{
this.adjacentConnections[i] = tileEntity;
}
}
}
}
@ -82,88 +100,118 @@ public abstract class TileEntityUniversalConductor extends TileEntityConductor i
return this.adjacentConnections;
}
@Override
public boolean canUpdate()
{
return !this.isAddedToEnergyNet;
}
/*
* @Override public boolean canUpdate() { return !this.isAddedToEnergyNet; }
*/
@Override
public void updateEntity()
{
if (!this.worldObj.isRemote)
{
if (!this.isAddedToEnergyNet)
{
this.initIC();
}
}
}
@Override
public void updateEntity()
{
if (!this.worldObj.isRemote)
{
if (!this.isAddedToEnergyNet)
{
this.initIC();
}
}
}
@Override
public void invalidate()
{
this.unloadTileIC2();
super.invalidate();
}
@Override
public void invalidate()
{
this.unloadTileIC2();
super.invalidate();
}
@Override
public void onChunkUnload()
{
this.unloadTileIC2();
super.onChunkUnload();
}
@Override
public void onChunkUnload()
{
this.unloadTileIC2();
super.onChunkUnload();
}
protected void initIC()
{
if (Compatibility.isIndustrialCraft2Loaded())
{
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
}
protected void initIC()
{
if (Compatibility.isIndustrialCraft2Loaded())
{
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
}
this.isAddedToEnergyNet = true;
}
this.isAddedToEnergyNet = true;
}
private void unloadTileIC2()
{
if (this.isAddedToEnergyNet && this.worldObj != null)
{
if (Compatibility.isIndustrialCraft2Loaded())
{
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
}
private void unloadTileIC2()
{
if (this.isAddedToEnergyNet && this.worldObj != null)
{
if (Compatibility.isIndustrialCraft2Loaded())
{
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
}
this.isAddedToEnergyNet = false;
}
}
this.isAddedToEnergyNet = false;
}
}
@Override
public double demandedEnergyUnits()
{
if (this.getNetwork() == null)
{
return 0.0;
}
return this.getNetwork().getRequest(this).getWatts() * Compatibility.TO_IC2_RATIO;
}
@Override
public double demandedEnergyUnits()
{
if (this.getNetwork() == null)
{
return 0.0;
}
@Override
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
{
TileEntity tile = VectorHelper.getTileEntityFromSide(this.worldObj, new Vector3(this), directionFrom);
return this.getNetwork().produce(ElectricityPack.getFromWatts((float) (amount * Compatibility.IC2_RATIO), 120.0F / 1000.0F), this, tile);
}
return this.getNetwork().getRequest(this).getWatts() * Compatibility.TO_IC2_RATIO;
}
@Override
public int getMaxSafeInput()
{
return Integer.MAX_VALUE;
}
@Override
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
{
TileEntity tile = VectorHelper.getTileEntityFromSide(this.worldObj, new Vector3(this), directionFrom);
ElectricityPack pack = ElectricityPack.getFromWatts((float) (amount * Compatibility.IC2_RATIO), 120);
return this.getNetwork().produce(pack, this, tile) * Compatibility.TO_IC2_RATIO;
}
@Override
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
{
return true;
}
@Override
public int getMaxSafeInput()
{
return Integer.MAX_VALUE;
}
@Override
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
{
return true;
}
/**
* BuildCraft functions
*/
@Override
public PowerReceiver getPowerReceiver(ForgeDirection side)
{
return this.powerHandler.getPowerReceiver();
}
@Override
public void doWork(PowerHandler workProvider)
{
Set<TileEntity> ignoreTiles = new HashSet<TileEntity>();
ignoreTiles.add(this);
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tile = new Vector3(this).modifyPositionFromSide(direction).getTileEntity(this.worldObj);
ignoreTiles.add(tile);
}
ElectricityPack pack = ElectricityPack.getFromWatts(workProvider.useEnergy(0, this.getNetwork().getRequest(this).getWatts() * Compatibility.TO_BC_RATIO, true) * Compatibility.BC3_RATIO, 120);
this.getNetwork().produce(pack, ignoreTiles.toArray(new TileEntity[0]));
}
@Override
public World getWorld()
{
return this.getWorldObj();
}
}

View file

@ -144,13 +144,15 @@ public abstract class TileEntityUniversalElectrical extends TileEntityElectrical
{
for (ForgeDirection outputDirection : this.getOutputDirections())
{
this.produceUE(outputDirection);
this.produceBuildCraft(outputDirection);
if (!this.produceUE(outputDirection))
{
this.produceBuildCraft(outputDirection);
}
}
}
}
public void produceBuildCraft(ForgeDirection outputDirection)
public boolean produceBuildCraft(ForgeDirection outputDirection)
{
if (!this.worldObj.isRemote && outputDirection != null && outputDirection != ForgeDirection.UNKNOWN)
{
@ -171,11 +173,14 @@ public abstract class TileEntityUniversalElectrical extends TileEntityElectrical
float bc3Provide = provide * Compatibility.TO_BC_RATIO;
float energyUsed = Math.min(receiver.receiveEnergy(this.bcBlockType, bc3Provide, outputDirection.getOpposite()), bc3Provide);
this.provideElectricity((bc3Provide - (energyUsed * Compatibility.TO_BC_RATIO)), true);
return true;
}
}
}
}
}
return false;
}
/**

View file

@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
@ -15,6 +16,7 @@ import universalelectricity.core.block.IConductor;
import universalelectricity.core.block.IElectrical;
import universalelectricity.core.block.INetworkConnection;
import universalelectricity.core.block.INetworkProvider;
import universalelectricity.core.electricity.ElectricalEvent.ElectricityProductionEvent;
import universalelectricity.core.electricity.ElectricalEvent.ElectricityRequestEvent;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.grid.ElectricityNetwork;
@ -24,6 +26,8 @@ import universalelectricity.core.path.PathfinderChecker;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import cpw.mods.fml.common.FMLLog;
/**
@ -34,6 +38,108 @@ import cpw.mods.fml.common.FMLLog;
*/
public class UniversalNetwork extends ElectricityNetwork
{
@Override
public float produce(ElectricityPack electricity, TileEntity... ignoreTiles)
{
ElectricityProductionEvent evt = new ElectricityProductionEvent(this, electricity, ignoreTiles);
MinecraftForge.EVENT_BUS.post(evt);
float totalEnergy = electricity.getWatts();
float networkResistance = getTotalResistance();
float proportionWasted = getTotalResistance() / (getTotalResistance() + acceptorResistance);
float energyWasted = totalEnergy * proportionWasted;
float totalUsableEnergy = totalEnergy - energyWasted;
float remainingUsableEnergy = totalUsableEnergy;
float voltage = electricity.voltage;
if (!evt.isCanceled())
{
Set<TileEntity> avaliableEnergyTiles = this.getAcceptors();
if (!avaliableEnergyTiles.isEmpty())
{
final float totalEnergyRequest = this.getRequest(ignoreTiles).getWatts();
if (totalEnergyRequest > 0)
{
for (TileEntity tileEntity : avaliableEnergyTiles)
{
if (tileEntity != null && !tileEntity.isInvalid())
{
if (remainingUsableEnergy > 0 && !Arrays.asList(ignoreTiles).contains(tileEntity))
{
if (tileEntity instanceof IElectrical)
{
IElectrical electricalTile = (IElectrical) tileEntity;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
if (electricalTile.canConnect(direction) && this.getConductors().contains(VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction)))
{
float energyToSend = totalUsableEnergy * (Math.min(electricalTile.getRequest(direction), totalEnergyRequest) / totalEnergyRequest);
if (energyToSend > 0)
{
ElectricityPack electricityToSend = ElectricityPack.getFromWatts(energyToSend, voltage);
remainingUsableEnergy -= electricalTile.receiveElectricity(direction, electricityToSend, true);
}
}
}
}
else if (Compatibility.isIndustrialCraft2Loaded() && tileEntity instanceof IEnergySink)
{
IEnergySink electricalTile = (IEnergySink) tileEntity;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity conductor = VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction);
if (this.getConductors().contains(conductor) && electricalTile.acceptsEnergyFrom(conductor, direction))
{
float energyToSend = (float) Math.min(totalUsableEnergy * ((electricalTile.demandedEnergyUnits() * Compatibility.IC2_RATIO) / totalEnergyRequest), electricalTile.getMaxSafeInput() * Compatibility.IC2_RATIO);
if (energyToSend > 0)
{
remainingUsableEnergy -= electricalTile.injectEnergyUnits(direction, energyToSend * Compatibility.TO_IC2_RATIO);
}
}
}
}
else if (Compatibility.isBuildcraftLoaded() && tileEntity instanceof IPowerReceptor)
{
IPowerReceptor electricalTile = (IPowerReceptor) tileEntity;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity conductor = VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction);
PowerReceiver receiver = electricalTile.getPowerReceiver(direction);
if (this.getConductors().contains(conductor))
{
float energyToSend = totalUsableEnergy * ((receiver.powerRequest() * Compatibility.TO_BC_RATIO) / totalEnergyRequest);
if (energyToSend > 0)
{
remainingUsableEnergy -= receiver.receiveEnergy(Type.PIPE, energyToSend * Compatibility.TO_BC_RATIO, direction);
}
}
}
}
}
}
else
{
this.refresh();
break;
}
}
}
}
}
return remainingUsableEnergy;
}
@Override
public ElectricityPack getRequest(TileEntity... ignoreTiles)
{
@ -50,11 +156,11 @@ public class UniversalNetwork extends ElectricityNetwork
continue;
}
if (tileEntity instanceof IElectrical)
if (tileEntity != null && !tileEntity.isInvalid())
{
if (!tileEntity.isInvalid())
if (tileEntity.worldObj.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) == tileEntity)
{
if (tileEntity.worldObj.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) == tileEntity)
if (tileEntity instanceof IElectrical)
{
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
@ -65,18 +171,12 @@ public class UniversalNetwork extends ElectricityNetwork
}
continue;
}
}
}
if (Compatibility.isIndustrialCraft2Loaded() && tileEntity instanceof IEnergySink)
{
if (!tileEntity.isInvalid())
{
if (tileEntity.worldObj.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) == tileEntity)
if (Compatibility.isIndustrialCraft2Loaded() && tileEntity instanceof IEnergySink)
{
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
if (((IEnergySink) tileEntity).acceptsEnergyFrom(VectorHelper.getTileEntityFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction), ForgeDirection.values()[(direction.ordinal() + 2) % 6]) && this.getConductors().contains(VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction)))
if (((IEnergySink) tileEntity).acceptsEnergyFrom(VectorHelper.getTileEntityFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction), direction) && this.getConductors().contains(VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction)))
{
requests.add(ElectricityPack.getFromWatts((float) (Math.min(((IEnergySink) tileEntity).demandedEnergyUnits(), ((IEnergySink) tileEntity).getMaxSafeInput()) * Compatibility.IC2_RATIO), 120));
}
@ -84,22 +184,25 @@ public class UniversalNetwork extends ElectricityNetwork
continue;
}
}
}
if (Compatibility.isBuildcraftLoaded() && tileEntity instanceof IPowerReceptor)
{
if (!tileEntity.isInvalid())
{
if (tileEntity.worldObj.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) == tileEntity)
if (Compatibility.isBuildcraftLoaded() && tileEntity instanceof IPowerReceptor)
{
/*
* TODO: Fix unkown direction
*
* TODO: Fix inaccurate BuildCraft request calculation.
*/
requests.add(ElectricityPack.getFromWatts(((IPowerReceptor) tileEntity).getPowerReceiver(ForgeDirection.UNKNOWN).getActivationEnergy() * Compatibility.BC3_RATIO, 120));
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
if (((IPowerReceptor) tileEntity).getPowerReceiver(direction) != null)
{
ElectricityPack pack = ElectricityPack.getFromWatts(((IPowerReceptor) tileEntity).getPowerReceiver(direction).powerRequest() * Compatibility.BC3_RATIO, 120);
if (pack.getWatts() > 0)
{
requests.add(pack);
break;
}
}
}
continue;
}
}
}
@ -178,7 +281,7 @@ public class UniversalNetwork extends ElectricityNetwork
possibleDirections = new ArrayList<ForgeDirection>();
}
if (((IEnergyAcceptor) acceptor).acceptsEnergyFrom(VectorHelper.getTileEntityFromSide(acceptor.worldObj, new Vector3(acceptor), ForgeDirection.getOrientation(i)), ForgeDirection.values()[(i + 2) % 6]) && this.getConductors().contains(VectorHelper.getConnectorFromSide(acceptor.worldObj, new Vector3(acceptor), ForgeDirection.getOrientation(i))))
if (((IEnergyAcceptor) acceptor).acceptsEnergyFrom(VectorHelper.getTileEntityFromSide(acceptor.worldObj, new Vector3(acceptor), ForgeDirection.getOrientation(i)), ForgeDirection.getOrientation(i)) && this.getConductors().contains(VectorHelper.getConnectorFromSide(acceptor.worldObj, new Vector3(acceptor), ForgeDirection.getOrientation(i))))
{
possibleDirections.add(ForgeDirection.getOrientation(i));
}

View file

@ -5,13 +5,11 @@ package universalelectricity.core.electricity;
*
* @author Calclavia
*/
public class ElectricityDisplay
{
/**
* Universal Electricity's units are in KILOJOULES, KILOWATTS and KILOVOLTS. Try to make your
* energy ratio as close to real life as possible.
*
*/
public static enum ElectricUnit
{
@ -34,25 +32,32 @@ public class ElectricityDisplay
}
}
/** Metric system of measurement. */
public static enum MeasurementUnit
{
MICRO("Micro", "mi", 0.000001), MILLI("Milli", "m", 0.001), KILO("Kilo", "k", 1000),
MEGA("Mega", "M", 1000000), GIGA("Giga", "G", 1000000000);
MICRO("Micro", "u", 0.000001f), MILLI("Milli", "m", 0.001f), BASE("", "", 1),
KILO("Kilo", "k", 1000f), MEGA("Mega", "M", 1000000f), GIGA("Giga", "G", 1000000000f),
TERA("Tera", "T", 1000000000000f), PETA("Peta", "P", 1000000000000000f),
EXA("Exa", "E", 1000000000000000000f), ZETTA("Zetta", "Z", 1000000000000000000000f),
YOTTA("Yotta", "Y", 1000000000000000000000000f);
/** long name for the unit */
public String name;
/** short unit version of the unit */
public String symbol;
public double value;
/** Point by which a number is consider to be of this unit */
public float value;
private MeasurementUnit(String name, String symbol, double value)
private MeasurementUnit(String name, String symbol, float value)
{
this.name = name;
this.symbol = symbol;
this.value = value;
}
public String getName(boolean isSymbol)
public String getName(boolean getShort)
{
if (isSymbol)
if (getShort)
{
return symbol;
}
@ -62,28 +67,46 @@ public class ElectricityDisplay
}
}
/** Divides the value by the unit value start */
public double process(double value)
{
return value / this.value;
}
/** Checks if a value is above the unit value start */
public boolean isAbove(float value)
{
return value > this.value;
}
/** Checks if a value is lower than the unit value start */
public boolean isBellow(float value)
{
return value < this.value;
}
}
/**
* By default, mods should store energy in Kilo-Joules, hence a multiplier of 1/1000.
*/
/** By default, mods should store energy in Kilo-Joules, hence a multiplier of 1/1000. */
public static String getDisplay(float value, ElectricUnit unit, int decimalPlaces, boolean isShort)
{
return getDisplay(value, unit, decimalPlaces, isShort, 1000);
}
/**
* Displays the unit as text. Works only for positive numbers.
* Displays the unit as text. Does handle negative numbers, and will place a negative sign in
* front of the output string showing this. Use string.replace to remove the negative sign if
* unwanted
*/
public static String getDisplay(float value, ElectricUnit unit, int decimalPlaces, boolean isShort, float multiplier)
{
value *= multiplier;
String unitName = unit.name;
String prefix = "";
if (value < 0)
{
value = Math.abs(value);
prefix = "-";
}
value *= multiplier;
if (isShort)
{
@ -98,28 +121,28 @@ public class ElectricityDisplay
{
return value + " " + unitName;
}
if (value <= MeasurementUnit.MILLI.value)
else
{
return roundDecimals(MeasurementUnit.MICRO.process(value), decimalPlaces) + " " + MeasurementUnit.MICRO.getName(isShort) + unitName;
for (int i = 0; i < MeasurementUnit.values().length; i++)
{
MeasurementUnit lowerMeasure = MeasurementUnit.values()[i];
if (lowerMeasure.isBellow(value) && lowerMeasure.ordinal() == 0)
{
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName;
}
if (lowerMeasure.ordinal() + 1 >= MeasurementUnit.values().length)
{
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName;
}
MeasurementUnit upperMeasure = MeasurementUnit.values()[i + 1];
if ((lowerMeasure.isAbove(value) && upperMeasure.isBellow(value)) || lowerMeasure.value == value)
{
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName;
}
}
}
if (value < 1)
{
return roundDecimals(MeasurementUnit.MILLI.process(value), decimalPlaces) + " " + MeasurementUnit.MILLI.getName(isShort) + unitName;
}
if (value > MeasurementUnit.MEGA.value)
{
return roundDecimals(MeasurementUnit.MEGA.process(value), decimalPlaces) + " " + MeasurementUnit.MEGA.getName(isShort) + unitName;
}
if (value > MeasurementUnit.KILO.value)
{
return roundDecimals(MeasurementUnit.KILO.process(value), decimalPlaces) + " " + MeasurementUnit.KILO.getName(isShort) + unitName;
}
return roundDecimals(value, decimalPlaces) + " " + unitName;
return prefix + roundDecimals(value, decimalPlaces) + " " + unitName;
}
public static String getDisplay(float value, ElectricUnit unit)

View file

@ -1,19 +1,15 @@
package universalelectricity.core.electricity;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.event.ForgeSubscribe;
import universalelectricity.core.block.IConnector;
import universalelectricity.core.block.INetworkProvider;
import universalelectricity.core.electricity.ElectricalEvent.ElectricityProduceEvent;
import universalelectricity.core.grid.IElectricityNetwork;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
/**
* A helper class that provides additional useful functions to interact with the ElectricityNetwork

View file

@ -70,21 +70,24 @@ public class ElectricityNetwork implements IElectricityNetwork
{
for (TileEntity tileEntity : avaliableEnergyTiles)
{
if (tileEntity instanceof IElectrical && !Arrays.asList(ignoreTiles).contains(tileEntity))
if (!Arrays.asList(ignoreTiles).contains(tileEntity))
{
IElectrical electricalTile = (IElectrical) tileEntity;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
if (tileEntity instanceof IElectrical)
{
if (electricalTile.canConnect(direction) && this.getConductors().contains(VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction)))
IElectrical electricalTile = (IElectrical) tileEntity;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
float energyToSend = totalUsableEnergy * (electricalTile.getRequest(direction) / totalEnergyRequest);
if (energyToSend > 0)
if (electricalTile.canConnect(direction) && this.getConductors().contains(VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction)))
{
ElectricityPack electricityToSend = ElectricityPack.getFromWatts(energyToSend, voltage);
float energyToSend = totalUsableEnergy * (electricalTile.getRequest(direction) / totalEnergyRequest);
remainingUsableEnergy -= ((IElectrical) tileEntity).receiveElectricity(direction, electricityToSend, true);
if (energyToSend > 0)
{
ElectricityPack electricityToSend = ElectricityPack.getFromWatts(energyToSend, voltage);
remainingUsableEnergy -= ((IElectrical) tileEntity).receiveElectricity(direction, electricityToSend, true);
}
}
}
}

View file

@ -6,146 +6,144 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagDouble;
import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.world.World;
import universalelectricity.core.electricity.ElectricityDisplay;
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
/**
* Extend from this class if your item requires electricity or to be charged. Optionally, you can
/** Extend from this class if your item requires electricity or to be charged. Optionally, you can
* implement IItemElectric instead.
*
* @author Calclavia
*
*/
*
* @author Calclavia */
public abstract class ItemElectric extends Item implements IItemElectric
{
public ItemElectric(int id)
{
super(id);
this.setMaxStackSize(1);
this.setMaxDamage(100);
this.setNoRepair();
}
public ItemElectric(int id)
{
super(id);
this.setMaxStackSize(1);
this.setMaxDamage(100);
this.setNoRepair();
}
@Override
public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean par4)
{
String color = "";
float joules = this.getElectricityStored(itemStack);
@Override
public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean par4)
{
String color = "";
float joules = this.getElectricityStored(itemStack);
if (joules <= this.getMaxElectricityStored(itemStack) / 3)
{
color = "\u00a74";
}
else if (joules > this.getMaxElectricityStored(itemStack) * 2 / 3)
{
color = "\u00a72";
}
else
{
color = "\u00a76";
}
if (joules <= this.getMaxElectricityStored(itemStack) / 3)
{
color = "\u00a74";
}
else if (joules > this.getMaxElectricityStored(itemStack) * 2 / 3)
{
color = "\u00a72";
}
else
{
color = "\u00a76";
}
list.add(color + ElectricityDisplay.getDisplayShort(joules, ElectricUnit.JOULES) + "/" + ElectricityDisplay.getDisplayShort(this.getMaxElectricityStored(itemStack), ElectricUnit.JOULES));
}
list.add(color + ElectricityDisplay.getDisplayShort(joules, ElectricUnit.JOULES) + "/" + ElectricityDisplay.getDisplayShort(this.getMaxElectricityStored(itemStack), ElectricUnit.JOULES));
}
/**
* 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 itemStack, World par2World, EntityPlayer par3EntityPlayer)
{
this.setElectricity(itemStack, 0);
}
/** 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 itemStack, World par2World, EntityPlayer par3EntityPlayer)
{
this.setElectricity(itemStack, 0);
}
@Override
public float recharge(ItemStack itemStack, float energy, boolean doReceive)
{
float rejectedElectricity = Math.max((this.getElectricityStored(itemStack) + energy) - this.getMaxElectricityStored(itemStack), 0);
float energyToReceive = energy - rejectedElectricity;
@Override
public float recharge(ItemStack itemStack, float energy, boolean doReceive)
{
float rejectedElectricity = Math.max((this.getElectricityStored(itemStack) + energy) - this.getMaxElectricityStored(itemStack), 0);
float energyToReceive = energy - rejectedElectricity;
if (doReceive)
{
this.setElectricity(itemStack, this.getElectricityStored(itemStack) + energyToReceive);
}
if (doReceive)
{
this.setElectricity(itemStack, this.getElectricityStored(itemStack) + energyToReceive);
}
return energyToReceive;
}
return energyToReceive;
}
@Override
public float discharge(ItemStack itemStack, float energy, boolean doTransfer)
{
float energyToTransfer = Math.min(this.getElectricityStored(itemStack), energy);
@Override
public float discharge(ItemStack itemStack, float energy, boolean doTransfer)
{
float energyToTransfer = Math.min(this.getElectricityStored(itemStack), energy);
if (doTransfer)
{
this.setElectricity(itemStack, this.getElectricityStored(itemStack) - energyToTransfer);
}
if (doTransfer)
{
this.setElectricity(itemStack, this.getElectricityStored(itemStack) - energyToTransfer);
}
return energyToTransfer;
}
return energyToTransfer;
}
@Override
public float getVoltage(ItemStack itemStack)
{
return 120;
}
@Override
public float getVoltage(ItemStack itemStack)
{
return 0.120f;
}
@Override
public void setElectricity(ItemStack itemStack, float joules)
{
// Saves the frequency in the ItemStack
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
@Override
public void setElectricity(ItemStack itemStack, float joules)
{
// Saves the frequency in the ItemStack
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
float electricityStored = Math.max(Math.min(joules, this.getMaxElectricityStored(itemStack)), 0);
itemStack.getTagCompound().setFloat("electricity", electricityStored);
float electricityStored = Math.max(Math.min(joules, this.getMaxElectricityStored(itemStack)), 0);
itemStack.getTagCompound().setFloat("electricity", electricityStored);
/**
* Sets the damage as a percentage to render the bar properly.
*/
itemStack.setItemDamage((int) (100 - (electricityStored / getMaxElectricityStored(itemStack)) * 100));
}
/** Sets the damage as a percentage to render the bar properly. */
itemStack.setItemDamage((int) (100 - (electricityStored / getMaxElectricityStored(itemStack)) * 100));
}
@Override
public float getTransfer(ItemStack itemStack)
{
return this.getMaxElectricityStored(itemStack) - this.getElectricityStored(itemStack);
}
@Override
public float getTransfer(ItemStack itemStack)
{
return this.getMaxElectricityStored(itemStack) - this.getElectricityStored(itemStack);
}
/**
* This function is called to get the electricity stored in this item
*
* @return - The amount of electricity stored in watts
*/
@Override
public float getElectricityStored(ItemStack itemStack)
{
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
/** Gets the energy stored in the item. Energy is stored using item NBT */
@Override
public float getElectricityStored(ItemStack itemStack)
{
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
float energyStored = 0f;
if (itemStack.getTagCompound().hasKey("electricity"))
{
NBTBase obj = itemStack.getTagCompound().getTag("electricity");
if (obj instanceof NBTTagDouble)
{
energyStored = (float) ((NBTTagDouble) obj).data;
}
else if (obj instanceof NBTTagFloat)
{
energyStored = ((NBTTagFloat) obj).data;
}
}
float electricityStored = itemStack.getTagCompound().getFloat("electricity");
/** Sets the damage as a percentage to render the bar properly. */
itemStack.setItemDamage((int) (100 - (energyStored / getMaxElectricityStored(itemStack)) * 100));
return energyStored;
}
/**
* Sets the damage as a percentage to render the bar properly.
*/
itemStack.setItemDamage((int) (100 - (electricityStored / getMaxElectricityStored(itemStack)) * 100));
return electricityStored;
}
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
// Add an uncharged version of the electric item
par3List.add(ElectricItemHelper.getUncharged(new ItemStack(this)));
// Add an electric item to the creative list that is fully charged
ItemStack chargedItem = new ItemStack(this);
par3List.add(ElectricItemHelper.getWithCharge(chargedItem, this.getMaxElectricityStored(chargedItem)));
}
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(ElectricItemHelper.getUncharged(new ItemStack(this)));
par3List.add(ElectricItemHelper.getWithCharge(new ItemStack(this), this.getMaxElectricityStored(new ItemStack(this))));
}
}

View file

@ -54,7 +54,7 @@ public abstract class TileEntityElectrical extends TileEntityAdvanced implements
*
* @param outputDirection - The output direction.
*/
public void produceUE(ForgeDirection outputDirection)
public boolean produceUE(ForgeDirection outputDirection)
{
if (!this.worldObj.isRemote && outputDirection != null && outputDirection != ForgeDirection.UNKNOWN)
{
@ -64,7 +64,6 @@ public abstract class TileEntityElectrical extends TileEntityAdvanced implements
{
TileEntity outputTile = VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), outputDirection);
IElectricityNetwork outputNetwork = ElectricityHelper.getNetworkFromTileEntity(outputTile, outputDirection);
if (outputNetwork != null)
{
ElectricityPack powerRequest = outputNetwork.getRequest(this);
@ -74,10 +73,13 @@ public abstract class TileEntityElectrical extends TileEntityAdvanced implements
ElectricityPack sendPack = ElectricityPack.min(ElectricityPack.getFromWatts(this.getEnergyStored(), this.getVoltage()), ElectricityPack.getFromWatts(provide, this.getVoltage()));
float rejectedPower = outputNetwork.produce(sendPack, this);
this.provideElectricity(sendPack.getWatts() - rejectedPower, true);
return true;
}
}
}
}
return false;
}
/**