Merge branch 'master' of https://github.com/fnuecke/EnderIO into fnuecke-master

This commit is contained in:
CrazyPants committed 2014-10-27 12:15:56 +08:00
commit ebcfd7f17c
17 files changed
+551 -20

No files matched your search

@@ -148,7 +148,7 @@ import crazypants.enderio.teleport.ItemTravelStaff;
import crazypants.enderio.teleport.TeleportRecipes;
import crazypants.util.EntityUtil;
@Mod(modid = MODID, name = MOD_NAME, version = VERSION, dependencies = "required-after:[email protected],);", guiFactory = "crazypants.enderio.config.ConfigFactoryEIO")
@Mod(modid = MODID, name = MOD_NAME, version = VERSION, dependencies = "required-after:[email protected],);after:MineFactoryReloaded", guiFactory = "crazypants.enderio.config.ConfigFactoryEIO")
public class EnderIO {
public static final String MODID = "EnderIO";
@@ -26,6 +26,7 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.tools.IToolWrench;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -53,8 +54,11 @@ import crazypants.enderio.machine.painter.PainterUtil;
import crazypants.enderio.network.PacketHandler;
import crazypants.render.BoundingBox;
import crazypants.util.Util;
import powercrystals.minefactoryreloaded.api.rednet.IRedNetOmniNode;
import powercrystals.minefactoryreloaded.api.rednet.connectivity.RedNetConnectionType;
public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade {
@Optional.Interface(iface = "powercrystals.minefactoryreloaded.api.rednet.IRedNetOmniNode", modid = "MineFactoryReloaded")
public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade, IRedNetOmniNode {
private static final String KEY_CONNECTOR_ICON = "enderIO:conduitConnector";
@@ -291,12 +295,7 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade
@Override
public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z,
int par5) {
TileEntity te = world.getTileEntity(x, y, z);
if(!(te instanceof IConduitBundle)) {
return 0;
}
IConduitBundle bundle = (IConduitBundle) te;
IRedstoneConduit con = bundle.getConduit(IRedstoneConduit.class);
IRedstoneConduit con = getRedstoneConduit(world, x, y, z);
if(con == null) {
return 0;
}
@@ -306,12 +305,7 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade
@Override
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z,
int par5) {
TileEntity te = world.getTileEntity(x, y, z);
if(!(te instanceof IConduitBundle)) {
return 0;
}
IConduitBundle bundle = (IConduitBundle) te;
IRedstoneConduit con = bundle.getConduit(IRedstoneConduit.class);
IRedstoneConduit con = getRedstoneConduit(world, x, y, z);
if(con == null) {
return 0;
}
@@ -839,4 +833,57 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade
return res;
}
@Override
public void onInputsChanged(World world, int x, int y, int z, ForgeDirection side, int[] inputValues) {
IRedstoneConduit conduit = getRedstoneConduit(world, x, y, z);
if(conduit == null) {
return;
}
conduit.onInputsChanged(world, x, y, z, side, inputValues);
}
@Override
public void onInputChanged(World world, int x, int y, int z, ForgeDirection side, int inputValue) {
// Unused because only called in "Single" mode.
}
@Override
public int[] getOutputValues(World world, int x, int y, int z, ForgeDirection side) {
IRedstoneConduit conduit = getRedstoneConduit(world, x, y, z);
if(conduit == null) {
return null;
}
return conduit.getOutputValues(world, x, y, z, side);
}
@Override
public int getOutputValue(World world, int x, int y, int z, ForgeDirection side, int subnet) {
IRedstoneConduit conduit = getRedstoneConduit(world, x, y, z);
if(conduit == null) {
return 0;
}
return conduit.getOutputValue(world, x, y, z, side, subnet);
}
@Override
@Optional.Method(modid = "MineFactoryReloaded")
public RedNetConnectionType getConnectionType(World world, int x, int y, int z, ForgeDirection side) {
IRedstoneConduit conduit = getRedstoneConduit(world, x, y, z);
if(conduit == null) {
return RedNetConnectionType.None;
}
return conduit.canConnectToExternal(side, false) ? RedNetConnectionType.CableAll : RedNetConnectionType.None;
}
private static IRedstoneConduit getRedstoneConduit(IBlockAccess world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if(!(te instanceof IConduitBundle)) {
return null;
}
IConduitBundle bundle = (IConduitBundle) te;
return bundle.getConduit(IRedstoneConduit.class);
}
}
@@ -30,8 +30,11 @@ public interface IRedstoneConduit extends IConduit {
void updateNetwork();
// MFR RedNet
int[] getOutputValues(World world, int x, int y, int z, ForgeDirection side);
int getOutputValue(World world, int x, int y, int z, ForgeDirection side, int subnet);
void onInputsChanged(World world, int x, int y, int z, ForgeDirection side, int[] inputValues);
}
@@ -1,8 +1,10 @@
package crazypants.enderio.conduit.redstone;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -14,6 +16,7 @@ import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.EnderIO;
@@ -25,6 +28,7 @@ import crazypants.enderio.conduit.geom.CollidableComponent;
import crazypants.render.IconUtil;
import crazypants.util.BlockCoord;
import crazypants.util.DyeColor;
import powercrystals.minefactoryreloaded.api.rednet.IRedNetOutputNode;
public class RedstoneConduit extends AbstractConduit implements IRedstoneConduit {
@@ -52,11 +56,14 @@ public class RedstoneConduit extends AbstractConduit implements IRedstoneConduit
protected RedstoneConduitNetwork network;
protected final Set<Signal> externalSignals = new HashSet<Signal>();
protected final List<Set<Signal>> externalSignals = new ArrayList<Set<Signal>>();
protected boolean neighbourDirty = true;
public RedstoneConduit() {
for (ForgeDirection ignored : ForgeDirection.VALID_DIRECTIONS) {
externalSignals.add(new HashSet<Signal>());
}
}
@Override
@@ -119,6 +126,26 @@ public class RedstoneConduit extends AbstractConduit implements IRedstoneConduit
Signal signal = new Signal(loc.x, loc.y, loc.z, dir, input - 1, getSignalColor(dir));
res.add(signal);
}
if (Loader.isModLoaded("MineFactoryReloaded")) {
// Add stored RedNet input. See onInputsChanged below for more information.
res.addAll(externalSignals.get(dir.ordinal()));
// Manually check if neighbors are outputting bundled redstone signals.
// This is required to directly support other blocks implementing the
// RedNet API, without requiring a piece of RedNet cable in-between.
int[] bundledInput = getExternalBundledPowerLevel(dir);
if(bundledInput != null) {
BlockCoord loc = getLocation().getLocation(dir);
for (int subnet = 0; subnet < bundledInput.length; ++subnet) {
if(bundledInput[subnet] > 1) { // force signal strength reduction to avoid cycles
int color = convertColorForRedNet(subnet);
Signal signal = new Signal(loc.x, loc.y, loc.z, dir, bundledInput[subnet] - 1, DyeColor.fromIndex(color));
res.add(signal);
}
}
}
}
}
}
@@ -185,6 +212,19 @@ public class RedstoneConduit extends AbstractConduit implements IRedstoneConduit
return res;
}
protected int[] getExternalBundledPowerLevel(ForgeDirection dir) {
World world = getBundle().getEntity().getWorldObj();
BlockCoord loc = getLocation();
loc = loc.getLocation(dir);
Block block = world.getBlock(loc.x, loc.y, loc.z);
if(block instanceof IRedNetOutputNode) {
return ((IRedNetOutputNode) block).getOutputValues(world, loc.x, loc.y, loc.z, dir.getOpposite());
}
return null;
}
@Override
public int isProvidingStrongPower(ForgeDirection toDirection) {
return 0;
@@ -223,31 +263,84 @@ public class RedstoneConduit extends AbstractConduit implements IRedstoneConduit
@Override
public int[] getOutputValues(World world, int x, int y, int z, ForgeDirection side) {
int[] result = new int[16];
Set<Signal> outs = getNetworkOutputs(side);
Set<Signal> outs = network != null ? network.getSignals() : null;
if(outs != null) {
BlockCoord loc = getLocation().getLocation(side);
for (Signal s : outs) {
result[s.color.ordinal()] = s.strength;
// Avoid "feedback loops", i.e. don't report an output on a side where
// we have an input (otherwise a RedNet cable connected to a conduit
// will keep a signal high, even if the original source vanishes).
// Note that it's still possible to get loops if there are two
// connections between a conduit set and a RedNet network. I'm not
// sure there's anything we could do to avoid this, though, nor am I
// convinced we should.
if(s.dir != side || s.x != loc.x || s.y != loc.y || s.z != loc.z) {
int subnet = convertColorForRedNet(s.color.ordinal());
result[subnet] = s.strength;
}
}
}
return result;
}
@Override
public int getOutputValue(World world, int x, int y, int z, ForgeDirection side, int subnet) {
Set<Signal> outs = getNetworkOutputs(side);
Set<Signal> outs = network != null ? network.getSignals() : null;
if(outs != null) {
BlockCoord loc = getLocation().getLocation(side);
int color = convertColorForRedNet(subnet);
for (Signal s : outs) {
if(subnet == s.color.ordinal()) {
return s.strength;
// Avoid "feedback loops", see comment in getOutputValues.
if(s.dir != side || s.x != loc.x || s.y != loc.y || s.z != loc.z) {
if(s.color.ordinal() == color) {
return s.strength;
}
}
}
}
return 0;
}
@Override
public void onInputsChanged(World world, int x, int y, int z, ForgeDirection side, int[] inputValues) {
// Check if anything changed, if so mark neighbor dirty to trigger an
// update in the next tick. We have to iterate over the colors in the
// outer loop to make sure we check all of them, because for channels
// with zero signal strength no signals are stored.
Set<Signal> inputs = getNetworkInputs(side);
externalSignals.get(side.ordinal()).clear();
BlockCoord loc = getLocation().getLocation(side);
for (int subnet = 0; subnet < inputValues.length; ++subnet) {
int color = convertColorForRedNet(subnet);
int newInput = inputValues[subnet];
int oldInput = 0;
for (Signal input : inputs) {
if(input.color.ordinal() == color) {
oldInput = input.strength;
break;
}
}
neighbourDirty |= oldInput != newInput;
// Store external inputs to allow regenerating the global list of signals
// in getNetworkInputs. This is required for RedNet cables to work, e.g.
if(newInput > 1) { // force signal strength reduction to avoid cycles
externalSignals.get(side.ordinal()).add(new Signal(loc.x, loc.y, loc.z, side, newInput - 1, DyeColor.fromIndex(color)));
}
}
}
@Override
public boolean onNeighborChange(IBlockAccess world, int x, int y, int z, int tileX, int tileY, int tileZ) {
return false;
}
// RedNet refers to colors in inverse order...
private static int convertColorForRedNet(int colorOrSubnet) {
return 15 - colorOrSubnet;
}
}
@@ -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);
}
}