Update IC2 API

This commit is contained in:
aidancbrady committed 2017-05-27 15:24:46 -07:00
1 parent f4570f61d2
commit 85827362fe
108 files changed
+1570 -598

No files matched your search

Binary file not shown.
Binary file not shown.
@@ -1,9 +1,13 @@
package ic2.api.energy;
import java.io.PrintStream;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.info.ILocatable;
/**
* Interface representing the methods provided by the global EnergyNet class.
@@ -44,6 +48,11 @@ public interface IEnergyNet {
*/
IEnergyTile getSubTile(World world, BlockPos pos);
<T extends TileEntity & IEnergyTile> void addTile(T tile);
<T extends ILocatable & IEnergyTile> void addTile(T tile);
void removeTile(IEnergyTile tile);
World getWorld(IEnergyTile tile);
BlockPos getPos(IEnergyTile tile);
@@ -58,6 +67,8 @@ public interface IEnergyNet {
*/
NodeStats getNodeStats(IEnergyTile tile);
boolean dumpDebugInfo(World world, BlockPos pos, PrintStream console, PrintStream chat);
/**
* Determine the typical power used by the specific tier, e.g. 128 eu/t for tier 2.
*
@@ -73,4 +84,7 @@ public interface IEnergyNet {
* @return tier
*/
int getTierFromPower(double power);
void registerEventReceiver(IEnergyNetEventReceiver receiver);
void unregisterEventReceiver(IEnergyNetEventReceiver receiver);
}
@@ -0,0 +1,20 @@
package ic2.api.energy;
import ic2.api.energy.tile.IEnergyTile;
/**
* Interface for handlers being invoked after energy net changes.
*
* <p>Normally it's enough to listen for the neighbor update, which also happens, but using this
* mechanism allows listening to events that are not adjacent. Mechanisms that inject energy over
* a distance or provide compatibility with 3rd party energy may benefit from it.
*
* <p>The events will be fired after validation and only for successful changes.
*
* <p>WARNING: The events may (and will) be invoked from arbitrary threads. It's up to the
* implementation of IEnergyNetEventReceiver to properly synchronize them.
*/
public interface IEnergyNetEventReceiver {
void onAdd(IEnergyTile tile);
void onRemove(IEnergyTile tile);
}
@@ -0,0 +1,104 @@
package ic2.api.energy.prefab;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
/**
* BasicEnergyTe.Sink and BasicEnergyTe.Source allow integrating tile entities into the energy net
* by using them as the super class.
*
* <p>They implement the necessary forwards to make BasicSink/BasicSource work, provided the sub
* classes always call those forwards when overriding them.
*
* <p>If it's not desirable to use BasicEnergyTe, the delegates like BasicSink can also be used
* directly, provided they receive the forwards like implemented here.
*
* <p>Example usage, machine with 10k EU buffer, tier 2, 50 EU/tick, 100 tick process time:
* <pre><code>
* public class MyMachine extends BasicEnergyTe.Sink implements ITickable {
* public MyMachine() {
* super(10000, 2);
* }
*
* {@literal @}Override
* public void readFromNBT(NBTTagCompound nbt) {
* super.readFromNbt(nbt); // important: keep super call
*
* this.progess = nbt.getInteger("progress");
* }
*
* {@literal @}Override
* public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
* nbt = super.writeToNBT(nbt); // important: keep super call
*
* nbt.setInteger("progress", progress);
*
* return nbt;
* }
*
* {@literal @}Override
* public void update() {
* if (hasWork() && getEnergyBuffer().useEnergy(50) && ++progress >= 100) {
* progress = 0;
* doWork();
* }
* }
*
* private int progress;
* }
* </code></pre>
*/
public class BasicEnergyTe<T extends BasicEnergyTile> extends TileEntity {
public static class Sink extends BasicEnergyTe<BasicSink> {
public Sink(int capacity, int tier) {
energyBuffer = new BasicSink(this, capacity, tier);
}
}
public static class Source extends BasicEnergyTe<BasicSource> {
public Source(int capacity, int tier) {
energyBuffer = new BasicSource(this, capacity, tier);
}
}
protected BasicEnergyTe() { }
public T getEnergyBuffer() {
return energyBuffer;
}
// forwards >>
@Override
public void onLoad() {
energyBuffer.onLoad();
}
@Override
public void invalidate() {
super.invalidate();
energyBuffer.invalidate();
}
@Override
public void onChunkUnload() {
energyBuffer.onChunkUnload();
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
energyBuffer.readFromNBT(nbt);
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
return energyBuffer.writeToNBT(super.writeToNBT(nbt));
}
// << forwards
protected T energyBuffer;
}
@@ -0,0 +1,309 @@
package ic2.api.energy.prefab;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.info.ILocatable;
import ic2.api.info.Info;
import ic2.api.item.ElectricItem;
/**
* Common functionality for BasicSink and BasicSource.
*/
abstract class BasicEnergyTile implements ILocatable, IEnergyTile {
// **********************************
// *** Methods for use by the mod ***
// **********************************
/**
* Constructor for a new BasicSink delegate.
*
* @param parent TileEntity represented by this energy sink.
* @param capacity Maximum amount of eu to store.
* @param tier IC2 tier, 1 = LV, 2 = MV, ...
*/
protected BasicEnergyTile(TileEntity parent, double capacity) {
this((Object) parent, capacity);
}
protected BasicEnergyTile(ILocatable parent, double capacity) {
this((Object) parent, capacity);
}
private BasicEnergyTile(Object locationProvider, double capacity) {
this.locationProvider = locationProvider;
this.capacity = capacity;
}
protected BasicEnergyTile(World world, BlockPos pos, double capacity) {
if (world == null) throw new NullPointerException("null world");
if (pos == null) throw new NullPointerException("null pos");
this.locationProvider = null;
this.world = world;
this.pos = pos;
this.capacity = capacity;
}
// in-world te forwards >>
/**
* Forward for the base TileEntity's update(), used for creating the energy net link.
* Either update or onLoad have to be used.
*/
public void update() {
if (!addedToEnet) onLoad();
}
/**
* Notification that the base TileEntity is loaded, used for creating the energy net link.
* Either update or onLoad have to be used.
*/
public void onLoad() {
if (!addedToEnet
&& !getWorldObj().isRemote
&& Info.isIc2Available()) {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
addedToEnet = true;
}
}
/**
* Forward for the base TileEntity's invalidate(), used for destroying the energy net link.
* Both invalidate and onChunkUnload have to be used.
*/
public void invalidate() {
onChunkUnload();
}
/**
* Forward for the base TileEntity's onChunkUnload(), used for destroying the energy net link.
* Both invalidate and onChunkUnload have to be used.
*/
public void onChunkUnload() {
if (addedToEnet
&& !getWorldObj().isRemote
&& Info.isIc2Available()) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
addedToEnet = false;
}
}
/**
* Forward for the base TileEntity's readFromNBT(), used for loading the state.
*
* @param tag Compound tag as supplied by TileEntity.readFromNBT()
*/
public void readFromNBT(NBTTagCompound tag) {
NBTTagCompound data = tag.getCompoundTag(getNbtTagName());
energyStored = data.getDouble("energy");
}
/**
* Forward for the base TileEntity's writeToNBT(), used for saving the state.
*
* @param tag Compound tag as supplied by TileEntity.writeToNBT()
*/
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
NBTTagCompound data = new NBTTagCompound();
data.setDouble("energy", energyStored);
tag.setTag(getNbtTagName(), data);
return tag;
}
// << in-world te forwards
// methods for using this adapter >>
/**
* Get the maximum amount of energy this sink can hold in its buffer.
*
* @return Capacity in EU.
*/
public double getCapacity() {
return capacity;
}
/**
* Set the maximum amount of energy this sink can hold in its buffer.
*
* @param capacity1 Capacity in EU.
*/
public void setCapacity(double capacity) {
this.capacity = capacity;
}
/**
* Determine the energy stored in this buffer.
*
* @return amount in EU, may be above capacity
*/
public double getEnergyStored() {
return energyStored;
}
/**
* Set the stored energy to the specified amount.
*
* This is intended for server -> client synchronization, e.g. to display the stored energy in
* a GUI through getEnergyStored().
*
* @param amount
*/
public void setEnergyStored(double amount) {
energyStored = amount;
}
/**
* Determine the free capacity in this buffer.
*
* @return amount in EU
*/
public double getFreeCapacity() {
return capacity - energyStored;
}
/**
* Add some energy to the output buffer.
*
* @param amount maximum amount of energy to add
* @return amount added/used, NOT remaining
*/
public double addEnergy(double amount) {
if (getWorldObj().isRemote) return 0;
if (amount > capacity - energyStored) amount = capacity - energyStored;
energyStored += amount;
return amount;
}
/**
* Determine if the specified amount of energy is available.
*
* @param amount in EU
* @return true if the amount is available
*/
public boolean canUseEnergy(double amount) {
return energyStored >= amount;
}
/**
* Use the specified amount of energy, if available.
*
* @param amount amount to use
* @return true if the amount was available
*/
public boolean useEnergy(double amount) {
if (!canUseEnergy(amount) || getWorldObj().isRemote) return false;
energyStored -= amount;
return true;
}
/**
* Charge the supplied ItemStack from this energy buffer.
*
* @param stack ItemStack to charge (null is ignored)
* @return true if energy was transferred
*/
public boolean charge(ItemStack stack) {
if (stack == null || !Info.isIc2Available() || getWorldObj().isRemote) return false;
double amount = ElectricItem.manager.charge(stack, energyStored, Math.max(getSinkTier(), getSourceTier()), false, false);
energyStored -= amount;
return amount > 0;
}
/**
* Discharge the supplied ItemStack into this energy buffer.
*
* @param stack ItemStack to discharge (null is ignored)
* @param limit Transfer limit, values <= 0 will use the battery's limit
* @return true if energy was transferred
*/
public boolean discharge(ItemStack stack, double limit) {
if (stack == null || !Info.isIc2Available() || getWorldObj().isRemote) return false;
double amount = capacity - energyStored;
if (amount <= 0) return false;
if (limit > 0 && limit < amount) amount = limit;
amount = ElectricItem.manager.discharge(stack, amount, Math.max(getSinkTier(), getSourceTier()), limit > 0, true, false);
energyStored += amount;
return amount > 0;
}
// << methods for using this adapter
// ******************************
// *** Methods for use by ic2 ***
// ******************************
// ILocatable >>
@Override
public World getWorldObj() {
if (world == null) initLocation();
return world;
}
@Override
public BlockPos getPosition() {
if (pos == null) initLocation();
return pos;
}
private void initLocation() {
if (locationProvider instanceof ILocatable) {
ILocatable provider = (ILocatable) locationProvider;
world = provider.getWorldObj();
pos = provider.getPosition();
} else if (locationProvider instanceof TileEntity) {
TileEntity provider = (TileEntity) locationProvider;
world = provider.getWorld();
pos = provider.getPos();
} else {
throw new IllegalStateException("no/incompatible location provider");
}
}
// << ILocatable
protected abstract String getNbtTagName();
protected int getSinkTier() {
return 0;
}
protected int getSourceTier() {
return 0;
}
private final Object locationProvider;
protected World world;
protected BlockPos pos;
protected double capacity;
protected double energyStored;
protected boolean addedToEnet;
}
Binary file not shown.
@@ -0,0 +1,155 @@
package ic2.api.energy.prefab;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import ic2.api.energy.tile.IEnergyEmitter;
import ic2.api.energy.tile.IEnergySink;
import ic2.api.info.ILocatable;
/**
* BasicSink is a simple delegate to provide an ic2 energy sink.
*
* <p>It's designed to be attached to a tile entity as a delegate. Functionally BasicSink acts as a
* one-time configurable input energy buffer, thus providing a common use case for machines.
*
* <p>A simpler alternative is to use {@link BasicSinkTe.Sink}, which requires injecting into the
* type hierarchy (using it as a super class). BasicSink however can be added to any class without
* inheritance, but needs some forwards for keeping its state and registering with the energy net.
*
* <p>The constraints set by BasicSink like the strict tank-like energy buffering should provide a
* more easy to use and stable interface than using IEnergySink directly while aiming for
* optimal performance.
*
* <p>Using BasicSink involves the following steps:<ul>
* <li>create a BasicSink instance in your TileEntity, typically in a field
* <li>forward onLoad (or update), invalidate, onChunkUnload, readFromNBT and writeToNBT to the BasicSink
* instance.
* <li>call useEnergy whenever appropriate. canUseEnergy determines if enough energy is available
* without consuming the energy.
* <li>optionally use getEnergyStored to display the output buffer charge level
* <li>optionally use setEnergyStored to sync the stored energy to the client (e.g. in the Container)</ul>
*
* <p>Example implementation code:
* <pre><code>
* public class SomeTileEntity extends TileEntity {
* // new basic energy sink, 1000 EU buffer, tier 1 (32 EU/t, LV)
* private BasicSink ic2EnergySink = new BasicSink(this, 1000, 1);
*
* {@literal @}Override
* public void onLoad() {
* ic2EnergySink.onLoad(); // notify the energy sink
* ...
* }
*
* {@literal @}Override
* public void invalidate() {
* ic2EnergySink.invalidate(); // notify the energy sink
* ...
* super.invalidate(); // this is important for mc!
* }
*
* {@literal @}Override
* public void onChunkUnload() {
* ic2EnergySink.onChunkUnload(); // notify the energy sink
* ...
* }
*
* {@literal @}Override
* public void readFromNBT(NBTTagCompound tag) {
* super.readFromNBT(tag);
*
* ic2EnergySink.readFromNBT(tag);
* ...
* }
*
* {@literal @}Override
* public void writeToNBT(NBTTagCompound tag) {
* super.writeToNBT(tag);
*
* ic2EnergySink.writeToNBT(tag);
* ...
* }
*
* {@literal @}Override
* public void update() {
* if (ic2EnergySink.useEnergy(5)) { // use 5 eu from the sink's buffer this tick
* ... // do something with the energy
* }
* ...
* }
*
* ...
* }
* </code></pre>
*/
public class BasicSink extends BasicEnergyTile implements IEnergySink {
/**
* Constructor for a new BasicSink delegate.
*
* @param parent TileEntity represented by this energy sink.
* @param capacity Maximum amount of eu to store.
* @param tier IC2 tier, 1 = LV, 2 = MV, ...
*/
public BasicSink(TileEntity parent, double capacity, int tier) {
super(parent, capacity);
this.tier = tier;
}
public BasicSink(ILocatable parent, double capacity, int tier) {
super(parent, capacity);
this.tier = tier;
}
public BasicSink(World world, BlockPos pos, double capacity, int tier) {
super(world, pos, capacity);
this.tier = tier;
}
/**
* Set the IC2 energy tier for this sink.
*
* @param tier IC2 Tier.
*/
public void setSinkTier(int tier) {
this.tier = tier;
}
// energy net interface >>
@Override
public boolean acceptsEnergyFrom(IEnergyEmitter emitter, EnumFacing direction) {
return true;
}
@Override
public double getDemandedEnergy() {
return Math.max(0, capacity - energyStored);
}
@Override
public double injectEnergy(EnumFacing directionFrom, double amount, double voltage) {
energyStored += amount;
return 0;
}
@Override
public int getSinkTier() {
return tier;
}
// << energy net interface
@Override
protected String getNbtTagName() {
return "IC2BasicSink";
}
protected int tier;
}
@@ -0,0 +1,116 @@
package ic2.api.energy.prefab;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import ic2.api.energy.EnergyNet;
import ic2.api.energy.tile.IEnergySink;
import ic2.api.energy.tile.IEnergySource;
import ic2.api.info.ILocatable;
/**
* Combination of BasicSink and BasicSource, see their respective documentation for details.
*
* <p>A subclass still has to implement acceptsEnergyFrom and emitsEnergyTo.
*/
public abstract class BasicSinkSource extends BasicEnergyTile implements IEnergySink, IEnergySource {
public BasicSinkSource(TileEntity parent, double capacity, int sinkTier, int sourceTier) {
super(parent, capacity);
this.sinkTier = sinkTier;
this.sourceTier = sourceTier;
this.sourcePower = EnergyNet.instance.getPowerFromTier(sourceTier);
if (getCapacity() < sourcePower) setCapacity(sourcePower);
}
public BasicSinkSource(ILocatable parent, double capacity, int sinkTier, int sourceTier) {
super(parent, capacity);
this.sinkTier = sinkTier;
this.sourceTier = sourceTier;
this.sourcePower = EnergyNet.instance.getPowerFromTier(sourceTier);
if (getCapacity() < sourcePower) setCapacity(sourcePower);
}
public BasicSinkSource(World world, BlockPos pos, double capacity, int sinkTier, int sourceTier) {
super(world, pos, capacity);
this.sinkTier = sinkTier;
this.sourceTier = sourceTier;
this.sourcePower = EnergyNet.instance.getPowerFromTier(sourceTier);
if (getCapacity() < sourcePower) setCapacity(sourcePower);
}
/**
* Set the IC2 energy tier for this sink.
*
* @param tier IC2 Tier.
*/
public void setSinkTier(int tier) {
this.sinkTier = tier;
}
/**
* Set the IC2 energy tier for this source.
*
* @param tier IC2 Tier.
*/
public void setSourceTier(int tier) {
double power = EnergyNet.instance.getPowerFromTier(tier);
if (getCapacity() < power) setCapacity(power);
this.sourceTier = tier;
this.sourcePower = power;
}
// energy net interface >>
@Override
public double getDemandedEnergy() {
return Math.max(0, capacity - energyStored);
}
@Override
public double injectEnergy(EnumFacing directionFrom, double amount, double voltage) {
energyStored += amount;
return 0;
}
@Override
public int getSinkTier() {
return sinkTier;
}
@Override
public double getOfferedEnergy() {
return Math.min(energyStored, sourcePower);
}
@Override
public void drawEnergy(double amount) {
energyStored -= amount;
}
@Override
public int getSourceTier() {
return sourceTier;
}
// << energy net interface
@Override
protected String getNbtTagName() {
return "IC2BasicSinkSource";
}
protected int sinkTier;
protected int sourceTier;
protected double sourcePower;
}
Binary file not shown.
@@ -0,0 +1,167 @@
package ic2.api.energy.prefab;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import ic2.api.energy.EnergyNet;
import ic2.api.energy.tile.IEnergyAcceptor;
import ic2.api.energy.tile.IEnergySource;
import ic2.api.info.ILocatable;
/**
* BasicSource is a simple delegate to add an ic2 energy source.
*
* <p>It's designed to be attached to a tile entity as a delegate. Functionally BasicSource acts as a
* one-time configurable output energy buffer, thus providing a common use case for generators.
*
* <p>A simpler alternative is to use {@link BasicSinkTe.Source}, which requires injecting into the
* type hierarchy (using it as a super class). BasicSource however can be added to any class without
* inheritance, but needs some forwards for keeping its state and registering with the energy net.
*
* <p>The constraints set by BasicSource like the strict tank-like energy buffering should provide a
* more easy to use and stable interface than using IEnergySource directly while aiming for
* optimal performance.
*
* <p>Using BasicSource involves the following steps:<ul>
* <li>create a BasicSource instance in your TileEntity, typically in a field
* <li>forward onLoad (or update), invalidate, onChunkUnload, readFromNBT ans writeToNBT to the BasicSource
* instance.
* <li>call addEnergy whenever appropriate, using getFreeCapacity may determine if e.g. the generator
* should run
* <li>optionally use getEnergyStored to display the output buffer charge level
* <li>optionally use setEnergyStored to sync the stored energy to the client (e.g. in the Container)</ul>
*
* <p>Example implementation code:
* <pre><code>
* public class SomeTileEntity extends TileEntity {
* // new basic energy source, 1000 EU buffer, tier 1 (32 EU/t, LV)
* private BasicSource ic2EnergySource = new BasicSource(this, 1000, 1);
*
* {@literal @}Override
* public void onLoad() {
* ic2EnergySource.onLoad(); // notify the energy source
* ...
* }
*
* {@literal @}Override
* public void invalidate() {
* ic2EnergySource.invalidate(); // notify the energy source
* ...
* super.invalidate(); // this is important for mc!
* }
*
* {@literal @}Override
* public void onChunkUnload() {
* ic2EnergySource.onChunkUnload(); // notify the energy source
* ...
* }
*
* {@literal @}Override
* public void readFromNBT(NBTTagCompound tag) {
* super.readFromNBT(tag);
*
* ic2EnergySource.readFromNBT(tag);
* ...
* }
*
* {@literal @}Override
* public void writeToNBT(NBTTagCompound tag) {
* super.writeToNBT(tag);
*
* ic2EnergySource.writeToNBT(tag);
* ...
* }
*
* {@literal @}Override
* public void update() {
* ic2EnergySource.addEnergy(5); // add 5 eu to the source's buffer this tick
* ...
* }
*
* ...
* }
* </code></pre>
*/
public class BasicSource extends BasicEnergyTile implements IEnergySource {
/**
* Constructor for a new BasicSource delegate.
*
* @param parent1 Base TileEntity represented by this energy source.
* @param capacity1 Maximum amount of eu to store.
* @param tier1 IC2 tier, 1 = LV, 2 = MV, ...
*/
public BasicSource(TileEntity parent, double capacity, int tier) {
super(parent, capacity);
this.tier = tier;
this.power = EnergyNet.instance.getPowerFromTier(tier);
if (getCapacity() < power) setCapacity(power);
}
public BasicSource(ILocatable parent, double capacity, int tier) {
super(parent, capacity);
this.tier = tier;
this.power = EnergyNet.instance.getPowerFromTier(tier);
if (getCapacity() < power) setCapacity(power);
}
public BasicSource(World world, BlockPos pos, double capacity, int tier) {
super(world, pos, capacity);
this.tier = tier;
this.power = EnergyNet.instance.getPowerFromTier(tier);
if (getCapacity() < power) setCapacity(power);
}
/**
* Set the IC2 energy tier for this source.
*
* @param tier1 IC2 Tier.
*/
public void setSourceTier(int tier) {
double power = EnergyNet.instance.getPowerFromTier(tier);
if (getCapacity() < power) setCapacity(power);
this.tier = tier;
this.power = power;
}
// energy net interface >>
@Override
public boolean emitsEnergyTo(IEnergyAcceptor receiver, EnumFacing direction) {
return true;
}
@Override
public double getOfferedEnergy() {
return Math.min(energyStored, power);
}
@Override
public void drawEnergy(double amount) {
energyStored -= amount;
}
@Override
public int getSourceTier() {
return tier;
}
// << energy net interface
@Override
protected String getNbtTagName() {
return "IC2BasicSource";
}
protected int tier;
protected double power;
}
+48 -75
View File
@@ -1,8 +1,7 @@
package ic2.api.info;
import java.util.Set;
import net.minecraft.block.material.Material;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
@@ -19,25 +18,14 @@ import ic2.api.tile.IWrenchable;
* by being able to extend it means all those methods you can now extend and be confident they will be called correctly.
* </p>
* <p>
* The more observant might have noticed there was an event that allowed you to do basically the same thing called <code>TeBlockBakeEvent</code>.
* Whilst that event used to add your own class onto <code>TeBlock</code> (that wasn't ideal as you could end up using the same ID as another addon which would cause a crash),
* this allows you to completely implement your own version of <code>TeBlock</code>, then let IC2 take it and build the necessary structures around it.
* Both mean you no longer have to use <code>EnumHelper</code> and lots of reflection to mess about with <code>TeBlock</code>,
* just to be left with either a crash from doing it too late/wrong, or lots of code bound to IC2 (such as language keys and blockstate jsons being in IC2's assets).
* </p>
* <p>
* Unlike <code>TeBlockBakeEvent</code>, this gives you near total control of your tile entities:
* Because it allows effectively level control to IC2 itself, this gives you near total control of your tile entities:
* <blockquote>
* You can pick whether each of your tile entity items show up in creative, and the order in which they do.<br/>
* You can choose whether you use an <code>enum</code> or <code>class</code> for your implementation.
* We use (and I personally recommend) using an <code>enum</code>, as the values should never change, but in the end the choice is yours.<br/>
* There is a proper separation between each registered <code>ITeBlock</code> by resource location, rather than everything being inserted into a single <code>enum</code>.
* You also receive your own instance of <code>BlockTileEntity</code> and <code>ItemBlockTileEntity</code> rather than having to use IC2's own one.<br/>
* All the language keys and blockstate file are in your own assets (which you can, and in fact have to, pick).
* You can have custom item models with non-standard model locations.
* </blockquote>
* It is a vast improvement over <code>TeBlockBakeEvent</code>, which is probably important as it's gone now ;)
* </p>
* <br/>
* The event allows you to properly register your own version of <code>TeBlock</code> in a way that will be as fully supported as is physically possible.
* It's not in the actual API itself as it's heavily dependent on internal classes, so you have this instead.
* This is also probably the most documented thing in the entire IC2 API. <small>I'm too kind really. ;)</small>
@@ -49,44 +37,42 @@ import ic2.api.tile.IWrenchable;
*import net.minecraftforge.common.MinecraftForge;
*import net.minecraftforge.fml.common.Mod;
*import net.minecraftforge.fml.common.Mod.EventHandler;
*import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
*import net.minecraftforge.fml.common.event.FMLConstructionEvent;
*import net.minecraftforge.fml.common.event.FMLInitializationEvent;
*
*{@literal @}Mod(modId="ExampleIC2Addon")
*public class ExampleIC2Addon {
* public ExampleIC2Addon() {
* //You have to register before IC2 reaches Pre-Initialization, which unless you specifically load before it is unlikely you'll achieve.
* //Especially if you're an addon, you'll want to be loading after IC2 not before!
* //But, your mod's constructor will definitely be called before then. The issue is it's called more than once.
* //If you try registering the same tile entity ID twice it will crash (more on that later), so you'll have to use a singleton instance.
* //An enum works well for this, but anything will work as long as it's registered to the event bus once, and only once.
* MinecraftForge.EVENT_BUS.register(TileEntityRegisterer.INSTANCE);
* }
*
* {@literal @}EventHandler
* public void preInit(FMLPreInitializationEvent event) {
* MyTeBlock.registerTileEntities();
* }
*
* {@literal @}EventHandler
* public void preInit(FMLInitializationEvent event) {
* MyTeBlock.buildDummies();
* }
*}
*import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
*
*import ic2.api.event.TeBlockFinalCallEvent;
*import ic2.core.block.TeBlockRegistry;
*import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
*
*public enum TileEntityRegisterer {
* INSTANCE;
*{@literal @}Mod(modId="ExampleIC2Addon")
*public class ExampleIC2Addon {
* {@literal @}EventHandler
* public void start(FMLConstructionEvent event) {
* MinecraftForge.EVENT_BUS.register(this);
* }
*
* {@literal @}SubscribeEvent
* public void register(TeBlockFinalCallEvent event) {
* TeBlockRegistry.addAll(MyTeBlock.class, MyTeBlock.IDENTITY);
*
* MinecraftForge.EVENT_BUS.unregister(this);
* }
*
* {@literal @}EventHandler
* public void init(FMLInitializationEvent event) {
* MyTeBlock.buildDummies();
* }
*}
*
*
*import net.minecraft.block.material.Material;
*import net.minecraft.creativetab.CreativeTabs;
*import net.minecraft.item.EnumRarity;
*import net.minecraft.item.ItemStack;
*import net.minecraft.tileentity.TileEntity;
*import net.minecraft.util.EnumFacing;
*import net.minecraft.util.ResourceLocation;
*
*import ic2.core.block.BlockTileEntity;
*import ic2.core.block.ITeBlock;
*import ic2.core.block.TileEntityBlock;
@@ -95,21 +81,14 @@ import ic2.api.tile.IWrenchable;
*import ic2.core.ref.TeBlock.HarvestTool;
*import ic2.core.ref.TeBlock.ITePlaceHandler;
*import ic2.core.util.Util;
*import net.minecraft.block.material.Material;
*import net.minecraft.creativetab.CreativeTabs;
*import net.minecraft.item.EnumRarity;
*import net.minecraft.item.ItemStack;
*import net.minecraft.tileentity.TileEntity;
*import net.minecraft.util.EnumFacing;
*import net.minecraft.util.ResourceLocation;
*
*public enum MyTeBlock implements ITeBlock {
* my_machine_name(MyMachineTileEntity.class, 0, false, Util.noFacings, false, HarvestTool.Pickaxe, DefaultDrop.Machine, 5, 10, EnumRarity.UNCOMMON, Material.IRON);
* my_machine_name(MyMachineTileEntity.class, 0, false, Util.noFacings, false, HarvestTool.Pickaxe, DefaultDrop.Machine, 5, 10, EnumRarity.UNCOMMON, Material.IRON, false);
*
* private MyTeBlock(Class<? extends TileEntityBlock> teClass, int ID,
* boolean hasActive, Set{@literal <}EnumFacing{@literal >} possibleFacings, boolean canBeWrenched,
* HarvestTool tool, DefaultDrop drop,
* float hardness, float explosionResistance, EnumRarity rarity, Material material) {
* float hardness, float explosionResistance, EnumRarity rarity, Material material, boolean isTransparent) {
* this.teClass = teClass;
* this.ID = ID;
* this.hasActive = hasActive;
@@ -121,6 +100,9 @@ import ic2.api.tile.IWrenchable;
* this.explosionResistance = explosionResistance;
* this.rarity = rarity;
* this.material = material;
* this.isTransparent = isTransparent;
*
* TileEntity.addMapping(block.teClass, IDENTITY.getResourceDomain() + ':' + block.getName());
* }
*
* {@literal @}Override
@@ -194,12 +176,8 @@ import ic2.api.tile.IWrenchable;
* }
*
* {@literal @}Override
* public void addSubBlocks(List{@literal <}ItemStack{@literal >} list, BlockTileEntity block, ItemBlockTileEntity item, CreativeTabs tab) {
* for (MyTeBlock block : values()) {
* if (type.hasItem()) {
* list.add(block.getItemStack(type));
* }
* }
* public boolean isTransparent() {
* return isTransparent;
* }
*
* {@literal @}Override
@@ -212,15 +190,9 @@ import ic2.api.tile.IWrenchable;
* return placeHandler;
* }
*
* public static void registerTileEntities() {
* for (MyTeBlock block : values()) {
* if (block.teClass != null) TileEntity.addMapping(block.teClass, IDENTITY.getResourceDomain() + ':' + block.getName());
* }
* }
*
* public static void buildDummies() {
* for (MyTeBlock block : values()) {
* //System.out.printf("Registering %s (with teClass %s)%n", block.getName(), block.teClass);
* //System.out.printf("Building %s (with teClass %s)%n", block.getName(), block.teClass);
* if (block.teClass != null) {
* try {
* block.dummyTe = block.teClass.newInstance();
@@ -247,6 +219,7 @@ import ic2.api.tile.IWrenchable;
* private final float explosionResistance;
* private final EnumRarity rarity;
* private final Material material;
* private final boolean isTransparent;
* private TileEntityBlock dummyTe;
* private ITePlaceHandler placeHandler;
*
@@ -275,7 +248,7 @@ import ic2.api.tile.IWrenchable;
* <li><b>itemMeta</b>: The ID of the new instance. This is utterly critical, as it's the thing used to detect which <code>ITeBlock</code> an item is.
* That's very important as the tile entity class is worked out by the ID when a block's being placed in <code>ItemBlockTileEntity</code>.
* Changing this will cause everyone's items to change and there is no stopping that if you do.
* The ID you pick should start at 0, and go up to Short.MAX_VALUE.
* The ID you pick should start at 0, and go up to {@link Short#MAX_VALUE}.
* Use -1 if the tile entity doesn't have an item form (or is placed using an item other than <code>ItemBlockTileEntity</code>).</li>
* <li><b>identifier</b>: The resource location associated with the <code>ITeBlock</code>.
* The language keys, translations and internal mappings all use this, so it's best to store it as a static final variable and use that.
@@ -291,16 +264,13 @@ import ic2.api.tile.IWrenchable;
* <li><b>hardness</b>: The hardness the block should have with the tile entity, IC2 normally uses 5.</li>
* <li><b>explosionResistance</b>: The explosionResistance the block should have with the tile entity, IC2 normally uses 10.</li>
* <li><b>rarity</b>: The <code>EnumRarity</code> that the item will have for the tile entity.</li>
* <li><b>material</b>: The {@link Material} that the block representing the tile entity should have. Maximum of 16 different ones per ITeBlock registration.</li>
* <li><b>material</b>: The {@link Material} that the block representing the tile entity should have. Maximum of 8 different ones per ITeBlock registration.</li>
* <li><b>isTransparent</b>: Whether the block should be rendered with {@link BlockRenderLayer#CUTOUT} or {@link BlockRenderLayer#SOLID}
* (which controls whether transparency can be in the texture).</li>
* <li><b>placeHandler</b>: Custom placement logic, used for things like Reactor Chambers within IC2 itself.
* Returning null for this uses the default logic (placing like a normal block).</li>
* <li><b>dummyTe</b>: An instance of the tile entity never registered to the world (don't try doing that) used for getting additional information about the Tile Entity.
* Mostly an internal thing, only exposed in case your Tile Entity uses a special constructor.</li>
*
* <li><b>addSubBlocks</b>: Called by <code>BlockTileEntity</code> to add all the <code>ITeBlock</code>s you want to the creative menu.
* {@link BlockTileEntity#getItemStack(ITeBlock)} will be a useful method to get the item stack, a block instance is passed for that reason.
* This is only called once on a random <code>ITeBlock</code> for the resource location, because they are internally stored in a {@link Set} so has no order.
* Will probably be changed to a static method if/when the move is made to only Java 8 support.
* </ul>
* <strong>IMPORTANT THINGS TO NOTE</strong>
* <dl>
@@ -309,15 +279,17 @@ import ic2.api.tile.IWrenchable;
* For <code>ItemBlockTileEntity</code>, use {@link BlockTileEntity#getItem()}.</dd>
* <dt>Using a custom item model for your <code>ITeBlock</code></dt>
* <dd>Implement <code>ITeBlockSpecialItem</code> along with <code>ITeBlock</code>, then the item model will be what's provided rather than the block model.</dd>
* <dt>The default implementation for adding <code>ITeBlock</code>s to creative</dt>
* <dd>The default logic adds all registered <code>ITeBlock</code>s that return true for {@link ic2.core.ref.TeBlock#hasItem()}.</dd>
* </dl>
* More will be added to this list if questions keep re-occurring, or are about a suitably important topic.
* </p>
* <hr>
* <p>
* There, that should be everything you need to utilise <code>ITeBlock</code> to add your own tile entities using IC2's very flexible framework.
* I'll be happy to answer any questions you have on it, your best bet is to ask me (Chocohead) on <a href="http://forum.industrial-craft.net">the IC2 forums</a>,
* I'll be happy to answer any questions you have on it, your best bet is to ask me (Chocohead) on <a href="https://forum.industrial-craft.net">the IC2 forums</a>,
* although if you post in the support section other people might be able to help before I see your post.
* I'll certainly take suggestions too, this is a first version of <code>ITeBlock</code>, so I'm sure there could be improvements made.
* I'll certainly take suggestions too, this is mostly just based on what IC2 uses/needs, so there might well be things missed that might be useful.
* <br/>
* <small>Goodness I spent too long on this again...</small>
* </p>
@@ -327,16 +299,17 @@ import ic2.api.tile.IWrenchable;
* @see {@link ic2.core.ref.TeBlock} for how all the IC2 implements {@link ITeBlock}.
* @see {@link ic2.core.ref.TeBlock.HarvestTool} for the currently available tools (you'll need this for adding new tile entities).
* @see {@link ic2.core.ref.TeBlock.DefaultDrop} for the currently available drops (you'll need this for adding new tile entities too).
* @see {@link ic2.core.block.ITeBlock.ITeBlockCreativeRegisterer} for customising what blocks are added to creative past the default implementation
* @see {@link ic2.core.ref.TeBlock.ITePlaceHandler} for making your own block placement handler (example in {@link ic2.core.item.ItemHandlers#reactorChamberPlace}).
* @see {@link ic2.core.util.Util} for the useful facings you might want for <code>supportedFacings</code>.
* @see {@link ic2.core.block.TileEntityBlock} for the base tile entity.
* @see {@link ic2.core.block.BlockTileEntity} for the base block (you'll never need to construct this yourself).
* @see {@link ic2.core.item.block.ItemBlockTileEntity} for the base item (you'll never need to construct this yourself either).
* @see {@link ic2.core.item.block.ItemBlockTileEntity} for the base item (you shouldn't need to construct this yourself either).
* @see {@link ITeBlockSpecialItem} for the interface used to have a custom item location.
*
*
* @since IC2 2.6.114
* @version 1.2
* @since IC2 2.7.14
* @version 2.0
*
* @author Chocohead
*/
Binary file not shown.
+2 -1
View File
@@ -25,7 +25,7 @@ public class Info {
public static boolean isIc2Available() {
if (ic2Available != null) return ic2Available;
boolean loaded = Loader.isModLoaded("IC2");
boolean loaded = Loader.isModLoaded(MOD_ID);
if (Loader.instance().hasReachedState(LoaderState.CONSTRUCTING)) {
ic2Available = loaded;
@@ -34,5 +34,6 @@ public class Info {
return loaded;
}
public static String MOD_ID = "ic2";
private static Boolean ic2Available = null;
}
Binary file not shown.
+3 -1
View File
@@ -5,6 +5,8 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import ic2.api.info.Info;
/**
* Provides access to IC2 blocks and items.
@@ -75,7 +77,7 @@ public final class IC2Items {
public static void setInstance(IItemAPI api) {
ModContainer mc = Loader.instance().activeModContainer();
if (mc == null || !"IC2".equals(mc.getModId())) {
if (mc == null || !Info.MOD_ID.equals(mc.getModId())) {
throw new IllegalAccessError("invoked from "+mc);
}
@@ -94,7 +94,7 @@ public interface IElectricItemManager {
*
* @param stack electric item's stack
* @param amount amount of energy to discharge in EU
* @param entity entity holding the item
* @param entity entity holding the item, may be null
* @return true if the operation succeeded
*/
boolean use(ItemStack stack, double amount, EntityLivingBase entity);
Binary file not shown.
@@ -8,7 +8,7 @@ import net.minecraft.item.ItemStack;
*
* @author Chocohead
*/
public interface IItemHudProvider extends IElectricItem {
public interface IItemHudProvider {
/**
* Whether the given stack should display the HUD overlay.
*
Binary file not shown.
@@ -9,6 +9,8 @@ import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.relauncher.Side;
import ic2.api.info.Info;
/**
* Provides methods to initiate events and synchronize tile entity fields in SMP.
*
@@ -158,7 +160,7 @@ public final class NetworkHelper {
*/
public static void setInstance(INetworkManager server, INetworkManager client) {
ModContainer mc = Loader.instance().activeModContainer();
if (mc == null || !"IC2".equals(mc.getModId())) {
if (mc == null || !Info.MOD_ID.equals(mc.getModId())) {
throw new IllegalAccessError();
}
serverInstance = server;
Binary file not shown.
@@ -2,8 +2,6 @@ package ic2.api.reactor;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import ic2.api.info.ILocatable;
@@ -20,28 +18,6 @@ public interface IReactor extends ILocatable {
*/
public TileEntity getCoreTe();
/**
* Return the reactor's current world instance (it's position can be acquired using {@link #getReactorPos()}.
* <br/>
* Should be the same world as {@link #getCoreTe()} returns if it's not null.
* @deprecated See {@link #getWorldObj()}
*
* @return The reactor's world object
*/
@Deprecated //TODO: remove for 1.11
public World getReactorWorld(); //getWorld has obfuscation issues (https://github.com/md-5/SpecialSource/issues/12)
/**
* Return the reactor's current position in the world ({@link #getReactorWorld()}.
* <br/>
* Should be the same position as {@link #getCoreTe()} returns if it's not null.
* @deprecated See {@link #getPosition()}
*
* @return The reactor's current position
*/
@Deprecated //TODO: remove for 1.11
public BlockPos getReactorPos(); //As would getPos
/**
* Get the reactor's heat.
*
@@ -0,0 +1,13 @@
package ic2.api.recipe;
import java.util.Collection;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public interface IBasicMachineRecipeManager extends IMachineRecipeManager<IRecipeInput, Collection<ItemStack>, ItemStack> {
boolean addRecipe(IRecipeInput input, NBTTagCompound metadata, boolean replace, ItemStack... outputs);
@Deprecated
RecipeOutput getOutputFor(ItemStack input, boolean adjustInput);
}
@@ -1,51 +1,57 @@
package ic2.api.recipe;
import java.util.Map;
import net.minecraft.item.ItemStack;
public interface ICannerBottleRecipeManager {
import ic2.api.recipe.ICannerBottleRecipeManager.Input;
import ic2.api.recipe.ICannerBottleRecipeManager.RawInput;
public interface ICannerBottleRecipeManager extends IMachineRecipeManager<Input, ItemStack, RawInput> {
/**
* Adds a recipe to the machine.
*
*
* @param container Container to be filled
* @param fill Item to fill into the container
* @param output Filled container
* @return
*/
public void addRecipe(IRecipeInput container, IRecipeInput fill, ItemStack output);
boolean addRecipe(IRecipeInput container, IRecipeInput fill, ItemStack output, boolean replace);
@Deprecated
void addRecipe(IRecipeInput container, IRecipeInput fill, ItemStack output);
/**
* Gets the recipe output for the given input.
*
*
* @param container Container to be filled
* @param fill Item to fill into the container
* @param adjustInput modify the input according to the recipe's requirements
* @param acceptTest allow either container or fill to be null to see if either of them is part of a recipe
* @return Recipe output, or null if none
*/
public RecipeOutput getOutputFor(ItemStack container, ItemStack fill, boolean adjustInput, boolean acceptTest);
/**
* Gets a list of recipes.
*
* You're a mad evil scientist if you ever modify this.
*
* @return List of recipes
*/
public Map<Input, RecipeOutput> getRecipes();
@Deprecated
RecipeOutput getOutputFor(ItemStack container, ItemStack fill, boolean adjustInput, boolean acceptTest);
public static class Input {
public Input(IRecipeInput container1, IRecipeInput fill1) {
this.container = container1;
this.fill = fill1;
public Input(IRecipeInput container, IRecipeInput fill) {
this.container = container;
this.fill = fill;
}
public boolean matches(ItemStack container1, ItemStack fill1) {
return this.container.matches(container1) && this.fill.matches(fill1);
public boolean matches(ItemStack container, ItemStack fill) {
return this.container.matches(container) && this.fill.matches(fill);
}
public final IRecipeInput container;
public final IRecipeInput fill;
}
public static class RawInput {
public RawInput(ItemStack container, ItemStack fill) {
this.container = container;
this.fill = fill;
}
public final ItemStack container;
public final ItemStack fill;
}
}
@@ -1,54 +1,56 @@
package ic2.api.recipe;
import java.util.Map;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
public interface ICannerEnrichRecipeManager {
import ic2.api.recipe.ICannerEnrichRecipeManager.Input;
import ic2.api.recipe.ICannerEnrichRecipeManager.RawInput;
public interface ICannerEnrichRecipeManager extends IMachineRecipeManager<Input, FluidStack, RawInput> {
/**
* Adds a recipe to the machine.
*
*
* @param input Fluid input
* @param additive Item to enrich the fluid with
* @param output Output fluid
*/
@Deprecated
public void addRecipe(FluidStack input, IRecipeInput additive, FluidStack output);
/**
* Gets the recipe output for the given input.
*
*
* @param input Fluid input
* @param additive Item to enrich the fluid with
* @param adjustInput modify the input according to the recipe's requirements
* @param acceptTest allow input or additive to be null to see if either of them is part of a recipe
* @return Recipe output, or null if none, output fluid in nbt
*/
@Deprecated
public RecipeOutput getOutputFor(FluidStack input, ItemStack additive, boolean adjustInput, boolean acceptTest);
/**
* Gets a list of recipes.
*
* You're a mad evil scientist if you ever modify this.
*
* @return List of recipes
*/
public Map<Input, FluidStack> getRecipes();
public static class Input {
public Input(FluidStack fluid1, IRecipeInput additive1) {
this.fluid = fluid1;
this.additive = additive1;
public Input(FluidStack fluid, IRecipeInput additive) {
this.fluid = fluid;
this.additive = additive;
}
public boolean matches(FluidStack fluid1, ItemStack additive1) {
return (this.fluid == null || this.fluid.isFluidEqual(fluid1)) &&
this.additive.matches(additive1);
public boolean matches(FluidStack fluid, ItemStack additive) {
return this.fluid.isFluidEqual(fluid) && this.additive.matches(additive);
}
public final FluidStack fluid;
public final IRecipeInput additive;
}
public static class RawInput {
public RawInput(FluidStack fluid, ItemStack additive) {
this.fluid = fluid;
this.additive = additive;
}
public final FluidStack fluid;
public final ItemStack additive;
}
}
@@ -4,23 +4,42 @@ import net.minecraft.item.ItemStack;
/**
* Recipe manager interface for crafting recipes.
*
*
* @author Richard
*/
public interface ICraftingRecipeManager {
/**
* Adds a shaped crafting recipe.
*
*
* @param output Recipe output
* @param input Recipe input format
*/
public void addRecipe(ItemStack output, Object... input);
/**
* Adds a shapeless crafting recipe.
*
*
* @param output Recipe output
* @param input Recipe input
*/
public void addShapelessRecipe(ItemStack output, Object... input);
}
/**
* Attribute container to pass additional information to AdvRecipe and AdvShapelessRecipe
*
* @author Chocohead
*/
public static class AttributeContainer {
public final boolean hidden;
public final boolean consuming;
/**
* @param hidden Whether the recipe is hidden from JEI by default
* @param consuming Whether containers should be consumed or returned empty
*/
public AttributeContainer(boolean hidden, boolean consuming) {
this.hidden = hidden;
this.consuming = consuming;
}
}
}
@@ -0,0 +1,25 @@
package ic2.api.recipe;
import java.util.Collection;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import ic2.api.recipe.IEmptyFluidContainerRecipeManager.Output;
import ic2.api.util.FluidContainerOutputMode;
public interface IEmptyFluidContainerRecipeManager extends IMachineRecipeManager<Void, Output, ItemStack> {
MachineRecipeResult<Void, Output, ItemStack> apply(ItemStack input, Fluid requiredFluid, FluidContainerOutputMode outputMode, boolean acceptTest);
public static class Output {
public Output(Collection<ItemStack> container, FluidStack fluid) {
this.container = container;
this.fluid = fluid;
}
public final Collection<ItemStack> container;
public final FluidStack fluid;
}
}
@@ -0,0 +1,24 @@
package ic2.api.recipe;
import java.util.Collection;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import ic2.api.recipe.IFillFluidContainerRecipeManager.Input;
import ic2.api.util.FluidContainerOutputMode;
public interface IFillFluidContainerRecipeManager extends IMachineRecipeManager<Void, Collection<ItemStack>, Input> {
MachineRecipeResult<Void, Collection<ItemStack>, Input> apply(Input input, FluidContainerOutputMode outputMode, boolean acceptTest);
public static class Input {
public Input(ItemStack container, FluidStack fluid) {
this.container = container;
this.fluid = fluid;
}
public final ItemStack container;
public final FluidStack fluid;
}
}
@@ -1,60 +0,0 @@
package ic2.api.recipe;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
/**
* Recipe manager interface for machines that will probably never be added.
*
* @author estebes, Player
*/
public interface IFluidRecipeManager {
/**
* Adds a recipe to the machine.
*
* @param input Fluid input
* @param output Output fluid
*/
public boolean addRecipe(IRecipeInput input, NBTTagCompound metadata, boolean replace, FluidStack... output);
/**
* Gets the recipe output for the given input.
*
* @param input Fluid input
* @param adjustInput modify the input according to the recipe's requirements
* @return Recipe output, or null if none, output fluid in nbt
*/
public RecipeOutputFluid getOutputFor(ItemStack input, boolean adjustInput);
/**
* Get all registered recipes (optional operation).
*
* The method is only available if {@link #isIterable()} is true.
* You're a mad evil scientist if you ever modify this.
*
* @return Iterable of all recipes registered to the manager.
* @throws UnsupportedOperationException if {@link #isIterable()} is false.
*/
public Iterable<RecipeIoContainerFluid> getRecipes();
/**
* Determine whether the recipes can be iterated.
*
* @return true if {@link #getRecipes()} is implemented, false otherwise.
*/
public boolean isIterable();
public static class RecipeIoContainerFluid {
public RecipeIoContainerFluid(IRecipeInput input, RecipeOutputFluid output) {
this.input = input;
this.output = output;
}
public final IRecipeInput input;
public final RecipeOutputFluid output;
}
}
@@ -1,6 +1,5 @@
package ic2.api.recipe;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
/**
@@ -8,7 +7,7 @@ import net.minecraft.nbt.NBTTagCompound;
*
* @author Player, RichardG
*/
public interface IMachineRecipeManager {
public interface IMachineRecipeManager<RI, RO, I> {
/**
* Adds a recipe to the machine.
*
@@ -19,21 +18,23 @@ public interface IMachineRecipeManager {
* @note Replace is only as reliable as IRecipeInput.getInputs().
*
* @param input Recipe input
* @param output Recipe outputs, zero or more depending on the machine.
* @param metadata Meta data for additional recipe properties, may be null.
* @param replace Replace conflicting existing recipes, not recommended, may be ignored.
* @param outputs Recipe outputs, zero or more depending on the machine.
* @return true on success, false otherwise, e.g. on conflicts.
*/
public boolean addRecipe(IRecipeInput input, NBTTagCompound metadata, boolean replace, ItemStack... outputs);
boolean addRecipe(RI input, RO output, NBTTagCompound metadata, boolean replace);
/**
* Gets the recipe output for the given input.
* Gets the recipe result for the given input.
*
* @param input Recipe input
* @param adjustInput modify the input according to the recipe's requirements
* @return Recipe output, or null if none
* @param input Recipe input (not modified)
* @param acceptTest If true the manager will accept partially missing ingredients or
* ingredients with insufficient quantities. This is primarily used to check whether a
* slot/tank/etc can accept the input while trying to supply a machine with resources.
* @return Recipe result, or null if none
*/
public RecipeOutput getOutputFor(ItemStack input, boolean adjustInput);
MachineRecipeResult<RI, RO, I> apply(I input, boolean acceptTest);
/**
* Get all registered recipes (optional operation).
@@ -44,23 +45,12 @@ public interface IMachineRecipeManager {
* @return Iterable of all recipes registered to the manager.
* @throws UnsupportedOperationException if {@link #isIterable()} is false.
*/
public Iterable<RecipeIoContainer> getRecipes();
Iterable<? extends MachineRecipe<RI, RO>> getRecipes();
/**
* Determine whether the recipes can be iterated.
*
* @return true if {@link #getRecipes()} is implemented, false otherwise.
*/
public boolean isIterable();
public static class RecipeIoContainer {
public RecipeIoContainer(IRecipeInput input, RecipeOutput output) {
this.input = input;
this.output = output;
}
public final IRecipeInput input;
public final RecipeOutput output;
}
boolean isIterable();
}
Binary file not shown.
@@ -4,7 +4,7 @@ import java.util.Map;
import net.minecraft.item.ItemStack;
public interface IScrapboxManager {
public interface IScrapboxManager extends IBasicMachineRecipeManager {
void addDrop(ItemStack drop, float rawChance);
ItemStack getDrop(ItemStack input, boolean adjustInput);
Binary file not shown.
@@ -0,0 +1,35 @@
package ic2.api.recipe;
import net.minecraft.nbt.NBTTagCompound;
public class MachineRecipe<I, O> {
public MachineRecipe(I input, O output) {
this(input, output, null);
}
public MachineRecipe(I input, O output, NBTTagCompound meta) {
this.input = input;
this.output = output;
this.meta = meta;
}
public I getInput() {
return input;
}
public O getOutput() {
return output;
}
public NBTTagCompound getMetaData() {
return meta;
}
public <AI> MachineRecipeResult<I, O, AI> getResult(AI adjustedInput) {
return new MachineRecipeResult<I, O, AI>(this, adjustedInput);
}
private final I input;
private final O output;
private final NBTTagCompound meta;
}
@@ -0,0 +1,23 @@
package ic2.api.recipe;
public class MachineRecipeResult<RI, RO, I> {
public MachineRecipeResult(MachineRecipe<RI, RO> recipe, I adjustedInput) {
this.recipe = recipe;
this.adjustedInput = adjustedInput;
}
public MachineRecipe<RI, RO> getRecipe() {
return recipe;
}
public RO getOutput() {
return recipe.getOutput();
}
public I getAdjustedInput() {
return adjustedInput;
}
private final MachineRecipe<RI, RO> recipe;
private final I adjustedInput;
}
@@ -1,68 +0,0 @@
package ic2.api.recipe;
import ic2.api.item.IC2Items;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
/**
* @deprecated Use {@link Recipes#inputFactory} instead.
*/
@Deprecated
public class RecipeInputFluidContainer implements IRecipeInput {
public RecipeInputFluidContainer(Fluid fluid) {
this(fluid, Fluid.BUCKET_VOLUME);
}
public RecipeInputFluidContainer(Fluid fluid, int amount) {
this.fluid = fluid;
this.amount = amount;
}
@Override
public boolean matches(ItemStack subject) {
/*FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(subject);
if (fs == null && subject.getItem() instanceof IFluidContainerItem) {
IFluidContainerItem item = (IFluidContainerItem)subject.getItem();
fs = item.getFluid(subject);
}
// match amount precisely to avoid having to deal with leftover
return fs == null && fluid == null ||
fs != null && fs.getFluid() == fluid && fs.amount >= amount;*/
return false;
}
@Override
public int getAmount() {
return amount;
}
@Override
public List<ItemStack> getInputs() {
List<ItemStack> ret = new ArrayList<ItemStack>();
/*for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) {
if (data.fluid.getFluid() != fluid) continue;
ret.add(RecipeUtil.setImmutableSize(data.filledContainer, getAmount()));
}*/
ret.add(RecipeUtil.setImmutableSize(IC2Items.getItem("fluid_cell", fluid.getName()), getAmount()));
return Collections.unmodifiableList(ret);
}
@Override
public String toString() {
return "RInputFluidContainer<"+amount+"x"+fluid.getName()+">";
}
public final Fluid fluid;
public final int amount;
}
@@ -1,51 +0,0 @@
package ic2.api.recipe;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
/**
* @deprecated Use {@link Recipes#inputFactory} instead.
*/
@Deprecated
public class RecipeInputItemStack implements IRecipeInput {
public RecipeInputItemStack(ItemStack input) {
this(input, input.getCount());
}
public RecipeInputItemStack(ItemStack input, int amount) {
if (input.getItem() == null) throw new IllegalArgumentException("Invalid item stack specfied");
this.input = input.copy(); // Never forget to copy.
this.amount = amount;
}
@Override
public boolean matches(ItemStack subject) {
return subject.getItem() == input.getItem() && // Item matching
(subject.getMetadata() == input.getMetadata() || input.getMetadata() == OreDictionary.WILDCARD_VALUE) && //meta matching
(input.getMetadata() == OreDictionary.WILDCARD_VALUE || RecipeUtil.matchesNBT(subject.getTagCompound(), input.getTagCompound())); //nbt matching.
}
@Override
public int getAmount() {
return amount;
}
@Override
public List<ItemStack> getInputs() {
return Collections.unmodifiableList(Arrays.asList(RecipeUtil.setImmutableSize(input, getAmount())));
}
@Override
public String toString() {
return "RInputItemStack<"+RecipeUtil.setImmutableSize(input, amount)+">";
}
public final ItemStack input;
public final int amount;
}
Binary file not shown.
@@ -1,110 +0,0 @@
package ic2.api.recipe;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
/**
* @deprecated Use {@link Recipes#inputFactory} instead.
*/
@Deprecated
public class RecipeInputOreDict implements IRecipeInput {
public RecipeInputOreDict(String input) {
this(input, 1);
}
public RecipeInputOreDict(String input, int amount) {
this(input, amount, null);
}
public RecipeInputOreDict(String input, int amount, Integer meta) {
this.input = input;
this.amount = amount;
this.meta = meta;
}
@Override
public boolean matches(ItemStack subject) {
List<ItemStack> inputs = getOres();
boolean useOreStackMeta = (meta == null);
Item subjectItem = subject.getItem();
int subjectMeta = subject.getItemDamage();
for (ItemStack oreStack : inputs) {
Item oreItem = oreStack.getItem();
if (oreItem == null) continue; // ignore invalid
int metaRequired = useOreStackMeta ? oreStack.getItemDamage() : meta;
if (subjectItem == oreItem &&
(subjectMeta == metaRequired || metaRequired == OreDictionary.WILDCARD_VALUE)) {
return true;
}
}
return false;
}
@Override
public int getAmount() {
return amount;
}
@Override
public List<ItemStack> getInputs() {
List<ItemStack> ores = getOres();
// check if we have to filter the list first
boolean hasUnsuitableEntries = false;
for (ItemStack stack : ores) {
if (stack.getItem() == null || stack.getCount() != getAmount()) {
hasUnsuitableEntries = true;
break;
}
}
if (!hasUnsuitableEntries) return ores;
List<ItemStack> ret = new ArrayList<ItemStack>(ores.size());
for (ItemStack stack : ores) {
if (stack.getItem() != null) { // ignore invalid
ret.add(RecipeUtil.setImmutableSize(stack, getAmount()));
}
}
return Collections.unmodifiableList(ret);
}
@Override
public String toString() {
if (meta == null) {
return "RInputOreDict<"+amount+"x"+input+">";
} else {
return "RInputOreDict<"+amount+"x"+input+"@"+meta+">";
}
}
private List<ItemStack> getOres() {
if (ores != null) return ores;
// cache the ore list by making use of the fact that forge always uses the same list,
// unless it's EMPTY_LIST, which should never happen.
List<ItemStack> ret = OreDictionary.getOres(input);
if (ret != OreDictionary.EMPTY_LIST) ores = ret;
return ret;
}
public final String input;
public final int amount;
public final Integer meta;
private List<ItemStack> ores;
}
Binary file not shown.
@@ -7,6 +7,7 @@ import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@Deprecated
public final class RecipeOutput {
public RecipeOutput(NBTTagCompound metadata1, List<ItemStack> items1) {
assert !items1.contains(null);
Binary file not shown.
@@ -1,57 +0,0 @@
package ic2.api.recipe;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
/**
* @author estebes
*/
public class RecipeOutputFluid {
public RecipeOutputFluid(NBTTagCompound metadata, List<FluidStack> outputs) {
assert !outputs.contains(null);
this.metadata = metadata;
this.outputs = outputs;
}
public RecipeOutputFluid(NBTTagCompound metadata, FluidStack... outputs) {
this(metadata, Arrays.asList(outputs));
}
@Override
public boolean equals(Object obj) {
if (obj instanceof RecipeOutputFluid) {
RecipeOutputFluid ro = (RecipeOutputFluid) obj;
if (outputs.size() == ro.outputs.size() &&
(metadata == null && ro.metadata == null || metadata != null && ro.metadata != null && metadata.equals(ro.metadata))) {
Iterator<FluidStack> itA = outputs.iterator();
Iterator<FluidStack> itB = ro.outputs.iterator();
while (itA.hasNext() && itB.hasNext()) {
FluidStack stackA = itA.next();
FluidStack stackB = itB.next();
if (stackA.isFluidStackIdentical(stackB)) return false;
}
return true;
}
}
return false;
}
@Override
public String toString() {
return "ROutput<"+outputs+","+metadata+">";
}
public final List<FluidStack> outputs;
public final NBTTagCompound metadata;
}
Binary file not shown.
@@ -1,34 +0,0 @@
package ic2.api.recipe;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
class RecipeUtil {
public static ItemStack setImmutableSize(ItemStack stack, int size) {
if (stack.getCount() != size) {
stack = stack.copy();
stack.setCount(size);
}
return stack;
}
/**
* Checks whether the first Compound has all tags, the second one has as well. Used for ItemStack matching.
* @param subject The NBT to check.
* @param target The NBT to match.
* @return whether the first NBT has all tags equal to the one of the second.
*/
public static boolean matchesNBT(NBTTagCompound subject, NBTTagCompound target) {
if (subject == null) return target == null || target.hasNoTags();
if (target == null) return true;
for (String key : target.getKeySet()) {
NBTBase targetNBT = target.getTag(key);
if (!subject.hasKey(key) || targetNBT.getId() != subject.getTagId(key)) return false;
NBTBase subjectNBT = subject.getTag(key);
if (!targetNBT.equals(subjectNBT)) return false;
}
return true;
}
}
Binary file not shown.
+24 -21
View File
@@ -1,5 +1,7 @@
package ic2.api.recipe;
import net.minecraft.item.ItemStack;
/**
* General recipe registry.
*
@@ -34,33 +36,33 @@ public class Recipes {
/**
* Recipe manager for furnace recipes.
*
* <p>No recipe meta.
*
* @deprecated currently unused/not implemented, uses the vanilla furnace recipe list
* <p>Recipe meta:
* <ul>
* <li>float experience: experience per smelt operation
* </ul>
*/
@Deprecated
public static IMachineRecipeManager furnace;
public static IMachineRecipeManager<ItemStack, ItemStack, ItemStack> furnace;
/**
* Recipe manager for macerator recipes.
*
* <p>No recipe meta.
*/
public static IMachineRecipeManager macerator;
public static IBasicMachineRecipeManager macerator;
/**
* Recipe manager for extractor recipes.
*
* <p>No recipe meta.
*/
public static IMachineRecipeManager extractor;
public static IBasicMachineRecipeManager extractor;
/**
* Recipe manager for compressor recipes.
*
* <p>No recipe meta.
*/
public static IMachineRecipeManager compressor;
public static IBasicMachineRecipeManager compressor;
/**
* Recipe manager for thermal centrifuge recipes.
@@ -70,7 +72,7 @@ public class Recipes {
* <li>int minHeat: minimum heat level required
* </ul>
*/
public static IMachineRecipeManager centrifuge;
public static IBasicMachineRecipeManager centrifuge;
/**
* Recipe manager for blast cutter recipes.
@@ -80,7 +82,7 @@ public class Recipes {
* <li>int hardness: minimum blade hardness (3=iron, 6=steel, 9=diamond)
* </ul>
*/
public static IMachineRecipeManager blockcutter;
public static IBasicMachineRecipeManager blockcutter;
/**
* Recipe manager for blast furnace recipes.
@@ -91,7 +93,7 @@ public class Recipes {
* <li>int duration: process duration (in ticks)
* </ul>
*/
public static IMachineRecipeManager blastfurnace;
public static IBasicMachineRecipeManager blastfurnace;
/**
* Recipe manager for recycler recipes.
@@ -101,28 +103,28 @@ public class Recipes {
* @note the implementation is currently immutable, any non-blacklisted item will be accepted,
* chance checking is up to the caller.
*/
public static IMachineRecipeManager recycler;
public static IBasicMachineRecipeManager recycler;
/**
* Recipe manager for metal former extrusion mode recipes.
*
* <p>No recipe meta.
*/
public static IMachineRecipeManager metalformerExtruding;
public static IBasicMachineRecipeManager metalformerExtruding;
/**
* Recipe manager for metal former cutting mode recipes.
*
* <p>No recipe meta.
*/
public static IMachineRecipeManager metalformerCutting;
public static IBasicMachineRecipeManager metalformerCutting;
/**
* Recipe manager for metal former rolling mode recipes.
*
* <p>No recipe meta.
*/
public static IMachineRecipeManager metalformerRolling;
public static IBasicMachineRecipeManager metalformerRolling;
/**
* Recipe manager for ore washing plant recipes.
@@ -132,7 +134,7 @@ public class Recipes {
* <li>int amount: input fluid amount per cycle (in mB)
* </ul>
*/
public static IMachineRecipeManager oreWashing;
public static IBasicMachineRecipeManager oreWashing;
public static ICannerBottleRecipeManager cannerBottle;
public static ICannerEnrichRecipeManager cannerEnrich;
public static IElectrolyzerRecipeManager electrolyzer;
@@ -141,10 +143,7 @@ public class Recipes {
/**
* Recipe manager for uu mass fabricator (matter gen) recipes.
*
* <p>Recipe meta:
* <ul>
* <li>int amplification: amount of eu to be amplified per item (fixed +5x)
* </ul>
* <p>No recipe meta.
*
* <p>Reference values:
* <ul>
@@ -152,7 +151,8 @@ public class Recipes {
* <li>45000: Scrapbox
* </ul>
*/
public static IMachineRecipeManager matterAmplifier;
public static IMachineRecipeManager<IRecipeInput, Integer, ItemStack> matterAmplifier;
/**
* Reference scrap box chance values:
*
@@ -184,4 +184,7 @@ public class Recipes {
* Opposite of {@link #liquidCooldownManager}. This is for Liquids that can be heated up again.
*/
public static ILiquidHeatExchangerManager liquidHeatupManager;
public static IEmptyFluidContainerRecipeManager emptyFluidContainer;
public static IFillFluidContainerRecipeManager fillFluidContainer;
}
Binary file not shown.
+3 -1
View File
@@ -8,6 +8,8 @@ import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.relauncher.SideOnly;
import ic2.api.info.Info;
/**
* Helper class for registering {@link IRotorProvider}s to provide the default windmill renderer
*/
@@ -28,7 +30,7 @@ public class RotorRegistry {
*/
public static void setInstance(IRotorRegistry i) {
ModContainer mc = Loader.instance().activeModContainer();
if (mc == null || !"IC2".equals(mc.getModId())) {
if (mc == null || !Info.MOD_ID.equals(mc.getModId())) {
throw new IllegalAccessError("Only IC2 can set the instance");
} else {
INSTANCE = i;
@@ -0,0 +1,20 @@
package ic2.api.upgrade;
import net.minecraft.item.ItemStack;
/**
* An interface to mark an item as an {@link UpgradableProperty#Augmentable} type upgrade
*
* @author Player, Chocohead
*/
public interface IAugmentationUpgrade extends IUpgradeItem {
/**
* Gets the augmentation of the upgrade on the given {@link IUpgradableBlock}
*
* @param stack The upgrade stack
* @param parent The block being augmented
*
* @return The augmentation applied
*/
int getAugmentation(ItemStack stack, IUpgradableBlock parent);
}
@@ -0,0 +1,30 @@
package ic2.api.upgrade;
import net.minecraft.item.ItemStack;
/**
* An interface to mark an item as an {@link UpgradableProperty#EnergyStorage} type upgrade
*
* @author Player, Chocohead
*/
public interface IEnergyStorageUpgrade extends IUpgradeItem {
/**
* A raw value that is added to the {@link IUpgradableBlock}'s energy storage
*
* @param stack The upgrade stack
* @param parent The block storing energy
*
* @return The raw change in energy storage to be applied
*/
int getExtraEnergyStorage(ItemStack stack, IUpgradableBlock parent);
/**
* A multiplier value that the {@link IUpgradableBlock}'s energy storage is affected by
*
* @param stack The upgrade stack
* @param parent The block storing energy
*
* @return The multiplier to be applied to be energy storage
*/
double getEnergyStorageMultiplier(ItemStack stack, IUpgradableBlock parent);
}
@@ -0,0 +1,10 @@
package ic2.api.upgrade;
/**
* An interface to mark an item as an {@link UpgradableProperty#FluidConsuming} type upgrade
*
* @author Player, Chocohead
*/
public interface IFluidConsumingUpgrade extends IUpgradeItem {
}
@@ -0,0 +1,10 @@
package ic2.api.upgrade;
/**
* An interface to mark an item as an {@link UpgradableProperty#FluidProducing} type upgrade
*
* @author Player, Chocohead
*/
public interface IFluidProducingUpgrade extends IUpgradeItem {
}
Binary file not shown.
@@ -0,0 +1,12 @@
package ic2.api.upgrade;
/**
* An interface to mark an item supporting all {@link UpgradableProperty} type upgrades
*
* @author Player, Chocohead
*/
public interface IFullUpgrade extends IAugmentationUpgrade, IEnergyStorageUpgrade, IFluidConsumingUpgrade,
IFluidProducingUpgrade, IItemConsumingUpgrade, IItemProducingUpgrade, IProcessingUpgrade,
IRedstoneSensitiveUpgrade, ITransformerUpgrade {
}
@@ -0,0 +1,10 @@
package ic2.api.upgrade;
/**
* An interface to mark an item as an {@link UpgradableProperty#ItemConsuming} type upgrade
*
* @author Player, Chocohead
*/
public interface IItemConsumingUpgrade extends IUpgradeItem {
}
@@ -0,0 +1,10 @@
package ic2.api.upgrade;
/**
* An interface to mark an item as an {@link UpgradableProperty#ItemProducing} type upgrade
*
* @author Player, Chocohead
*/
public interface IItemProducingUpgrade extends IUpgradeItem {
}
@@ -0,0 +1,50 @@
package ic2.api.upgrade;
import net.minecraft.item.ItemStack;
/**
* An interface to mark an item as an {@link UpgradableProperty#Processing} type upgrade
*
* @author Player, Chocohead
*/
public interface IProcessingUpgrade extends IUpgradeItem {
/**
* A raw value that the process time is affected by (in ticks)
*
* @param stack The upgrade stack
* @param parent The {@link IUpgradableBlock} receiving the change
*
* @return The raw change in process to be applied
*/
int getExtraProcessTime(ItemStack stack, IUpgradableBlock parent);
/**
* A multiplier value that the process time is affected by
*
* @param stack The upgrade stack
* @param parent The {@link IUpgradableBlock} receiving the change
*
* @return The multiplier to be applied to be progress
*/
double getProcessTimeMultiplier(ItemStack stack, IUpgradableBlock parent);
/**
* A raw value that is added to the {@link IUpgradableBlock}'s energy demand
*
* @param stack The upgrade stack
* @param parent The block consuming energy
*
* @return The raw change in energy demand to be applied
*/
int getExtraEnergyDemand(ItemStack stack, IUpgradableBlock parent);
/**
* A multiplier value that the {@link IUpgradableBlock}'s energy demand is affected by
*
* @param stack The upgrade stack
* @param parent The block consuming energy
*
* @return The multiplier to be applied to be energy demand
*/
double getEnergyDemandMultiplier(ItemStack stack, IUpgradableBlock parent);
}
@@ -0,0 +1,31 @@
package ic2.api.upgrade;
import net.minecraft.item.ItemStack;
/**
* An interface to mark an item as an {@link UpgradableProperty#RedstoneSensitive} type upgrade
*
* @author Player, Chocohead
*/
public interface IRedstoneSensitiveUpgrade extends IUpgradeItem {
/**
* Whether the upgrade modifies the given {@link IUpgradableBlock}'s redstone input
*
* @param stack The upgrade stack
* @param parent The block being modified
*
* @return Whether the redstone input should be changed (and thus {@link #getRedstoneInput(ItemStack, IUpgradableBlock, int)} be called)
*/
boolean modifiesRedstoneInput(ItemStack stack, IUpgradableBlock parent);
/**
* Change the redstone input given the {@link IUpgradableBlock}'s initial input value
*
* @param stack The upgrade stack
* @param parent The block receiving the redstone signal
* @param externalInput The initial redstone signal
*
* @return The new redstone signal
*/
int getRedstoneInput(ItemStack stack, IUpgradableBlock parent, int externalInput);
}
@@ -0,0 +1,20 @@
package ic2.api.upgrade;
import net.minecraft.item.ItemStack;
/**
* An interface to mark an item as an {@link UpgradableProperty#Transformer} type upgrade
*
* @author Player, Chocohead
*/
public interface ITransformerUpgrade extends IUpgradeItem {
/**
* Gets the additional tier that the given {@link IUpgradableBlock} can take
*
* @param stack The upgrade stack
* @param parent The block receiving energy
*
* @return The value to tier the tier by
*/
int getExtraTier(ItemStack stack, IUpgradableBlock parent);
}
Binary file not shown.
@@ -0,0 +1,29 @@
package ic2.api.upgrade;
import java.util.Set;
/**
* An interface to mark a block as supporting {@link IUpgradeItem}s
*
* @author Player
*/
public interface IUpgradableBlock {
/**
* @return The energy the block current has
*/
double getEnergy();
/**
* Attempt to use the given amount of energy
*
* @param amount The amount of energy to be used
*
* @return Whether the energy was successfully used
*/
boolean useEnergy(double amount);
/**
* @return The set of {@link UpgradableProperty}s that the block supports
*/
Set<UpgradableProperty> getUpgradableProperties();
}
Binary file not shown.
@@ -0,0 +1,44 @@
package ic2.api.upgrade;
import java.util.Collection;
import java.util.Set;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
/**
* An interface to mark an item as an upgrade for {@link IUpgradableBlock}s
*
* @author Player, Chocohead
*/
public interface IUpgradeItem {
/**
* Checks if the upgrade is valid for the given {@link UpgradableProperty} types
*
* @param stack The upgrade stack being checked
* @param types The list of types being tested
*
* @return Whether the upgrade is valid
*/
boolean isSuitableFor(ItemStack stack, Set<UpgradableProperty> types);
/**
* Called every time the given {@link IUpgradableBlock} ticks
*
* @param stack The upgrade stack being ticked
* @param parent The parent block being ticked
*
* @return Whether to call {@link TileEntity#markDirty()} due to a stack changing
*/
boolean onTick(ItemStack stack, IUpgradableBlock parent);
/**
* Called when the given {@link IUpgradableBlock} finishes processing
*
* @param stack The upgrade stack
* @param parent The parent finishing processing
* @param output The list of output products from the process, read only!
* @return final output
*/
Collection<ItemStack> onProcessEnd(ItemStack stack, IUpgradableBlock parent, Collection<ItemStack> output);
}
Loaded 100 of 108 files, more files were not shown because too many files have changed in this diff. Show more