Update build file to 1.9, use Cofh API.
This commit is contained in:
11
src/main/java/cofh/api/CoFHAPIProps.java
Normal file
11
src/main/java/cofh/api/CoFHAPIProps.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package cofh.api;
|
||||
|
||||
public class CoFHAPIProps {
|
||||
|
||||
private CoFHAPIProps() {
|
||||
|
||||
}
|
||||
|
||||
public static final String VERSION = "1.8.9R1.2.0B1";
|
||||
|
||||
}
|
@@ -4,9 +4,9 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Reference implementation of {@link IEnergyStorage}. Use/extend this or implement your own.
|
||||
*
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class EnergyStorage implements IEnergyStorage {
|
||||
|
||||
@@ -51,29 +51,33 @@ public class EnergyStorage implements IEnergyStorage {
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public void setCapacity(int capacity) {
|
||||
public EnergyStorage setCapacity(int capacity) {
|
||||
|
||||
this.capacity = capacity;
|
||||
|
||||
if (energy > capacity) {
|
||||
energy = capacity;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMaxTransfer(int maxTransfer) {
|
||||
public EnergyStorage setMaxTransfer(int maxTransfer) {
|
||||
|
||||
setMaxReceive(maxTransfer);
|
||||
setMaxExtract(maxTransfer);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMaxReceive(int maxReceive) {
|
||||
public EnergyStorage setMaxReceive(int maxReceive) {
|
||||
|
||||
this.maxReceive = maxReceive;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMaxExtract(int maxExtract) {
|
||||
public EnergyStorage setMaxExtract(int maxExtract) {
|
||||
|
||||
this.maxExtract = maxExtract;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getMaxReceive() {
|
||||
@@ -87,9 +91,9 @@ public class EnergyStorage implements IEnergyStorage {
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is included to allow for server -> client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers
|
||||
* This function is included to allow for server to client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers
|
||||
* are guaranteed to have it.
|
||||
*
|
||||
*
|
||||
* @param energy
|
||||
*/
|
||||
public void setEnergyStored(int energy) {
|
||||
@@ -106,7 +110,7 @@ public class EnergyStorage implements IEnergyStorage {
|
||||
/**
|
||||
* This function is included to allow the containing tile to directly and efficiently modify the energy contained in the EnergyStorage. Do not rely on this
|
||||
* externally, as not all IEnergyHandlers are guaranteed to have it.
|
||||
*
|
||||
*
|
||||
* @param energy
|
||||
*/
|
||||
public void modifyEnergyStored(int energy) {
|
||||
|
@@ -2,20 +2,21 @@ package cofh.api.energy;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
|
||||
/**
|
||||
* Implement this interface on TileEntities which should connect to energy transportation blocks. This is intended for blocks which generate energy but do not
|
||||
* accept it; otherwise just use IEnergyHandler.
|
||||
* <p>
|
||||
* Note that {@link IEnergyHandler} is an extension of this.
|
||||
*
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface IEnergyConnection {
|
||||
|
||||
/**
|
||||
* Returns TRUE if the TileEntity can connect on a given side.
|
||||
*/
|
||||
boolean canConnectEnergy(EnumFacing facing);
|
||||
boolean canConnectEnergy(EnumFacing from);
|
||||
|
||||
}
|
||||
|
@@ -6,15 +6,15 @@ import net.minecraft.item.ItemStack;
|
||||
* Implement this interface on Item classes that support external manipulation of their internal energy storages.
|
||||
* <p>
|
||||
* A reference implementation is provided {@link ItemEnergyContainer}.
|
||||
*
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface IEnergyContainerItem {
|
||||
|
||||
/**
|
||||
* Adds energy to a container item. Returns the quantity of energy that was accepted. This should always return 0 if the item cannot be externally charged.
|
||||
*
|
||||
*
|
||||
* @param container
|
||||
* ItemStack to be charged.
|
||||
* @param maxReceive
|
||||
@@ -28,7 +28,7 @@ public interface IEnergyContainerItem {
|
||||
/**
|
||||
* Removes energy from a container item. Returns the quantity of energy that was removed. This should always return 0 if the item cannot be externally
|
||||
* discharged.
|
||||
*
|
||||
*
|
||||
* @param container
|
||||
* ItemStack to be discharged.
|
||||
* @param maxExtract
|
||||
|
@@ -2,58 +2,26 @@ package cofh.api.energy;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
|
||||
/**
|
||||
* Implement this interface on Tile Entities which should handle energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
|
||||
* <p>
|
||||
* A reference implementation is provided {@link TileEnergyHandler}.
|
||||
* <p>
|
||||
* Note that {@link IEnergyReceiver} and {@link IEnergyProvider} are extensions of this.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyHandler extends IEnergyProvider, IEnergyReceiver {
|
||||
|
||||
// merely a convenience interface (remove these methods in 1.8; provided here for back-compat via compiler doing things)
|
||||
|
||||
/**
|
||||
* Add energy to an IEnergyReceiver, internal distribution is left entirely to the IEnergyReceiver.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is received from.
|
||||
* @param maxReceive
|
||||
* Maximum amount of energy to receive.
|
||||
* @param simulate
|
||||
* If TRUE, the charge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) received.
|
||||
*/
|
||||
@Override
|
||||
int receiveEnergy(EnumFacing facing, int maxReceive, boolean simulate);
|
||||
|
||||
/**
|
||||
* Remove energy from an IEnergyProvider, internal distribution is left entirely to the IEnergyProvider.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is extracted from.
|
||||
* @param maxExtract
|
||||
* Maximum amount of energy to extract.
|
||||
* @param simulate
|
||||
* If TRUE, the extraction will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted.
|
||||
*/
|
||||
@Override
|
||||
int extractEnergy(EnumFacing facing, int maxExtract, boolean simulate);
|
||||
|
||||
public interface IEnergyHandler extends IEnergyConnection {
|
||||
|
||||
/**
|
||||
* Returns the amount of energy currently stored.
|
||||
*/
|
||||
@Override
|
||||
int getEnergyStored(EnumFacing facing);
|
||||
int getEnergyStored(EnumFacing from);
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
@Override
|
||||
int getMaxEnergyStored(EnumFacing facing);
|
||||
int getMaxEnergyStored(EnumFacing from);
|
||||
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ import net.minecraft.util.EnumFacing;
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyProvider extends IEnergyConnection {
|
||||
public interface IEnergyProvider extends IEnergyHandler {
|
||||
|
||||
/**
|
||||
* Remove energy from an IEnergyProvider, internal distribution is left entirely to the IEnergyProvider.
|
||||
@@ -24,16 +24,6 @@ public interface IEnergyProvider extends IEnergyConnection {
|
||||
* If TRUE, the extraction will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted.
|
||||
*/
|
||||
int extractEnergy(EnumFacing facing, int maxExtract, boolean simulate);
|
||||
|
||||
/**
|
||||
* Returns the amount of energy currently stored.
|
||||
*/
|
||||
int getEnergyStored(EnumFacing facing);
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
int getMaxEnergyStored(EnumFacing facing);
|
||||
int extractEnergy(EnumFacing from, int maxExtract, boolean simulate);
|
||||
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ import net.minecraft.util.EnumFacing;
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyReceiver extends IEnergyConnection {
|
||||
public interface IEnergyReceiver extends IEnergyHandler {
|
||||
|
||||
/**
|
||||
* Add energy to an IEnergyReceiver, internal distribution is left entirely to the IEnergyReceiver.
|
||||
@@ -24,16 +24,6 @@ public interface IEnergyReceiver extends IEnergyConnection {
|
||||
* If TRUE, the charge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) received.
|
||||
*/
|
||||
int receiveEnergy(EnumFacing facing, int maxReceive, boolean simulate);
|
||||
|
||||
/**
|
||||
* Returns the amount of energy currently stored.
|
||||
*/
|
||||
int getEnergyStored(EnumFacing facing);
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
int getMaxEnergyStored(EnumFacing facing);
|
||||
int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate);
|
||||
|
||||
}
|
||||
|
@@ -5,15 +5,15 @@ package cofh.api.energy;
|
||||
* This is not to be implemented on TileEntities. This is for internal use only.
|
||||
* <p>
|
||||
* A reference implementation can be found at {@link EnergyStorage}.
|
||||
*
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface IEnergyStorage {
|
||||
|
||||
/**
|
||||
* Adds energy to the storage. Returns quantity of energy that was accepted.
|
||||
*
|
||||
*
|
||||
* @param maxReceive
|
||||
* Maximum amount of energy to be inserted.
|
||||
* @param simulate
|
||||
@@ -24,7 +24,7 @@ public interface IEnergyStorage {
|
||||
|
||||
/**
|
||||
* Removes energy from the storage. Returns quantity of energy that was removed.
|
||||
*
|
||||
*
|
||||
* @param maxExtract
|
||||
* Maximum amount of energy to be extracted.
|
||||
* @param simulate
|
||||
|
@@ -6,9 +6,9 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Reference implementation of {@link IEnergyContainerItem}. Use/extend this or implement your own.
|
||||
*
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ItemEnergyContainer extends Item implements IEnergyContainerItem {
|
||||
|
||||
@@ -43,27 +43,30 @@ public class ItemEnergyContainer extends Item implements IEnergyContainerItem {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMaxTransfer(int maxTransfer) {
|
||||
public ItemEnergyContainer setMaxTransfer(int maxTransfer) {
|
||||
|
||||
setMaxReceive(maxTransfer);
|
||||
setMaxExtract(maxTransfer);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMaxReceive(int maxReceive) {
|
||||
public ItemEnergyContainer setMaxReceive(int maxReceive) {
|
||||
|
||||
this.maxReceive = maxReceive;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMaxExtract(int maxExtract) {
|
||||
public ItemEnergyContainer setMaxExtract(int maxExtract) {
|
||||
|
||||
this.maxExtract = maxExtract;
|
||||
return this;
|
||||
}
|
||||
|
||||
/* IEnergyContainerItem */
|
||||
@Override
|
||||
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
|
||||
|
||||
if (container.getTagCompound() == null) {
|
||||
if (!container.hasTagCompound()) {
|
||||
container.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
int energy = container.getTagCompound().getInteger("Energy");
|
||||
|
@@ -5,12 +5,14 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
/**
|
||||
* Reference implementation of {@link IEnergyHandler}. Use/extend this or implement your own.
|
||||
* Reference implementation of {@link IEnergyReceiver} and {@link IEnergyProvider}. Use/extend this or implement your own.
|
||||
*
|
||||
* This class is really meant to summarize how each interface is properly used.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public class TileEnergyHandler extends TileEntity implements IEnergyHandler {
|
||||
public class TileEnergyHandler extends TileEntity implements IEnergyReceiver, IEnergyProvider {
|
||||
|
||||
protected EnergyStorage storage = new EnergyStorage(32000);
|
||||
|
||||
@@ -30,34 +32,34 @@ public class TileEnergyHandler extends TileEntity implements IEnergyHandler {
|
||||
|
||||
/* IEnergyConnection */
|
||||
@Override
|
||||
public boolean canConnectEnergy(EnumFacing facing) {
|
||||
public boolean canConnectEnergy(EnumFacing from) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* IEnergyReceiver */
|
||||
@Override
|
||||
public int receiveEnergy(EnumFacing facing, int maxReceive, boolean simulate) {
|
||||
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) {
|
||||
|
||||
return storage.receiveEnergy(maxReceive, simulate);
|
||||
}
|
||||
|
||||
/* IEnergyProvider */
|
||||
@Override
|
||||
public int extractEnergy(EnumFacing facing, int maxExtract, boolean simulate) {
|
||||
public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) {
|
||||
|
||||
return storage.extractEnergy(maxExtract, simulate);
|
||||
}
|
||||
|
||||
/* IEnergyReceiver and IEnergyProvider */
|
||||
/* IEnergyHandler */
|
||||
@Override
|
||||
public int getEnergyStored(EnumFacing facing) {
|
||||
public int getEnergyStored(EnumFacing from) {
|
||||
|
||||
return storage.getEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(EnumFacing facing) {
|
||||
public int getMaxEnergyStored(EnumFacing from) {
|
||||
|
||||
return storage.getMaxEnergyStored();
|
||||
}
|
||||
|
10
src/main/java/cofh/api/energy/package-info.java
Normal file
10
src/main/java/cofh/api/energy/package-info.java
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* (C) 2014-2016 Team CoFH / CoFH / Cult of the Full Hub
|
||||
* http://www.teamcofh.com
|
||||
*/
|
||||
@API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHAPI", provides = "CoFHAPI|energy")
|
||||
package cofh.api.energy;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
||||
import cofh.api.CoFHAPIProps;
|
||||
|
9
src/main/java/cofh/api/package-info.java
Normal file
9
src/main/java/cofh/api/package-info.java
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* (C) 2014-2016 Team CoFH / CoFH / Cult of the Full Hub
|
||||
* http://www.teamcofh.com
|
||||
*/
|
||||
@API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHLib", provides = "CoFHAPI")
|
||||
package cofh.api;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
||||
|
Reference in New Issue
Block a user