capabilities finish

This commit is contained in:
Dragon2488 2017-08-12 11:48:57 +07:00
parent 9367f9b079
commit 2be8419ab0
6 changed files with 37 additions and 111 deletions

View file

@ -1,25 +1,22 @@
package gregtech.api.capability; package gregtech.api.capability;
import gregtech.api.capability.internal.IRedstoneTileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
public interface ICoverable extends IRedstoneTileEntity { public interface ICoverable {
/** @CapabilityInject(ICoverable.class)
* If a Cover of that Type can be placed on this Side. public static final Capability<ICoverable> CAPABILITY_COVERABLE = null;
*/
boolean allowCoverOnSide(EnumFacing side, int coverId);
boolean dropCover(EnumFacing side, EnumFacing droppedSide, boolean forced); boolean allowCoverOnSide(int coverId);
void setCoverDataAtSide(EnumFacing side, int coverData); boolean dropCover(EnumFacing droppedSide, boolean forced);
void setCoverIDAtSide(EnumFacing side, int coverId); void setCoverIDAtSide(int coverId);
int getCoverDataAtSide(EnumFacing side); int getCoverID();
int getCoverIDAtSide(EnumFacing side); void setCoverRedstoneOutput(byte strength);
void setCoverRedstoneOutput(EnumFacing side, byte strength);
} }

View file

@ -1,84 +0,0 @@
package gregtech.api.capability;
import cofh.api.energy.IEnergyReceiver;
import gregtech.api.GregTech_API;
import gregtech.api.capability.internal.IHasWorldObjectAndCoords;
import ic2.api.energy.tile.IEnergyAcceptor;
import ic2.api.energy.tile.IEnergyEmitter;
import ic2.api.energy.tile.IEnergySink;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
/**
* Interface for getting Connected to the GregTech Energy Network.
* <p/>
* This is all you need to connect to the GT Network.
* IPaintable is needed for not connecting differently coloured Blocks to each other.
* IHasWorldObjectAndCoords is needed for the InWorld related Stuff. @TickableTileEntityBase does implement most of that Interface.
*/
public interface IEnergyConnected extends IPaintable, IHasWorldObjectAndCoords, IEnergyAcceptor, IEnergyEmitter {
/**
* Inject Energy Call for Electricity. Gets called by EnergyEmitters to inject Energy into your Block
* <p/>
* Note: you have to check for @inputEnergyFrom because the Network won't check for that by itself.
*
* @param side Vanilla Directions of YOUR Block the Energy gets inserted to. 6 = No specific Side (don't do Side checks for this Side)
* @return amount of used Amperes. 0 if not accepted anything.
*/
long injectEnergyUnits(EnumFacing side, long voltage, long amperage);
/**
* Sided Energy Input
*/
boolean inputEnergyFrom(EnumFacing side);
/**
* Sided Energy Output
*/
boolean outputsEnergyTo(EnumFacing side);
/**
* Utility for the Network
*/
class Util {
/**
* Emits Energy to the E-net. Also compatible with adjacent IC2 TileEntities.
*
* @return the used Amperage.
*/
public static long emitEnergyToNetwork(long voltage, long amperage, IEnergyConnected emitter) {
long rUsedAmperes = 0;
for (EnumFacing side : EnumFacing.VALUES) {
if (amperage <= rUsedAmperes) break;
EnumFacing oppositeSide = side.getOpposite();
if (emitter.outputsEnergyTo(side)) {
TileEntity tileEntity = emitter.getWorldObj().getTileEntity(emitter.getWorldPos().offset(side));
if (tileEntity instanceof IEnergyConnected) {
if (emitter.getColorization() >= 0) {
byte tColor = ((IEnergyConnected) tileEntity).getColorization();
if (tColor >= 0 && tColor != emitter.getColorization()) continue;
}
rUsedAmperes += ((IEnergyConnected) tileEntity).injectEnergyUnits(oppositeSide, voltage, amperage - rUsedAmperes);
} else if (tileEntity instanceof IEnergySink) {
if (((IEnergySink) tileEntity).acceptsEnergyFrom(emitter, oppositeSide)) {
while (amperage > rUsedAmperes && ((IEnergySink) tileEntity).getDemandedEnergy() > 0 &&
((IEnergySink) tileEntity).injectEnergy(oppositeSide, voltage, voltage) < voltage)
rUsedAmperes++;
}
} else if (tileEntity instanceof IEnergyReceiver) {
int rfOut = (int) (voltage * GregTech_API.mEUtoRF / 100);
if (((IEnergyReceiver) tileEntity).receiveEnergy(oppositeSide, rfOut, true) == rfOut) {
((IEnergyReceiver) tileEntity).receiveEnergy(oppositeSide, rfOut, false);
rUsedAmperes++;
}
}
}
}
return rUsedAmperes;
}
}
}

