Merge branch 'development' into 1.8 (gosh darn conflicts)

Conflicts:
	src/api/java/ic2/api/Direction.java
	src/api/java/ic2/api/energy/NodeStats.java
	src/main/java/mekanism/common/Mekanism.java
	src/main/java/mekanism/common/block/BlockMachine.java
	src/main/java/mekanism/common/tile/TileEntityElectricBlock.java
	src/main/java/mekanism/common/util/MekanismUtils.java
	src/main/java/mekanism/generators/common/block/BlockGenerator.java
This commit is contained in:
Aidan C. Brady 2014-10-17 12:00:39 -04:00
commit 60bf7f5f3d
13 changed files with 123 additions and 124 deletions

View file

@ -12,29 +12,29 @@ public enum Direction {
/**
* -X
*/
XN(0),
XN,
/**
* +X
*/
XP(1),
XP,
/**
* -Y
*/
YN(2), //MC-Code starts with 0 here
YN, //MC-Code starts with 0 here
/**
* +Y
*/
YP(3), // 1...
YP, // 1...
/**
* -Z
*/
ZN(4),
ZN,
/**
* +Z
*/
ZP(5);
ZP;
public static Direction fromSideValue(int side) {
return directions[(side + 2) % 6];
@ -46,10 +46,6 @@ public enum Direction {
return fromSideValue(dir.ordinal());
}
private Direction(int dir1) {
this.dir = dir1;
}
/**
* Get the tile entity next to a tile entity following this direction.
*
@ -72,7 +68,7 @@ public enum Direction {
public TileEntity applyTo(World world, int x, int y, int z) {
int coords[] = { x, y, z };
coords[dir/2] += getSign();
coords[ordinal() / 2] += getSign();
if (world != null && world.blockExists(coords[0], coords[1], coords[2])) {
try {
@ -91,13 +87,7 @@ public enum Direction {
* @return Inverse direction
*/
public Direction getInverse() {
int inverseDir = dir - getSign();
for (Direction direction : directions) {
if (direction.dir == inverseDir) return direction;
}
return this;
return directions[ordinal() ^ 1];
}
/**
@ -106,7 +96,7 @@ public enum Direction {
* @return Minecraft side value
*/
public int toSideValue() {
return (dir + 4) % 6;
return (ordinal() + 4) % 6;
}
/**
@ -115,14 +105,13 @@ public enum Direction {
* @return -1 if the direction is negative, +1 if the direction is positive
*/
private int getSign() {
return (dir % 2) * 2 - 1;
return (ordinal() % 2) * 2 - 1;
}
public ForgeDirection toForgeDirection() {
return ForgeDirection.getOrientation(toSideValue());
}
private int dir;
public static final Direction[] directions = Direction.values();
}

View file

@ -19,7 +19,7 @@ public class NodeStats {
return voltage;
}
private final double energyIn;
private final double energyOut;
private final double voltage;
protected double energyIn;
protected double energyOut;
protected double voltage;
}

View file

@ -90,4 +90,6 @@ public interface IElectricItemManager {
* @return tool tip string or null for none
*/
String getToolTip(ItemStack stack);
// TODO: add tier getter
}

View file

