Added IPowerEmitter

This commit is contained in:
CovertJaguar 2013-07-02 07:56:36 -07:00
parent 5492f83a31
commit c3a54f2a24
6 changed files with 69 additions and 16 deletions

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) SpaceToad, 2011-2012
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.power;
import net.minecraftforge.common.ForgeDirection;
/**
* Essentially only used for Wooden Power Pipe connection rules.
*
* This Tile Entity interface allows you to indicate that a block can emit power
* from a specific side.
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public interface IPowerEmitter {
public boolean canEmitPowerFrom(ForgeDirection side);
}

View file

@ -11,10 +11,36 @@ import buildcraft.api.power.PowerHandler.PowerReceiver;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
/**
* This interface should be implemented by any Tile Entity that wishes to be
* able to receive power.
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public interface IPowerReceptor { public interface IPowerReceptor {
/**
* Get the PowerReceiver for this side of the block. You can return the same
* PowerReceiver for all sides or one for each side.
*
* You should NOT return null to this method unless you mean to NEVER
* receive power from that side. Returning null, after previous returning a
* PowerReceiver, will most likely cause pipe connections to derp out and
* engines to eventually explode.
*
* @param side
* @return
*/
public PowerReceiver getPowerReceiver(ForgeDirection side); public PowerReceiver getPowerReceiver(ForgeDirection side);
/**
* Call back from the PowerHandler that is called when the store power
* exceeds the activation power.
*
* It can be triggered by update() calls or power modification calls.
*
* @param workProvider
*/
public void doWork(PowerHandler workProvider); public void doWork(PowerHandler workProvider);
public World getWorldObj(); public World getWorldObj();

View file

@ -10,6 +10,7 @@ package buildcraft.api.power;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.core.SafeTimeTracker;
import java.util.EnumSet;
public final class PowerHandler { public final class PowerHandler {
@ -80,7 +81,7 @@ public final class PowerHandler {
private final SafeTimeTracker doWorkTracker = new SafeTimeTracker(); private final SafeTimeTracker doWorkTracker = new SafeTimeTracker();
private final SafeTimeTracker sourcesTracker = new SafeTimeTracker(); private final SafeTimeTracker sourcesTracker = new SafeTimeTracker();
private final SafeTimeTracker perditionTracker = new SafeTimeTracker(); private final SafeTimeTracker perditionTracker = new SafeTimeTracker();
public final int[] powerSources = {0, 0, 0, 0, 0, 0}; public final int[] powerSources = new int[6];
public final IPowerReceptor receptor; public final IPowerReceptor receptor;
private PerditionCalculator perdition; private PerditionCalculator perdition;
private final PowerReceiver receiver; private final PowerReceiver receiver;

View file

@ -19,6 +19,7 @@ import buildcraft.BuildCraftEnergy;
import buildcraft.api.core.Position; import buildcraft.api.core.Position;
import buildcraft.api.gates.IOverrideDefaultTriggers; import buildcraft.api.gates.IOverrideDefaultTriggers;
import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITrigger;
import buildcraft.api.power.IPowerEmitter;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler; import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver; import buildcraft.api.power.PowerHandler.PowerReceiver;
@ -35,7 +36,7 @@ import net.minecraft.inventory.ICrafting;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagFloat; import net.minecraft.nbt.NBTTagFloat;
public abstract class TileEngine extends TileBuildCraft implements IPowerReceptor, IInventory, IOverrideDefaultTriggers, IPipeConnection { public abstract class TileEngine extends TileBuildCraft implements IPowerReceptor, IPowerEmitter, IInventory, IOverrideDefaultTriggers, IPipeConnection {
public enum EnergyStage { public enum EnergyStage {
@ -495,6 +496,11 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
return with != orientation; return with != orientation;
} }
@Override
public boolean canEmitPowerFrom(ForgeDirection side) {
return side == orientation;
}
public void checkRedstonePower() { public void checkRedstonePower() {
isRedstonePowered = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord); isRedstonePowered = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
} }

View file

@ -13,6 +13,7 @@ import net.minecraftforge.common.ForgeDirection;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.api.core.SafeTimeTracker; import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITrigger;
import buildcraft.api.power.IPowerEmitter;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler.PowerReceiver; import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type; import buildcraft.api.power.PowerHandler.Type;
@ -76,9 +77,13 @@ public class PipeTransportPower extends PipeTransport {
if (tile instanceof IPowerReceptor) { if (tile instanceof IPowerReceptor) {
IPowerReceptor receptor = (IPowerReceptor) tile; IPowerReceptor receptor = (IPowerReceptor) tile;
PowerReceiver receiver = receptor.getPowerReceiver(side.getOpposite()); PowerReceiver receiver = receptor.getPowerReceiver(side.getOpposite());
if (receiver == null) if (receiver != null && receiver.getType().canReceiveFromPipes())
return false; return true;
if (container.pipe instanceof PipePowerWood || receiver.getType().canReceiveFromPipes()) }
if (container.pipe instanceof PipePowerWood && tile instanceof IPowerEmitter) {
IPowerEmitter emitter = (IPowerEmitter) tile;
if (emitter.canEmitPowerFrom(side.getOpposite()))
return true; return true;
} }

View file

@ -50,16 +50,7 @@ public class PipePowerWood extends Pipe implements IPowerReceptor {
@Override @Override
public int getIconIndex(ForgeDirection direction) { public int getIconIndex(ForgeDirection direction) {
if (direction == ForgeDirection.UNKNOWN)
return standardIconIndex; return standardIconIndex;
else {
int metadata = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
if (metadata == direction.ordinal())
return solidIconIndex;
else
return standardIconIndex;
}
} }
@Override @Override