Moved RedNet API to api dir

This commit is contained in:
CrazyPants committed 2014-11-10 21:08:43 +08:00
1 parent 54d04c96fb
commit 8da329cc52
13 files changed
-1

No files matched your search

@@ -0,0 +1,28 @@
package powercrystals.minefactoryreloaded.api.rednet;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;
/**
* Defines a Block that can print information about itself using the RedNet Meter. This must be implemented on your Block class.
*/
public interface IRedNetInfo
{
/**
* This function appends information to a list provided to it.
*
* @param world Reference to the world.
* @param x X coordinate of the block.
* @param y Y coordinate of the block.
* @param z Z coordinate of the block.
* @param side The side of the block that is being queried.
* @param player Player doing the querying - this can be NULL.
* @param info The list that the information should be appended to.
*/
public void getRedNetInfo(IBlockAccess world, int x, int y, int z,
ForgeDirection side, EntityPlayer player, List<IChatComponent> info);
}
@@ -0,0 +1,52 @@
package powercrystals.minefactoryreloaded.api.rednet;
import powercrystals.minefactoryreloaded.api.rednet.connectivity.IRedNetConnection;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
/**
* Defines a Block that can connect to RedNet cables. This must be implemented on your Block class.
* <p>
* Note that when you implement this, the RedNet network makes several assumptions about your code -
* It will not clamp values to 0 <= x <= 15. This means you must be able to accept any possible integer
* without crashing, even negatives. It will also assume that calling the onInput(s)Changed() methods
* are sufficient, and will not issue block updates. In Single mode, it will call onInputChanged.
* <p>
* RedNet cables have their subnets indicated to the user by colored bands on the cable.
* The color of a given subnet is the same as the wool with metadata equal to the subnet number.
* <p>
* For reference:<br>
* 0:White, 1:Orange, 2:Magenta, 3:LightBlue, 4:Yellow, 5:Lime, 6:Pink, 7:Gray,
* 8:LightGray, 9:Cyan, 10:Purple, 11:Blue, 12:Brown, 13:Green, 14:Red, 15:Black
*/
public interface IRedNetInputNode extends IRedNetConnection
{
/**
* Called when the input values to this block change. Only called if your block is connected in "All" mode.
* Do not issue a network value update from inside this method call; it will be ignored. Issue your updates
* on the next tick.
*
* @param world The world this block is in.
* @param x This block's X coordinate.
* @param y This block's Y coordinate.
* @param z This block's Z coordinate.
* @param side The side the input values are being changed on.
* @param inputValues The new set of input values. This array will be 16 elements long. Do not alter or cache.
*/
public void onInputsChanged(World world, int x, int y, int z, ForgeDirection side, int[] inputValues);
/**
* Called when the input value to this block changes. Only called if your block is connected in "Single" mode.
* Do not issue a network value update from inside this method call; it will be ignored. Issue your updates
* on the next tick.
*
* @param world The world this block is in.
* @param x This block's X coordinate.
* @param y This block's Y coordinate.
* @param z This block's Z coordinate.
* @param side The side the input values are being changed on.
* @param inputValue The new input value
*/
public void onInputChanged(World world, int x, int y, int z, ForgeDirection side, int inputValue);
}
@@ -0,0 +1,19 @@
package powercrystals.minefactoryreloaded.api.rednet;
import net.minecraft.nbt.NBTTagCompound;
public interface IRedNetLogicCircuit
{
public byte getInputCount();
public byte getOutputCount();
public int[] recalculateOutputValues(long worldTime, int[] inputValues);
public String getUnlocalizedName();
public String getInputPinLabel(int pin);
public String getOutputPinLabel(int pin);
public void readFromNBT(NBTTagCompound tag);
public void writeToNBT(NBTTagCompound tag);
}
@@ -0,0 +1,36 @@
package powercrystals.minefactoryreloaded.api.rednet;
/**
*
* @author skyboy
*/
public interface IRedNetLogicPoint
{
/**
*
* @param out
* @return
*/
public void transformOutput(int[] out);
/**
*
* @param out
* @return
*/
public void transformOutput(int out);
/**
*
* @param in
* @return
*/
public int[] transformInput(int[] in);
/**
*
* @param in
* @return
*/
public int transformInput(int in);
}
@@ -0,0 +1,32 @@
package powercrystals.minefactoryreloaded.api.rednet;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
/**
*
* You should not implement this yourself. Instead, use this to look for cables to notify from your IRedNetOmniNode as this does not
* require a block update. This will be implemented on the cable's Block class.
*
*/
public interface IRedNetNetworkContainer
{
/**
* Tells the network to recalculate all subnets.
* @param world The world this cable is in.
* @param x The x-coordinate of this cable.
* @param x The y-coordinate of this cable.
* @param x The z-coordinate of this cable.
*/
public void updateNetwork(World world, int x, int y, int z, ForgeDirection from);
/**
* Tells the network to recalculate a specific subnet.
* @param world The world this cable is in.
* @param x The x-coordinate of this cable.
* @param x The y-coordinate of this cable.
* @param x The z-coordinate of this cable.
* @param subnet The subnet to recalculate.
*/
public void updateNetwork(World world, int x, int y, int z, int subnet, ForgeDirection from);
}
@@ -0,0 +1,22 @@
package powercrystals.minefactoryreloaded.api.rednet;
/**
* Defines a Block that can connect to RedNet cables. This must be implemented on your Block class.
* <p>
* Note that when you implement this, the RedNet network makes several assumptions about your code -
* It will not clamp values to 0 <= x <= 15. This means you must be able to accept any possible integer
* without crashing, even negatives. It will also assume that calling the onInput(s)Changed() methods
* are sufficient, and will not issue block updates. It will never call the vanilla redstone output
* methods, and will only query the methods contained in this interface.
* <p>
* RedNet cables have their subnets indicated to the user by colored bands on the cable.
* The color of a given subnet is the same as the wool with metadata equal to the subnet number.
* <p>
* For reference:<br>
* 0:White, 1:Orange, 2:Magenta, 3:LightBlue, 4:Yellow, 5:Lime, 6:Pink, 7:Gray,
* 8:LightGray, 9:Cyan, 10:Purple, 11:Blue, 12:Brown, 13:Green, 14:Red, 15:Black
*/
public interface IRedNetOmniNode extends IRedNetInputNode, IRedNetOutputNode
{
// this is merely provided for convenience
}
@@ -0,0 +1,51 @@
package powercrystals.minefactoryreloaded.api.rednet;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import powercrystals.minefactoryreloaded.api.rednet.connectivity.IRedNetConnection;
/**
* Defines a Block that can connect to RedNet cables. This must be implemented on your Block class.
* <p>
* Note that when you implement this, the RedNet network makes several assumptions about your code -
* It will never call the vanilla redstone output methods, querying only the methods contained in
* this interface, and will not issue block updates.
* <p>
* RedNet cables have their subnets indicated to the user by colored bands on the cable.
* The color of a given subnet is the same as the wool with metadata equal to the subnet number.
* <p>
* For reference:<br>
* 0:White, 1:Orange, 2:Magenta, 3:LightBlue, 4:Yellow, 5:Lime, 6:Pink, 7:Gray,
* 8:LightGray, 9:Cyan, 10:Purple, 11:Blue, 12:Brown, 13:Green, 14:Red, 15:Black
*/
public interface IRedNetOutputNode extends IRedNetConnection
{
/**
* Returns the output values of this RedNet node.
* This array must be 16 elements long.
* Only called if your block is connected in "All" mode.
*
* @param world The world this block is in.
* @param x This block's X coordinate.
* @param y This block's Y coordinate.
* @param z This block's Z coordinate.
* @param side The side the output values are required for.
* @return The output values.
*/
public int[] getOutputValues(World world, int x, int y, int z, ForgeDirection side);
/**
* Returns the output value of this RedNet node for a given subnet.
* Must be the same as getOutputValues(world, x, y, z, side)[subnet].
*
* @param world The world this block is in.
* @param x This block's X coordinate.
* @param y This block's Y coordinate.
* @param z This block's Z coordinate.
* @param side The side the output value is required for.
* @param subnet The subnet to get the output value for (0-15).
* @return The output value.
*/
public int getOutputValue(World world, int x, int y, int z, ForgeDirection side, int subnet);
}
@@ -0,0 +1,26 @@
package powercrystals.minefactoryreloaded.api.rednet.connectivity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
/**
* Defines a Block that can connect to RedNet cables. This must be implemented on your Block class.
*/
public interface IRedNetConnection
{
/**
* Returns the connection type of this Block. If this value must be changed
* while the block is alive, it must notify neighbors of a change.
* <p>
* For nodes that want to interact with rednet,
* see IRedNetInputNode, IRedNetOutputNode, and IRedNetOmniNode
*
* @param world The world this block is in.
* @param x This block's X coordinate.
* @param y This block's Y coordinate.
* @param z This block's Z coordinate.
* @param side The side that connection information is required for.
* @return The connection type.
*/
public RedNetConnectionType getConnectionType(World world, int x, int y, int z, ForgeDirection side);
}
@@ -0,0 +1,11 @@
package powercrystals.minefactoryreloaded.api.rednet.connectivity;
/**
* This must be implemented on your Block class.
* <p>
* RedNet cables will treat your block similar to a vanilla block that's not redstone active.
*/
public interface IRedNetDecorative
{
}
@@ -0,0 +1,13 @@
package powercrystals.minefactoryreloaded.api.rednet.connectivity;
/**
* This must be implemented on your Block class.
* <p>
* RedNet cables will not connect to your block.
* <br>
* This behavior can be overridden in subclasses by IRedNetConnection
*/
public interface IRedNetNoConnection
{
}
@@ -0,0 +1,10 @@
package powercrystals.minefactoryreloaded.api.rednet.connectivity;
/**
* This must be implemented on your Block class.
* <p>
* RedNet cables will treat your block similar to a redstone dust, and subtract one from the power value.
*/
public interface IRedstoneAlike {
}
@@ -0,0 +1,86 @@
package powercrystals.minefactoryreloaded.api.rednet.connectivity;
import java.util.HashMap;
import java.util.Map;
/**
* Defines how RedNet cable connects to a block
* <p>
* None: RedNet will never connect to this block (if this is all you want: use IRedNetNoConnection)
* <p>
* CableSingle: Connections will use the cable renderer with a single band, best used for whole blocks
* <br>
* PlateSingle: Connections will use the plate renderer with a single band, used for conveyers and rails
* <p>
* CableAll: Connections permit access to all 16 bands
* <br>
* PlateAll: Connections permit access to all 16 bands
* <p><p>
* Forced connection modes are best used for decoration blocks: RedNet will not connect normally,
* but will if the user forces it. Typically, IRedNetDecorative is desired for this instead
* <p>
* ForcedCableSingle: Connections permit access to a single band, only when the cable is in forced connection mode
* <br>
* ForcedPlateSingle: Connections permit access to a single band, only when the cable is in forced connection mode
* <p>
* ForcedCableAll: Connections permit access to all 16 bands, only when the cable is in forced connection mode
* <br>
* ForcedPlateAll: Connections permit access to all 16 bands, only when the cable is in forced connection mode
* <p><p>
* The decorative nodes are for when you want rednet to decide how to connect to your block,
* but also need to receive full updates from the network.
* <p>
* DecorativeSingle: Connections permit access to a single band, using standard connection logic
* <br>
* DecorativeAll: Connections permit access to all 16 bands, using standard connection logic
* <br>
* ForcedDecorativeSingle: Connections permit access to a single band, only when the cable is in forced connection mode
* <br>
* ForcedDecorativeAll: Connections permit access to all 16 bands, only when the cable is in forced connection mode
*/
public enum RedNetConnectionType
{
None, // 0; 0000000
CableSingle, // 11; 0001011
PlateSingle, // 13; 0001101
CableAll, // 19; 0010011
PlateAll, // 21; 0010101
ForcedCableSingle, // 43; 0101011
ForcedPlateSingle, // 45; 0101101
ForcedCableAll, // 51; 0110011
ForcedPlateAll, // 53; 0110101
DecorativeSingle, // NA; 0001001
DecorativeAll, // NA; 0010001
ForcedDecorativeSingle, // NA; 0101001
ForcedDecorativeAll; // NA; 0110001
public final boolean isConnected = this.ordinal() != 0; // 0 bit (mask: 1)
public final boolean isSingleSubnet = this.name().endsWith("Single"); // 3 bit (mask: 8)
public final boolean isAllSubnets = this.name().endsWith("All"); // 4 bit (mask: 16)
public final boolean isPlate = this.name().contains("Plate"); // 2 bit (mask: 4)
public final boolean isCable = this.name().contains("Cable"); // 1 bit (mask: 2)
public final boolean isConnectionForced = this.name().startsWith("Forced"); // 5 bit (mask: 32)
public final boolean isDecorative = this.name().contains("Decorative");
public final short flags = toFlags(isConnected, isCable, isPlate,
isSingleSubnet, isAllSubnets, isConnectionForced);
public static final RedNetConnectionType fromFlags(short flags)
{
return connections.get(flags);
}
private static final short toFlags(boolean ...flags)
{
short ret = 0;
for (int i = flags.length; i --> 0;)
ret |= (flags[i] ? 1 : 0) << i;
return ret;
}
private static final Map<Short, RedNetConnectionType> connections = new HashMap<Short, RedNetConnectionType>();
static {
for (RedNetConnectionType type : RedNetConnectionType.values())
connections.put(type.flags, type);
}
}