@ -195,8 +195,6 @@ public class Mekanism
public static Set<String> gasmaskOn = new HashSet<String>();
public static Set<String> flamethrowerActive = new HashSet<String>();
public static Set<Coord4D> ic2Registered = new HashSet<Coord4D>();
public static Set<Coord4D> activeVibrators = new HashSet<Coord4D>();
/**
@ -985,7 +983,6 @@ public class Mekanism
//Clear all cache data
teleporters.clear();
ic2Registered.clear();
jetpackOn.clear();
gasmaskOn.clear();
activeVibrators.clear();

View file

@ -18,7 +18,7 @@ import ic2.api.energy.tile.IEnergySink;
@InterfaceList({
@Interface(iface = "buildcraft.api.power.IPowerReceptor", modid = "BuildCraftAPI|power"),
@Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "IC2API", striprefs = true),
@Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "IC2"),
@Interface(iface = "cofh.api.energy.IEnergyHandler", modid = "CoFHAPI|energy"),
@Interface(iface = "dan200.computercraft.api.peripheral.IPeripheral", modid = "ComputerCraft")
})

View file

@ -252,17 +252,6 @@ public class BlockEnergyCube extends BlockContainer implements IPeripheralProvid
return itemStack;
}
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
TileEntity tileEntity = world.getTileEntity(x, y, z);
if(!world.isRemote && MekanismUtils.useIC2())
{
((TileEntityElectricBlock)tileEntity).register();
}
}
public ItemStack dismantleBlock(World world, int x, int y, int z, boolean returnBlock)
{
ItemStack itemStack = getPickBlock(null, world, x, y, z);

View file

@ -998,20 +998,6 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer
return true;
}
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
TileEntity tileEntity = world.getTileEntity(x, y, z);
if(!world.isRemote)
{
if(tileEntity instanceof TileEntityBasicBlock)
{
((TileEntityBasicBlock)tileEntity).onAdded();
}
}
}
public static enum MachineBlock
{
MACHINE_BLOCK_1,

View file

@ -34,8 +34,6 @@ import ic2.api.recipe.Recipes;
*/
public final class MekanismHooks
{
private Class BasicComponents;
private Class BuildCraftEnergy;
public boolean IC2Loaded = false;
@ -84,7 +82,7 @@ public final class MekanismHooks
}
@Method(modid = "IC2API")
@Method(modid = "IC2")
public void hookIC2Recipes()
{
for(Map.Entry<IRecipeInput, RecipeOutput> entry : Recipes.macerator.getRecipes().entrySet())

View file

@ -412,7 +412,7 @@ public final class OreDictManager
try {
RecipeHandler.addCrusherRecipe(new ItemStack(MekanismItems.Ingot, 1, 2), MekanismUtils.size(OreDictionary.getOres("dustBronze").get(0), 1));
if(Mekanism.hooks.IC2APILoaded)
if(Mekanism.hooks.IC2Loaded)
{
addIC2BronzeRecipe();
}
@ -520,7 +520,7 @@ public final class OreDictManager
}
@Method(modid = "IC2API")
@Method(modid = "IC2")
public static void addIC2BronzeRecipe()
{
try {

View file

@ -29,7 +29,7 @@ import ic2.api.energy.tile.IEnergySink;
@InterfaceList({
@Interface(iface = "buildcraft.api.power.IPowerReceptor", modid = "BuildCraftAPI|power"),
@Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "IC2API", striprefs = true),
@Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "IC2"),
@Interface(iface = "cofh.api.energy.IEnergyHandler", modid = "CoFHAPI|energy"),
@Interface(iface = "dan200.computercraft.api.peripheral.IPeripheral", modid = "ComputerCraft")
})
@ -196,7 +196,7 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp
}
@Override
@Method(modid = "IC2API")
@Method(modid = "IC2")
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
{
if(getInv() == null)
@ -359,7 +359,7 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp
}
@Override
@Method(modid = "IC2API")
@Method(modid = "IC2")
public double getDemandedEnergy()
{
if(getInv() == null)
@ -371,7 +371,7 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp
}
@Override
@Method(modid = "IC2API")
@Method(modid = "IC2")
public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage)
{
if(getInv() == null)
@ -383,7 +383,7 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp
}
@Override
@Method(modid = "IC2API")
@Method(modid = "IC2")
public int getSinkTier()
{
if(getInv() == null)

View file

@ -1,5 +1,15 @@
package mekanism.common.tile;
import ic2.api.energy.EnergyNet;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergyConductor;
import ic2.api.energy.tile.IEnergySink;
import ic2.api.energy.tile.IEnergySource;
import ic2.api.energy.tile.IEnergyTile;
import ic2.api.tile.IEnergyStorage;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.EnumSet;
@ -9,41 +19,33 @@ import mekanism.api.energy.ICableOutputter;
import mekanism.api.energy.IStrictEnergyAcceptor;
import mekanism.api.energy.IStrictEnergyStorage;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.common.Mekanism;
import mekanism.common.Upgrade;
import mekanism.common.base.ITileNetwork;
import mekanism.common.base.IUpgradeTile;
import mekanism.common.util.MekanismUtils;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.Optional.Interface;
import cpw.mods.fml.common.Optional.InterfaceList;
import cpw.mods.fml.common.Optional.Method;
import io.netty.buffer.ByteBuf;
import buildcraft.api.power.IPowerEmitter;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import cofh.api.energy.IEnergyHandler;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergySink;
import ic2.api.tile.IEnergyStorage;
import cpw.mods.fml.common.Optional.Interface;
import cpw.mods.fml.common.Optional.InterfaceList;
import cpw.mods.fml.common.Optional.Method;
@InterfaceList({
@Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "IC2API", striprefs = true),
@Interface(iface = "ic2.api.tile.IEnergyStorage", modid = "IC2API", striprefs = true),
@Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "IC2"),
@Interface(iface = "ic2.api.tile.IEnergyStorage", modid = "IC2"),
@Interface(iface = "cofh.api.energy.IEnergyHandler", modid = "CoFHAPI|energy"),
@Interface(iface = "buildcraft.api.power.IPowerReceptor", modid = "BuildCraftAPI|power"),
@Interface(iface = "buildcraft.api.power.IPowerEmitter", modid = "BuildCraftAPI|power")
})
public abstract class TileEntityElectricBlock extends TileEntityContainerBlock implements ITileNetwork, IPowerEmitter, IPowerReceptor, IStrictEnergyStorage, IEnergyHandler, IEnergySink, IEnergyStorage, IStrictEnergyAcceptor, ICableOutputter
public abstract class TileEntityElectricBlock extends TileEntityContainerBlock implements ITileNetwork, IPowerEmitter, IPowerReceptor, IStrictEnergyStorage, IEnergyHandler, IEnergySink, IEnergySource, IEnergyStorage, IStrictEnergyAcceptor, ICableOutputter
{
/** How much energy is stored in this block. */
public double electricityStored;
@ -57,6 +59,9 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
/** BuildCraft power handler. */
public PowerHandler powerHandler;
/** Is this registered with IC2 */
public boolean ic2Registered = false;
/**
* The base of all blocks that deal with electricity. It has a facing state, initialized state,
* and a current amount of stored energy.
@ -70,7 +75,9 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
maxEnergy = BASE_MAX_ENERGY;
if(MekanismUtils.useBuildCraft())
{
configure();
}
}
@Method(modid = "BuildCraftAPI|power")
@ -82,28 +89,38 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
}
@Method(modid = "IC2API")
@Method(modid = "IC2")
public void register()
{
if(!worldObj.isRemote)
{
if(!Mekanism.ic2Registered.contains(Coord4D.get(this)))
TileEntity registered = EnergyNet.instance.getTileEntity(worldObj, xCoord, yCoord, zCoord);
if(registered != this)
{
Mekanism.ic2Registered.add(Coord4D.get(this));
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
if(registered instanceof IEnergyTile)
{
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile)registered));
}
else if(registered == null)
{
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
ic2Registered = true;
}
}
}
}
@Method(modid = "IC2API")
@Method(modid = "IC2")
public void deregister()
{
if(!worldObj.isRemote)
{
if(Mekanism.ic2Registered.contains(Coord4D.get(this)))
TileEntity registered = EnergyNet.instance.getTileEntity(worldObj, xCoord, yCoord, zCoord);
if(registered instanceof IEnergyTile)
{
Mekanism.ic2Registered.remove(Coord4D.get(this));
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile)registered));
}
}
}
@ -115,6 +132,11 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
{
reconfigure();
}
if(!ic2Registered && MekanismUtils.useIC2())
{
register();
}
}
public EnumSet<ForgeDirection> getOutputtingSides()
@ -343,29 +365,36 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
}
@Override
@Method(modid = "IC2API")
@Method(modid = "IC2")
public int getSinkTier()
{
return 4;
}
@Override
@Method(modid = "IC2API")
@Method(modid = "IC2")
public int getSourceTier()
{
return 4;
}
@Override
@Method(modid = "IC2")
public void setStored(int energy)
{
setEnergy(energy* general.FROM_IC2);
setEnergy(energy*general.FROM_IC2);
}
@Override
@Method(modid = "IC2API")
@Method(modid = "IC2")
public int addEnergy(int amount)
{
setEnergy(getEnergy() + amount* general.FROM_IC2);
return (int)Math.round(getEnergy()* general.TO_IC2);
setEnergy(getEnergy() + amount*general.FROM_IC2);
return (int)Math.round(getEnergy()*general.TO_IC2);
}
@Override
@Method(modid = "IC2API")
@Method(modid = "IC2")
public boolean isTeleporterCompatible(ForgeDirection side)
{
return getOutputtingSides().contains(side);
@ -378,38 +407,52 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
}
@Override
@Method(modid = "IC2API")
@Method(modid = "IC2")
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
{
return !getOutputtingSides().contains(direction);
return getConsumingSides().contains(direction);
}
@Override
@Method(modid = "IC2API")
@Method(modid = "IC2")
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction)
{
return getOutputtingSides().contains(direction) && receiver instanceof IEnergyConductor;
}
@Override
@Method(modid = "IC2")
public int getStored()
{
return (int)Math.round(getEnergy()* general.TO_IC2);
return (int)Math.round(getEnergy()*general.TO_IC2);
}
@Override
@Method(modid = "IC2API")
@Method(modid = "IC2")
public int getCapacity()
{
return (int)Math.round(getMaxEnergy()* general.TO_IC2);
return (int)Math.round(getMaxEnergy()*general.TO_IC2);
}
@Override
@Method(modid = "IC2API")
@Method(modid = "IC2")
public int getOutput()
{
return (int)Math.round(getMaxOutput()* general.TO_IC2);
return (int)Math.round(getMaxOutput()*general.TO_IC2);
}
@Override
@Method(modid = "IC2API")
@Method(modid = "IC2")
public double getDemandedEnergy()
{
return (getMaxEnergy() - getEnergy())* general.TO_IC2;
return (getMaxEnergy() - getEnergy())*general.TO_IC2;
}
@Override
@Method(modid = "IC2")
public double getOfferedEnergy()
{
return Math.min(getEnergy(), getMaxOutput())*general.TO_IC2;
}
@Override
@ -419,22 +462,29 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
}
@Override
@Method(modid = "IC2API")
@Method(modid = "IC2")
public double getOutputEnergyUnitsPerTick()
{
return getMaxOutput()* general.TO_IC2;
return getMaxOutput()*general.TO_IC2;
}
@Override
@Method(modid = "IC2API")
public double injectEnergy(ForgeDirection direction, double i, double v)
@Method(modid = "IC2")
public double injectEnergy(ForgeDirection direction, double amount, double voltage)
{
if(Coord4D.get(this).getFromSide(direction).getTileEntity(worldObj) instanceof IGridTransmitter)
{
return i;
return amount;
}
return i-transferEnergyToAcceptor(direction, i* general.FROM_IC2)* general.TO_IC2;
return amount-transferEnergyToAcceptor(direction, amount*general.FROM_IC2)*general.TO_IC2;
}
@Override
@Method(modid = "IC2")
public void drawEnergy(double amount)
{
setEnergy(Math.max(getEnergy() - (amount*general.FROM_IC2), 0));
}
@Override

View file

@ -1,5 +1,7 @@
package mekanism.common.util;
import ic2.api.energy.EnergyNet;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@ -1131,7 +1133,7 @@ public final class MekanismUtils
*/
public static boolean useIC2()
{
return Mekanism.hooks.IC2Loaded && !general.blacklistIC2;
return Mekanism.hooks.IC2Loaded && EnergyNet.instance != null && !general.blacklistIC2;
}
/**

View file

@ -496,20 +496,6 @@ public class BlockGenerator extends BlockContainer implements ISpecialBounds, IP
return itemStack;
}
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
TileEntity tileEntity = world.getTileEntity(x, y, z);
if(!world.isRemote)
{
if(tileEntity instanceof TileEntityBasicBlock)
{
((TileEntityBasicBlock)tileEntity).onAdded();
}
}
}
@Override
public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side)
{