View file

@ -1,6 +1,22 @@
package gregtech.api.capability; package gregtech.api.capability;
public interface IBasicEnergyContainer extends IEnergyConnected { import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
public interface IEnergyContainer {
@CapabilityInject(IEnergyContainer.class)
public static final Capability<IEnergyContainer> CAPABILITY_ENERGY_CONTAINER = null;
/**
* @return amount of used amperes. 0 if not accepted anything.
*/
long acceptEnergyFromNetwork(long voltage, long amperage);
boolean inputsEnergy();
boolean outputsEnergy();
/** /**
* Gets if that amount of electric energy is stored inside the machine. * Gets if that amount of electric energy is stored inside the machine.

View file

@ -29,6 +29,12 @@ public class SimpleCapabilityManager {
public static void init() { public static void init() {
registerCapability(ITurnable.class); registerCapability(ITurnable.class);
registerCapability(IPaintable.class);
registerCapability(IDescribable.class);
registerCapability(IEnergyContainer.class);
registerCapability(IWorkable.class);
registerCapability(IUpgradable.class);
registerCapability(ICoverable.class);
} }
} }

View file

@ -1,16 +1,7 @@
package gregtech.api.capability.internal; package gregtech.api.capability.internal;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.fluids.IFluidHandler;
public interface IHasWorldObjectAndCoords { public interface IHasWorldObjectAndCoords {

View file

@ -1190,10 +1190,10 @@ public class GT_Utility {
if (tString != null && !tString.equals(E)) tList.add(tString); if (tString != null && !tString.equals(E)) tList.add(tString);
} }
if (tTileEntity instanceof IBasicEnergyContainer && ((IBasicEnergyContainer) tTileEntity).getEUCapacity() > 0) { if (tTileEntity instanceof IEnergyContainer && ((IEnergyContainer) tTileEntity).getEUCapacity() > 0) {
tList.add("Max IN: " + ((IBasicEnergyContainer) tTileEntity).getInputVoltage() + " EU"); tList.add("Max IN: " + ((IEnergyContainer) tTileEntity).getInputVoltage() + " EU");
tList.add("Max OUT: " + ((IBasicEnergyContainer) tTileEntity).getOutputVoltage() + " EU at " + ((IBasicEnergyContainer) tTileEntity).getOutputAmperage() + " Amperes"); tList.add("Max OUT: " + ((IEnergyContainer) tTileEntity).getOutputVoltage() + " EU at " + ((IEnergyContainer) tTileEntity).getOutputAmperage() + " Amperes");
tList.add("Energy: " + GT_Utility.formatNumbers(((IBasicEnergyContainer) tTileEntity).getStoredEU()) + " / " + GT_Utility.formatNumbers(((IBasicEnergyContainer) tTileEntity).getEUCapacity()) + "EU"); tList.add("Energy: " + GT_Utility.formatNumbers(((IEnergyContainer) tTileEntity).getStoredEU()) + " / " + GT_Utility.formatNumbers(((IEnergyContainer) tTileEntity).getEUCapacity()) + "EU");
} }
if (tTileEntity instanceof IGregTechTileEntity) { if (tTileEntity instanceof IGregTechTileEntity) {