New advanced fluid conduit added.

#314 'Lock mode' added to fluid conduits.
This commit is contained in:
CrazyPants committed 2014-02-05 16:52:44 +08:00
1 parent adfbfea156
commit 9d5bf2bcef
43 files changed
+1616 -544

No files matched your search

@@ -18,6 +18,8 @@ import crazypants.enderio.conduit.IConduit;
import crazypants.enderio.conduit.TileConduitBundle;
import crazypants.enderio.conduit.facade.FacadeRenderer;
import crazypants.enderio.conduit.item.ItemConduit;
import crazypants.enderio.conduit.liquid.AdvancedLiquidConduit;
import crazypants.enderio.conduit.liquid.AdvancedLiquidConduitRenderer;
import crazypants.enderio.conduit.liquid.LiquidConduit;
import crazypants.enderio.conduit.liquid.LiquidConduitRenderer;
import crazypants.enderio.conduit.power.PowerConduit;
@@ -73,6 +75,7 @@ public class ClientProxy extends CommonProxy {
RedstoneSwitch.initIcons();
PowerConduit.initIcons();
LiquidConduit.initIcons();
AdvancedLiquidConduit.initIcons();
ItemConduit.initIcons();
}
@@ -149,6 +152,7 @@ public class ClientProxy extends CommonProxy {
ClientRegistry.bindTileEntitySpecialRenderer(TileConduitBundle.class, cbr);
conduitRenderers.add(RedstoneSwitchRenderer.getInstance());
conduitRenderers.add(new AdvancedLiquidConduitRenderer());
conduitRenderers.add(new LiquidConduitRenderer());
conduitRenderers.add(new PowerConduitRenderer());
conduitRenderers.add(new InsulatedRedstoneConduitRenderer());
+29 -5
View File
@@ -48,9 +48,17 @@ public final class Config {
public static boolean useSneakRightClickYetaWrench = false;
public static boolean useRfAsDefault = true;
public static boolean itemConduitUsePhyscialDistance = false;
public static int advancedFluidConduitExtractRate = 100;
public static int advancedFluidConduitMaxIoRate = 400;
public static int fluidConduitExtractRate = 50;
public static int fluidConduitMaxIoRate = 200;
public static void load(FMLPreInitializationEvent event) {
configDirectory = new File(event.getModConfigurationDirectory(), "enderio");
if(!configDirectory.exists()) {
@@ -111,6 +119,18 @@ public final class Config {
"In SMP, all clients must be using the same value as the server.").getDouble(DEFAULT_CONDUIT_SCALE);
conduitScale = VecmathUtil.clamp(conduitScale, 0, 1);
fluidConduitExtractRate = config.get("Settings", "fluidConduitExtractRate", fluidConduitExtractRate,
"Number of millibuckects per tick extract by a fluid conduits auto extract..").getInt(fluidConduitExtractRate);
fluidConduitMaxIoRate = config.get("Settings", "fluidConduitMaxIoRate", fluidConduitMaxIoRate,
"Number of millibuckects per tick that can pass through a single connection to a fluid conduit.").getInt(fluidConduitMaxIoRate);
advancedFluidConduitExtractRate = config.get("Settings", "advancedFluidConduitExtractRate", advancedFluidConduitExtractRate,
"Number of millibuckects per tick extract by advanced fluid conduits auto extract..").getInt(advancedFluidConduitExtractRate);
advancedFluidConduitMaxIoRate = config.get("Settings", "advancedFluidConduitMaxIoRate", advancedFluidConduitMaxIoRate,
"Number of millibuckects per tick that can pass through a single connection to an advanced fluid conduit.").getInt(advancedFluidConduitMaxIoRate);
useAlternateTesseractModel = config.get("Settings", "useAlternateTransceiverModel", useAlternateTesseractModel,
"Use TheKazador's alternatice model for the Dimensional Transceiver")
.getBoolean(false);
@@ -123,8 +143,12 @@ public final class Config {
transceiverBucketTransmissionCost = config.get("Settings", "transceiverBucketTransmissionCost", transceiverBucketTransmissionCost,
"The cost in MJ of trasporting a bucket of fluid via a Dimensional Transceiver.").getDouble(transceiverBucketTransmissionCost);
detailedPowerTrackingEnabled = config.get("Settings", "perInterfacePowerTrackingEnabled", detailedPowerTrackingEnabled,
"Enable per tick sampling on individual power inputs and outputs. This allows slightly more detailed messages from the MJ Reader but has a negative impact on server performance.")
detailedPowerTrackingEnabled = config
.get(
"Settings",
"perInterfacePowerTrackingEnabled",
detailedPowerTrackingEnabled,
"Enable per tick sampling on individual power inputs and outputs. This allows slightly more detailed messages from the MJ Reader but has a negative impact on server performance.")
.getBoolean(detailedPowerTrackingEnabled);
useSneakMouseWheelYetaWrench = config.get("Settings", "useSneakMouseWheelYetaWrench", useSneakMouseWheelYetaWrench,
@@ -134,10 +158,10 @@ public final class Config {
useSneakRightClickYetaWrench = config.get("Settings", "useSneakRightClickYetaWrench", useSneakRightClickYetaWrench,
"If true, shift-clicking the YetaWrench on a null or non wrenchable object will change the conduit display mode.")
.getBoolean(useSneakRightClickYetaWrench);
itemConduitUsePhyscialDistance = config.get("Settings", "itemConduitUsePhyscialDistance", itemConduitUsePhyscialDistance, "If true, " +
"'line of sight' distance rather than conduit path distance is used to calculate priorities.")
"'line of sight' distance rather than conduit path distance is used to calculate priorities.")
.getBoolean(itemConduitUsePhyscialDistance);
itemConduitUsePhyscialDistance = config.get("Settings", "itemConduitUsePhyscialDistance", itemConduitUsePhyscialDistance, "If true, " +
@@ -313,7 +313,7 @@ public abstract class AbstractConduit implements IConduit {
@Override
public void onChunkUnload(World worldObj) {
AbstractConduitNetwork<?> network = getNetwork();
AbstractConduitNetwork<?, ?> network = getNetwork();
if(network != null) {
network.destroyNetwork();
}
@@ -377,7 +377,8 @@ public abstract class AbstractConduit implements IConduit {
if(getNetwork() == null) {
ConduitUtil.ensureValidNetwork(this);
if(getNetwork() != null && !world.isRemote && bundle != null) {
world.notifyBlocksOfNeighborChange(bundle.getEntity().xCoord, bundle.getEntity().yCoord, bundle.getEntity().zCoord, bundle.getEntity().getBlockType().blockID);
world.notifyBlocksOfNeighborChange(bundle.getEntity().xCoord, bundle.getEntity().yCoord, bundle.getEntity().zCoord,
bundle.getEntity().getBlockType().blockID);
}
}
if(getNetwork() != null) {
@@ -428,7 +429,7 @@ public abstract class AbstractConduit implements IConduit {
}
externalConnections.clear();
AbstractConduitNetwork<?> network = getNetwork();
AbstractConduitNetwork<?, ?> network = getNetwork();
if(network != null) {
network.destroyNetwork();
}
@@ -7,22 +7,26 @@ import java.util.List;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public abstract class AbstractConduitNetwork<T extends IConduit> {
//I=base type, I is the base class of the implementations accepted by the network
public abstract class AbstractConduitNetwork<T extends IConduit, I extends T> {
protected final List<T> conduits = new ArrayList<T>();
protected final List<I> conduits = new ArrayList<I>();
protected AbstractConduitNetwork() {
protected Class<I> implClass;
protected AbstractConduitNetwork(Class<I> implClass) {
this.implClass = implClass;
}
public void init(IConduitBundle tile, Collection<T> connections, World world) {
public void init(IConduitBundle tile, Collection<I> connections, World world) {
if(world.isRemote) {
throw new UnsupportedOperationException();
}
// Destroy all existing redstone networks around this block
for (T con : connections) {
AbstractConduitNetwork<?> network = con.getNetwork();
for (I con : connections) {
AbstractConduitNetwork<?, ?> network = con.getNetwork();
if(network != null) {
network.destroyNetwork();
}
@@ -31,15 +35,16 @@ public abstract class AbstractConduitNetwork<T extends IConduit> {
notifyNetworkOfUpdate();
}
public abstract Class<? extends T> getBaseConduitType();
public abstract Class<T> getBaseConduitType();
protected void setNetwork(World world, IConduitBundle tile) {
T conduit = tile.getConduit(getBaseConduitType());
if(conduit.setNetwork(this)) {
addConduit(conduit);
if(conduit != null && implClass.isAssignableFrom(conduit.getClass()) && conduit.setNetwork(this)) {
addConduit(implClass.cast(conduit));
TileEntity te = tile.getEntity();
Collection<? extends T> connections = ConduitUtil.getConnectedConduits(world, te.xCoord, te.yCoord, te.zCoord, getBaseConduitType());
Collection<T> connections = ConduitUtil.getConnectedConduits(world, te.xCoord, te.yCoord, te.zCoord, getBaseConduitType());
for (T con : connections) {
if(con.getNetwork() == null) {
setNetwork(world, con.getBundle());
@@ -51,25 +56,25 @@ public abstract class AbstractConduitNetwork<T extends IConduit> {
}
}
public void addConduit(T con) {
public void addConduit(I con) {
if(!conduits.contains(con)) {
conduits.add(con);
}
}
public void destroyNetwork() {
for (T con : conduits) {
for (I con : conduits) {
con.setNetwork(null);
}
conduits.clear();
}
public List<T> getConduits() {
public List<I> getConduits() {
return conduits;
}
public void notifyNetworkOfUpdate() {
for (T con : conduits) {
for (I con : conduits) {
TileEntity te = con.getBundle().getEntity();
te.worldObj.markBlockForUpdate(te.xCoord, te.yCoord, te.zCoord);
}
@@ -120,7 +120,7 @@ public class ConduitPacketHandler implements IPacketProcessor {
}
ILiquidConduit con = conBun.getConduit(ILiquidConduit.class);
if(con == null) {
Log.warn("processFluidConduitLevelPacket: no fluid conduit exists in bundle when recieving packet.");
//Log.warn("processFluidConduitLevelPacket: no fluid conduit exists in bundle when recieving packet.");
return;
}
NBTTagCompound tc = PacketUtil.readNBTTagCompound(data);
@@ -25,7 +25,7 @@ public class ConduitRecipes {
ItemStack redstoneConduit = new ItemStack(itemRedstoneConduit.actualId, 1, 0);
ItemStack conduitBinder = new ItemStack(ModObject.itemMaterial.actualId, 1, Material.CONDUIT_BINDER.ordinal());
//ItemStack fusedQuartz = new ItemStack(ModObject.blockFusedQuartz.actualId, 1, 0);
ItemStack fusedQuartz = new ItemStack(ModObject.blockFusedQuartz.actualId, 1, 0);
ItemStack fusedGlass = new ItemStack(ModObject.blockFusedQuartz.actualId, 1, BlockFusedQuartz.Type.GLASS.ordinal());
ItemStack conductiveIron = new ItemStack(ModObject.itemAlloy.actualId, 1, Alloy.CONDUCTIVE_IRON.ordinal());
@@ -41,6 +41,7 @@ public class ConduitRecipes {
int numConduits = Config.numConduitsPerRecipe;
GameRegistry.addShapedRecipe(new ItemStack(itemLiquidConduit.actualId, numConduits, 0), "bbb", "###", "bbb", 'b', conduitBinder, '#', fusedGlass);
GameRegistry.addShapedRecipe(new ItemStack(itemLiquidConduit.actualId, numConduits, 1), "bbb", "###", "bbb", 'b', conduitBinder, '#', fusedQuartz);
GameRegistry.addShapedRecipe(new ItemStack(itemPowerConduit.actualId, numConduits, 0), "bbb", "###", "bbb", 'b', conduitBinder, '#', conductiveIron);
GameRegistry.addShapedRecipe(new ItemStack(itemPowerConduit.actualId, numConduits, 1), "bbb", "###", "bbb", 'b', conduitBinder, '#', energeticGold);
GameRegistry.addShapedRecipe(new ItemStack(itemPowerConduit.actualId, numConduits, 2), "bbb", "###", "bbb", 'b', conduitBinder, '#', phasedGold);
@@ -21,10 +21,13 @@ import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.EnderIO;
import crazypants.enderio.Log;
import crazypants.enderio.ModObject;
import crazypants.enderio.conduit.IConduitBundle.FacadeRenderState;
import crazypants.enderio.conduit.item.IItemConduit;
import crazypants.enderio.conduit.item.ItemConduitNetwork;
import crazypants.enderio.conduit.liquid.AdvancedLiquidConduit;
import crazypants.enderio.conduit.liquid.AdvancedLiquidConduitNetwork;
import crazypants.enderio.conduit.liquid.ILiquidConduit;
import crazypants.enderio.conduit.liquid.LiquidConduitNetwork;
import crazypants.enderio.conduit.power.IPowerConduit;
@@ -41,11 +44,13 @@ public class ConduitUtil {
public static final Random RANDOM = new Random();
public static AbstractConduitNetwork<?> createNetworkForType(Class<? extends IConduit> type) {
public static AbstractConduitNetwork<?, ?> createNetworkForType(Class<? extends IConduit> type) {
if(IRedstoneConduit.class.isAssignableFrom(type)) {
return new RedstoneConduitNetwork();
} else if(IPowerConduit.class.isAssignableFrom(type)) {
return new PowerConduitNetwork();
} else if(AdvancedLiquidConduit.class.isAssignableFrom(type)) {
return new AdvancedLiquidConduitNetwork();
} else if(ILiquidConduit.class.isAssignableFrom(type)) {
return new LiquidConduitNetwork();
} else if(IItemConduit.class.isAssignableFrom(type)) {
@@ -65,7 +70,7 @@ public class ConduitUtil {
return;
}
AbstractConduitNetwork res = createNetworkForType(conduit.getBaseConduitType());
AbstractConduitNetwork res = createNetworkForType(conduit.getClass());
res.init(conduit.getBundle(), connections, world);
return;
}
@@ -284,12 +289,16 @@ public class ConduitUtil {
conduitRoot.setCompoundTag("conduit", conduitBody);
}
public static IConduit readConduitFromNBT(NBTTagCompound conduitRoot) {
public static IConduit readConduitFromNBT(NBTTagCompound conduitRoot, short nbtVersion) {
String typeName = conduitRoot.getString("conduitType");
NBTTagCompound conduitBody = conduitRoot.getCompoundTag("conduit");
if(typeName == null || conduitBody == null) {
return null;
}
if(nbtVersion == 0 && "crazypants.enderio.conduit.liquid.LiquidConduit".equals(typeName)) {
Log.debug("ConduitUtil.readConduitFromNBT: Converted pre 0.7.3 fluid conduit to advanced fluid conduit.");
typeName = "crazypants.enderio.conduit.liquid.AdvancedLiquidConduit";
}
IConduit result;
try {
result = (IConduit) Class.forName(typeName).newInstance();
@@ -317,7 +326,6 @@ public class ConduitUtil {
return mode.isConditionMet(mode, signalStrength);
}
public static int getInternalSignalForColor(IConduitBundle bundle, DyeColor col) {
int signalStrength = 0;
IRedstoneConduit rsCon = bundle.getConduit(IRedstoneConduit.class);
@@ -41,6 +41,10 @@ public enum ConnectionMode {
return this == IN_OUT || this == INPUT;
}
public boolean acceptsOutput() {
return this == IN_OUT || this == OUTPUT;
}
public String getLocalisedName() {
return Lang.localize(unlocalisedName);
}
@@ -62,9 +62,9 @@ public interface IConduit {
void conduitConnectionRemoved(ForgeDirection fromDirection);
AbstractConduitNetwork<?> getNetwork();
AbstractConduitNetwork<?, ?> getNetwork();
boolean setNetwork(AbstractConduitNetwork<?> network);
boolean setNetwork(AbstractConduitNetwork<?, ?> network);
// External Connections
@@ -38,6 +38,8 @@ import crazypants.util.BlockCoord;
public class TileConduitBundle extends TileEntity implements IConduitBundle {
private static final short NBT_VERSION = 1;
private final List<IConduit> conduits = new ArrayList<IConduit>();
private int facadeId = -1;
@@ -85,17 +87,20 @@ public class TileConduitBundle extends TileEntity implements IConduitBundle {
nbtRoot.setTag("conduits", conduitTags);
nbtRoot.setInteger("facadeId", facadeId);
nbtRoot.setInteger("facadeMeta", facadeMeta);
nbtRoot.setShort("nbtVersion", NBT_VERSION);
}
@Override
public void readFromNBT(NBTTagCompound nbtRoot) {
super.readFromNBT(nbtRoot);
short nbtVersion = nbtRoot.getShort("nbtVersion");
conduits.clear();
NBTTagList conduitTags = nbtRoot.getTagList("conduits");
for (int i = 0; i < conduitTags.tagCount(); i++) {
NBTTagCompound conduitTag = (NBTTagCompound) conduitTags.tagAt(i);
IConduit conduit = ConduitUtil.readConduitFromNBT(conduitTag);
IConduit conduit = ConduitUtil.readConduitFromNBT(conduitTag, nbtVersion);
if(conduit != null) {
conduit.setBundle(this);
conduits.add(conduit);
@@ -361,7 +361,7 @@ public class ItemConduit extends AbstractConduit implements IItemConduit {
@Override
protected ConnectionMode getDefaultConnectionMode() {
return ConnectionMode.OUTPUT;
return ConnectionMode.INPUT;
}
@Override
@@ -376,12 +376,12 @@ public class ItemConduit extends AbstractConduit implements IItemConduit {
}
@Override
public AbstractConduitNetwork<?> getNetwork() {
public AbstractConduitNetwork<?, ?> getNetwork() {
return network;
}
@Override
public boolean setNetwork(AbstractConduitNetwork<?> network) {
public boolean setNetwork(AbstractConduitNetwork<?, ?> network) {
this.network = (ItemConduitNetwork) network;
return true;
}
@@ -21,7 +21,7 @@ import crazypants.util.BlockCoord;
import crazypants.util.InventoryWrapper;
import crazypants.util.ItemUtil;
public class ItemConduitNetwork extends AbstractConduitNetwork<IItemConduit> {
public class ItemConduitNetwork extends AbstractConduitNetwork<IItemConduit, IItemConduit> {
private long timeAtLastApply;
@@ -32,8 +32,12 @@ public class ItemConduitNetwork extends AbstractConduitNetwork<IItemConduit> {
private boolean requiresSort = true;
public ItemConduitNetwork() {
super(IItemConduit.class);
}
@Override
public Class<? extends IItemConduit> getBaseConduitType() {
public Class<IItemConduit> getBaseConduitType() {
return IItemConduit.class;
}
@@ -0,0 +1,203 @@
package crazypants.enderio.conduit.liquid;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.api.transport.IPipeTile;
import buildcraft.api.transport.IPipeTile.PipeType;
import crazypants.enderio.conduit.AbstractConduit;
import crazypants.enderio.conduit.ConduitUtil;
import crazypants.enderio.conduit.ConnectionMode;
import crazypants.enderio.conduit.IConduit;
import crazypants.enderio.conduit.IConduitBundle;
import crazypants.enderio.machine.RedstoneControlMode;
import crazypants.enderio.machine.reservoir.TileReservoir;
import crazypants.util.BlockCoord;
import crazypants.util.DyeColor;
public abstract class AbstractLiquidConduit extends AbstractConduit implements ILiquidConduit {
protected final EnumMap<ForgeDirection, RedstoneControlMode> extractionModes = new EnumMap<ForgeDirection, RedstoneControlMode>(ForgeDirection.class);
protected final EnumMap<ForgeDirection, DyeColor> extractionColors = new EnumMap<ForgeDirection, DyeColor>(ForgeDirection.class);
protected final Map<ForgeDirection, Integer> externalRedstoneSignals = new HashMap<ForgeDirection, Integer>();
protected boolean redstoneStateDirty = true;
public IFluidHandler getExternalHandler(ForgeDirection direction) {
IFluidHandler con = getTankContainer(getLocation().getLocation(direction));
return (con != null && !(con instanceof IConduitBundle)) ? con : null;
}
public IFluidHandler getTankContainer(BlockCoord bc) {
return getTankContainer(bc.x, bc.y, bc.z);
}
public IFluidHandler getTankContainer(int x, int y, int z) {
TileEntity te = getBundle().getEntity().worldObj.getBlockTileEntity(x, y, z);
if(te instanceof IFluidHandler) {
if(te instanceof IPipeTile) {
if(((IPipeTile) te).getPipeType() != PipeType.FLUID) {
return null;
}
}
return (IFluidHandler) te;
}
return null;
}
@Override
public boolean canConnectToExternal(ForgeDirection direction, boolean ignoreDisabled) {
return getExternalHandler(direction) != null;
}
@Override
public Class<? extends IConduit> getBaseConduitType() {
return ILiquidConduit.class;
}
@Override
public boolean onNeighborBlockChange(int blockId) {
redstoneStateDirty = true;
return super.onNeighborBlockChange(blockId);
}
@Override
public void setExtractionRedstoneMode(RedstoneControlMode mode, ForgeDirection dir) {
extractionModes.put(dir, mode);
redstoneStateDirty = true;
}
@Override
public RedstoneControlMode getExtractioRedstoneMode(ForgeDirection dir) {
RedstoneControlMode res = extractionModes.get(dir);
if(res == null) {
res = RedstoneControlMode.ON;
}
return res;
}
@Override
public void setExtractionSignalColor(ForgeDirection dir, DyeColor col) {
extractionColors.put(dir, col);
}
@Override
public DyeColor getExtractionSignalColor(ForgeDirection dir) {
DyeColor result = extractionColors.get(dir);
if(result == null) {
return DyeColor.RED;
}
return result;
}
@Override
public boolean canOutputToDir(ForgeDirection dir) {
if(isExtractingFromDir(dir) || getConectionMode(dir) == ConnectionMode.DISABLED) {
return false;
}
if(conduitConnections.contains(dir)) {
return true;
}
if(!externalConnections.contains(dir)) {
return false;
}
IFluidHandler ext = getExternalHandler(dir);
if(ext instanceof TileReservoir) { // dont push to an auto ejecting
// resevoir or we loop
TileReservoir tr = (TileReservoir) ext;
return !tr.isMultiblock() || !tr.isAutoEject();
}
return true;
}
protected boolean autoExtractForDir(ForgeDirection dir) {
if(!isExtractingFromDir(dir)) {
return false;
}
RedstoneControlMode mode = getExtractioRedstoneMode(dir);
if(mode == RedstoneControlMode.IGNORE) {
return true;
}
if(mode == RedstoneControlMode.NEVER) {
return false;
}
if(redstoneStateDirty) {
externalRedstoneSignals.clear();
redstoneStateDirty = false;
}
DyeColor col = getExtractionSignalColor(dir);
int signal = ConduitUtil.getInternalSignalForColor(getBundle(), col);
if(mode.isConditionMet(mode, signal)) {
return true;
}
int externalSignal = 0;
if(col == DyeColor.RED) {
Integer val = externalRedstoneSignals.get(dir);
if(val == null) {
TileEntity te = getBundle().getEntity();
externalSignal = te.worldObj.getStrongestIndirectPower(te.xCoord, te.yCoord, te.zCoord);
externalRedstoneSignals.put(dir, externalSignal);
} else {
externalSignal = val;
}
}
return mode.isConditionMet(mode, externalSignal);
}
@Override
public boolean isExtractingFromDir(ForgeDirection dir) {
return getConectionMode(dir) == ConnectionMode.INPUT;
}
@Override
public void writeToNBT(NBTTagCompound nbtRoot) {
super.writeToNBT(nbtRoot);
for (Entry<ForgeDirection, RedstoneControlMode> entry : extractionModes.entrySet()) {
if(entry.getValue() != null) {
short ord = (short) entry.getValue().ordinal();
nbtRoot.setShort("extRM." + entry.getKey().name(), ord);
}
}
for (Entry<ForgeDirection, DyeColor> entry : extractionColors.entrySet()) {
if(entry.getValue() != null) {
short ord = (short) entry.getValue().ordinal();
nbtRoot.setShort("extSC." + entry.getKey().name(), ord);
}
}
}
@Override
public void readFromNBT(NBTTagCompound nbtRoot) {
super.readFromNBT(nbtRoot);
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
String key = "extRM." + dir.name();
if(nbtRoot.hasKey(key)) {
short ord = nbtRoot.getShort(key);
if(ord >= 0 && ord < RedstoneControlMode.values().length) {
extractionModes.put(dir, RedstoneControlMode.values()[ord]);
}
}
key = "extSC." + dir.name();
if(nbtRoot.hasKey(key)) {
short ord = nbtRoot.getShort(key);
if(ord >= 0 && ord < DyeColor.values().length) {
extractionColors.put(dir, DyeColor.values()[ord]);
}
}
}
}
}
@@ -0,0 +1,205 @@
package crazypants.enderio.conduit.liquid;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatMessageComponent;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import crazypants.enderio.conduit.AbstractConduitNetwork;
import crazypants.enderio.conduit.ConduitUtil;
import crazypants.enderio.conduit.RaytraceResult;
import crazypants.util.BlockCoord;
import crazypants.util.Lang;
public abstract class AbstractTankConduit extends AbstractLiquidConduit {
protected ConduitTank tank = new ConduitTank(0);
protected boolean stateDirty = false;
protected long lastEmptyTick = 0;
protected int numEmptyEvents = 0;
protected boolean fluidTypeLocked = false;
@Override
public boolean onBlockActivated(EntityPlayer player, RaytraceResult res, List<RaytraceResult> all) {
if(player.getCurrentEquippedItem() == null) {
return false;
}
AbstractTankConduitNetwork<? extends AbstractTankConduit> network = getTankNetwork();
if(ConduitUtil.isToolEquipped(player)) {
if(!getBundle().getEntity().worldObj.isRemote) {
if(res != null && res.component != null) {
ForgeDirection connDir = res.component.dir;
ForgeDirection faceHit = ForgeDirection.getOrientation(res.movingObjectPosition.sideHit);
if(connDir == ForgeDirection.UNKNOWN || connDir == faceHit) {
BlockCoord loc = getLocation().getLocation(faceHit);
ILiquidConduit n = ConduitUtil.getConduit(getBundle().getEntity().worldObj, loc.x, loc.y, loc.z, ILiquidConduit.class);
if(n == null) {
return false;
}
if(!canJoinNeighbour(n)) {
return false;
}
if(!(n instanceof AbstractTankConduit)) {
return false;
}
AbstractTankConduit neighbour = (AbstractTankConduit) n;
if(neighbour.getFluidType() == null || getFluidType() == null) {
FluidStack type = getFluidType();
type = type != null ? type : neighbour.getFluidType();
neighbour.setFluidTypeOnNetwork(neighbour, type);
setFluidTypeOnNetwork(this, type);
}
return ConduitUtil.joinConduits(this, faceHit);
} else if(containsExternalConnection(connDir)) {
// Toggle extraction mode
setConnectionMode(connDir, getNextConnectionMode(connDir));
} else if(containsConduitConnection(connDir)) {
FluidStack curFluidType = null;
if(getTankNetwork() != null) {
curFluidType = getTankNetwork().getFluidType();
}
ConduitUtil.disconectConduits(this, connDir);
setFluidType(curFluidType);
}
}
}
return true;
} else if(player.getCurrentEquippedItem().itemID == Item.bucketEmpty.itemID) {
if(!getBundle().getEntity().worldObj.isRemote) {
long curTick = getBundle().getEntity().worldObj.getWorldTime();
if(curTick - lastEmptyTick < 20) {
numEmptyEvents++;
} else {
numEmptyEvents = 1;
}
lastEmptyTick = curTick;
if(numEmptyEvents < 2) {
if(network.fluidTypeLocked) {
network.setFluidTypeLocked(false);
numEmptyEvents = 0;
ChatMessageComponent c = ChatMessageComponent.createFromText(Lang.localize("itemLiquidConduit.unlockedType"));
player.sendChatToPlayer(c);
}
} else if(network != null) {
network.setFluidType(null);
numEmptyEvents = 0;
}
}
return true;
} else {
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(player.getCurrentEquippedItem());
if(fluid != null) {
if(!getBundle().getEntity().worldObj.isRemote) {
if(network != null
&& (network.getFluidType() == null || network.getTotalVolume() < 500 || LiquidConduitNetwork.areFluidsCompatable(getFluidType(), fluid))) {
network.setFluidType(fluid);
network.setFluidTypeLocked(true);
ChatMessageComponent c = ChatMessageComponent.createFromText(Lang.localize("itemLiquidConduit.lockedType") + " "
+ FluidRegistry.getFluidName(fluid));
player.sendChatToPlayer(c);
}
}
return true;
}
}
return false;
}
void setFluidTypeLocked(boolean fluidTypeLocked) {
if(fluidTypeLocked == this.fluidTypeLocked) {
return;
}
this.fluidTypeLocked = fluidTypeLocked;
stateDirty = true;
// BlockCoord l = getLocation();
// getBundle().getEntity().worldObj.markTileEntityChunkModified(l.x, l.y, l.z, getBundle().getEntity());
}
private void setFluidTypeOnNetwork(AbstractTankConduit con, FluidStack type) {
AbstractConduitNetwork<?, ?> n = con.getNetwork();
if(n != null) {
AbstractTankConduitNetwork<?> network = (AbstractTankConduitNetwork<?>) n;
network.setFluidType(type);
}
}
protected abstract boolean canJoinNeighbour(ILiquidConduit n);
public abstract AbstractTankConduitNetwork<? extends AbstractTankConduit> getTankNetwork();
public void setFluidType(FluidStack liquidType) {
if(tank.getFluid() != null && tank.getFluid().isFluidEqual(liquidType)) {
return;
}
if(liquidType != null) {
liquidType = liquidType.copy();
} else if(tank.getFluid() == null) {
return;
}
tank.setLiquid(liquidType);
stateDirty = true;
}
public ConduitTank getTank() {
return tank;
}
public FluidStack getFluidType() {
FluidStack result = null;
if(getTankNetwork() != null) {
result = getTankNetwork().getFluidType();
}
if(result == null) {
result = tank.getFluid();
}
return result;
}
protected abstract void updateTank();
@Override
public void readFromNBT(NBTTagCompound nbtRoot) {
super.readFromNBT(nbtRoot);
updateTank();
if(nbtRoot.hasKey("tank")) {
FluidStack liquid = FluidStack.loadFluidStackFromNBT(nbtRoot.getCompoundTag("tank"));
tank.setLiquid(liquid);
} else {
tank.setLiquid(null);
}
fluidTypeLocked = nbtRoot.getBoolean("fluidLocked");
}
@Override
public void writeToNBT(NBTTagCompound nbtRoot) {
super.writeToNBT(nbtRoot);
FluidStack ft = getFluidType();
if(ConduitUtil.isFluidValid(ft)) {
updateTank();
ft = ft.copy();
ft.amount = tank.getFluidAmount();
nbtRoot.setTag("tank", ft.writeToNBT(new NBTTagCompound()));
}
nbtRoot.setBoolean("fluidLocked", fluidTypeLocked);
}
}
@@ -0,0 +1,78 @@
package crazypants.enderio.conduit.liquid;
import net.minecraftforge.fluids.FluidStack;
import crazypants.enderio.conduit.AbstractConduitNetwork;
public class AbstractTankConduitNetwork<T extends AbstractTankConduit> extends AbstractConduitNetwork<ILiquidConduit, T> {
protected FluidStack liquidType;
protected boolean fluidTypeLocked = false;
protected AbstractTankConduitNetwork(Class<T> cl) {
super(cl);
}
public FluidStack getFluidType() {
return liquidType;
}
@Override
public Class<ILiquidConduit> getBaseConduitType() {
return ILiquidConduit.class;
}
@Override
public void addConduit(T con) {
super.addConduit(con);
con.setFluidType(liquidType);
if(con.fluidTypeLocked && !fluidTypeLocked) {
setFluidTypeLocked(true);
}
}
public boolean setFluidType(FluidStack newType) {
if(liquidType != null && liquidType.isFluidEqual(newType)) {
return false;
}
if(newType != null) {
liquidType = newType.copy();
liquidType.amount = 0;
} else {
liquidType = null;
}
for (AbstractTankConduit conduit : conduits) {
conduit.setFluidType(liquidType);
}
return true;
}
public void setFluidTypeLocked(boolean fluidTypeLocked) {
if(this.fluidTypeLocked == fluidTypeLocked) {
return;
}
this.fluidTypeLocked = fluidTypeLocked;
for (AbstractTankConduit conduit : conduits) {
conduit.setFluidTypeLocked(fluidTypeLocked);
}
}
public boolean canAcceptLiquid(FluidStack acceptable) {
return areFluidsCompatable(liquidType, acceptable);
}
public static boolean areFluidsCompatable(FluidStack a, FluidStack b) {
if(a == null || b == null) {
return true;
}
return a.isFluidEqual(b);
}
public int getTotalVolume() {
int totalVolume = 0;
for (T con : conduits) {
totalVolume += con.getTank().getFluidAmount();
}
return totalVolume;
}
}
@@ -0,0 +1,285 @@
package crazypants.enderio.conduit.liquid;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.Config;
import crazypants.enderio.ModObject;
import crazypants.enderio.conduit.AbstractConduitNetwork;
import crazypants.enderio.conduit.ConnectionMode;
import crazypants.enderio.conduit.IConduit;
import crazypants.enderio.conduit.geom.CollidableComponent;
import crazypants.render.IconUtil;
import crazypants.util.BlockCoord;
public class AdvancedLiquidConduit extends AbstractTankConduit {
public static final int CONDUIT_VOLUME = FluidContainerRegistry.BUCKET_VOLUME;
public static final String ICON_KEY = "enderio:liquidConduitAdvanced";
public static final String ICON_KEY_LOCKED = "enderio:liquidConduitAdvancedLocked";
public static final String ICON_CORE_KEY = "enderio:liquidConduitCoreAdvanced";
public static final String ICON_EXTRACT_KEY = "enderio:liquidConduitAdvancedInput";
public static final String ICON_INSERT_KEY = "enderio:liquidConduitAdvancedOutput";
public static final String ICON_EMPTY_EDGE = "enderio:liquidConduitAdvancedEdge";
static final Map<String, Icon> ICONS = new HashMap<String, Icon>();
@SideOnly(Side.CLIENT)
public static void initIcons() {
IconUtil.addIconProvider(new IconUtil.IIconProvider() {
@Override
public void registerIcons(IconRegister register) {
ICONS.put(ICON_KEY, register.registerIcon(ICON_KEY));
ICONS.put(ICON_CORE_KEY, register.registerIcon(ICON_CORE_KEY));
ICONS.put(ICON_EXTRACT_KEY, register.registerIcon(ICON_EXTRACT_KEY));
ICONS.put(ICON_INSERT_KEY, register.registerIcon(ICON_INSERT_KEY));
ICONS.put(ICON_EMPTY_EDGE, register.registerIcon(ICON_EMPTY_EDGE));
ICONS.put(ICON_KEY_LOCKED, register.registerIcon(ICON_KEY_LOCKED));
}
@Override
public int getTextureType() {
return 0;
}
});
}
private AdvancedLiquidConduitNetwork network;
private long ticksSinceFailedExtract = 0;
public static final int MAX_EXTRACT_PER_TICK = Config.advancedFluidConduitExtractRate;
public static final int MAX_IO_PER_TICK = Config.advancedFluidConduitMaxIoRate;
public AdvancedLiquidConduit() {
updateTank();
}
@Override
public void updateEntity(World world) {
super.updateEntity(world);
if(world.isRemote) {
return;
}
doExtract();
if(stateDirty) {
getBundle().dirty();
stateDirty = false;
}
}
private void doExtract() {
BlockCoord loc = getLocation();
if(!hasConnectionMode(ConnectionMode.INPUT)) {
return;
}
if(network == null) {
return;
}
// assume failure, reset to 0 if we do extract
ticksSinceFailedExtract++;
if(ticksSinceFailedExtract > 9 && ticksSinceFailedExtract % 10 != 0) {
// after 10 ticks of failing, only check every 10 ticks
return;
}
Fluid f = tank.getFluid() == null ? null : tank.getFluid().getFluid();
for (ForgeDirection dir : externalConnections) {
if(autoExtractForDir(dir)) {
if(network.extractFrom(this, dir, MAX_EXTRACT_PER_TICK)) {
ticksSinceFailedExtract = 0;
}
}
}
}
@Override
protected void updateTank() {
tank.setCapacity(CONDUIT_VOLUME);
if(network != null) {
network.updateConduitVolumes();
}
}
@Override
public ItemStack createItem() {
return new ItemStack(ModObject.itemLiquidConduit.actualId, 1, 1);
}
@Override
public AbstractConduitNetwork<?, ?> getNetwork() {
return network;
}
@Override
public boolean setNetwork(AbstractConduitNetwork<?, ?> network) {
if(network == null) {
this.network = null;
return true;
}
if(!(network instanceof AdvancedLiquidConduitNetwork)) {
return false;
}
AdvancedLiquidConduitNetwork n = (AdvancedLiquidConduitNetwork) network;
if(tank.getFluid() == null) {
tank.setLiquid(n.getFluidType() == null ? null : n.getFluidType().copy());
} else if(n.getFluidType() == null) {
n.setFluidType(tank.getFluid());
} else if(!tank.getFluid().isFluidEqual(n.getFluidType())) {
return false;
}
this.network = n;
return true;
}
@Override
public boolean canConnectToConduit(ForgeDirection direction, IConduit con) {
if(!super.canConnectToConduit(direction, con)) {
return false;
}
if(!(con instanceof AdvancedLiquidConduit)) {
return false;
}
if(getFluidType() != null && ((AdvancedLiquidConduit) con).getFluidType() == null) {
return false;
}
return LiquidConduitNetwork.areFluidsCompatable(getFluidType(), ((AdvancedLiquidConduit) con).getFluidType());
}
@Override
public void setConnectionMode(ForgeDirection dir, ConnectionMode mode) {
super.setConnectionMode(dir, mode);
refreshInputs(dir);
}
private void refreshInputs(ForgeDirection dir) {
if(network == null) {
return;
}
LiquidOutput lo = new LiquidOutput(getLocation().getLocation(dir), dir.getOpposite());
network.removeInput(lo);
if(getConectionMode(dir).acceptsOutput() && containsExternalConnection(dir)) {
network.addInput(lo);
}
}
@Override
public void externalConnectionAdded(ForgeDirection fromDirection) {
super.externalConnectionAdded(fromDirection);
refreshInputs(fromDirection);
}
@Override
public void externalConnectionRemoved(ForgeDirection fromDirection) {
super.externalConnectionRemoved(fromDirection);
refreshInputs(fromDirection);
}
@Override
public Icon getTextureForState(CollidableComponent component) {
if(component.dir == ForgeDirection.UNKNOWN) {
return ICONS.get(ICON_CORE_KEY);
}
return fluidTypeLocked ? ICONS.get(ICON_KEY_LOCKED) : ICONS.get(ICON_KEY);
}
public Icon getTextureForInputMode() {
return ICONS.get(ICON_EXTRACT_KEY);
}
public Icon getTextureForOutputMode() {
return ICONS.get(ICON_INSERT_KEY);
}
public Icon getNotSetEdgeTexture() {
return ICONS.get(ICON_EMPTY_EDGE);
}
@Override
public Icon getTransmitionTextureForState(CollidableComponent component) {
if(isActive() && tank.containsValidLiquid()) {
return tank.getFluid().getFluid().getStillIcon();
}
return null;
}
// ------------------------------------------- Fluid API
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
if(network == null) {
return 0;
}
return network.fill(from, resource, doFill);
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
if(network == null) {
return null;
}
return network.drain(from, resource, doDrain);
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
if(network == null) {
return null;
}
return network.drain(from, maxDrain, doDrain);
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid) {
if(network == null) {
return false;
}
return getConectionMode(from).acceptsInput() && LiquidConduitNetwork.areFluidsCompatable(getFluidType(), new FluidStack(fluid, 0));
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid) {
if(network == null) {
return false;
}
return getConectionMode(from).acceptsOutput() && LiquidConduitNetwork.areFluidsCompatable(getFluidType(), new FluidStack(fluid, 0));
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
if(network == null) {
return null;
}
return new FluidTankInfo[] { new FluidTankInfo(tank) };
}
@Override
protected boolean canJoinNeighbour(ILiquidConduit n) {
return n instanceof AdvancedLiquidConduit;
}
@Override
public AbstractTankConduitNetwork<? extends AbstractTankConduit> getTankNetwork() {
return network;
}
}
@@ -0,0 +1,279 @@
package crazypants.enderio.conduit.liquid;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.api.transport.IPipeTile;
import buildcraft.api.transport.IPipeTile.PipeType;
import crazypants.enderio.conduit.IConduit;
import crazypants.util.BlockCoord;
public class AdvancedLiquidConduitNetwork extends AbstractTankConduitNetwork<AdvancedLiquidConduit> {
private final ConduitTank tank = new ConduitTank(0);
private final Set<LiquidOutput> outputs = new HashSet<LiquidOutput>();
private Iterator<LiquidOutput> outputIterator;
private int ticksActiveUnsynced;
private boolean lastSyncedActive = false;
private int lastSyncedVolume = -1;
public AdvancedLiquidConduitNetwork() {
super(AdvancedLiquidConduit.class);
}
@Override
public Class<ILiquidConduit> getBaseConduitType() {
return ILiquidConduit.class;
}
@Override
public void addConduit(AdvancedLiquidConduit con) {
tank.setCapacity(tank.getCapacity() + AdvancedLiquidConduit.CONDUIT_VOLUME);
if(con.getTank().containsValidLiquid()) {
tank.addAmount(con.getTank().getFluidAmount());
}
for (ForgeDirection dir : con.getExternalConnections()) {
if(con.getConectionMode(dir).acceptsOutput()) {
outputs.add(new LiquidOutput(con.getLocation().getLocation(dir), dir.getOpposite()));
}
}
outputIterator = null;
super.addConduit(con);
}
public boolean setFluidType(FluidStack newType) {
if(super.setFluidType(newType)) {
FluidStack ft = getFluidType();
tank.setLiquid(ft == null ? null : ft.copy());
return true;
}
return false;
}
@Override
public void setFluidTypeLocked(boolean fluidTypeLocked) {
super.setFluidTypeLocked(fluidTypeLocked);
if(!fluidTypeLocked && tank.isEmpty()) {
setFluidType(null);
}
}
@Override
public void destroyNetwork() {
setConduitVolumes();
outputs.clear();
super.destroyNetwork();
}
private void setConduitVolumes() {
if(tank.containsValidLiquid() && !conduits.isEmpty()) {
FluidStack fluidPerConduit = tank.getFluid().copy();
int numCons = conduits.size();
int leftOvers = fluidPerConduit.amount % numCons;
fluidPerConduit.amount = fluidPerConduit.amount / numCons;
for (AdvancedLiquidConduit con : conduits) {
FluidStack f = fluidPerConduit.copy();
if(leftOvers > 0) {
f.amount += 1;
leftOvers--;
}
con.getTank().setLiquid(f);
BlockCoord bc = con.getLocation();
con.getBundle().getEntity().worldObj.markTileEntityChunkModified(bc.x, bc.y, bc.z, con.getBundle().getEntity());
}
}
}
@Override
public void onUpdateEntity(IConduit conduit) {
World world = conduit.getBundle().getEntity().worldObj;
if(world == null) {
return;
}
if(world.isRemote) {
return;
}
if(liquidType == null || outputs.isEmpty() || !tank.containsValidLiquid() || tank.isEmpty()) {
updateActiveState();
return;
}
if(outputIterator == null || !outputIterator.hasNext()) {
outputIterator = outputs.iterator();
}
updateActiveState();
int numVisited = 0;
while (!tank.isEmpty() && numVisited < outputs.size()) {
if(!outputIterator.hasNext()) {
outputIterator = outputs.iterator();
}
LiquidOutput output = outputIterator.next();
if(output != null) {
IFluidHandler cont = getTankContainer(output.location);
if(cont != null) {
FluidStack offer = tank.getFluid().copy();
int filled = cont.fill(output.dir, offer, true);
tank.addAmount(-filled);
}
}
numVisited++;
}
}
private void updateActiveState() {
boolean isActive = tank.containsValidLiquid() && !tank.isEmpty();
if(lastSyncedActive != isActive) {
ticksActiveUnsynced++;
} else {
ticksActiveUnsynced = 0;
}
if(ticksActiveUnsynced >= 10 || ticksActiveUnsynced > 0 && isActive) {
if(!isActive && !fluidTypeLocked) {
setFluidType(null);
}
for (IConduit con : conduits) {
con.setActive(isActive);
}
lastSyncedActive = isActive;
ticksActiveUnsynced = 0;
}
}
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
if(resource == null) {
return 0;
}
resource.amount = Math.min(resource.amount, AdvancedLiquidConduit.MAX_IO_PER_TICK);
boolean liquidWasValid = !tank.containsValidLiquid();
int res = tank.fill(resource, doFill);
if(doFill && res > 0 && !liquidWasValid) {
setFluidType(resource);
}
return res;
}
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
if(resource == null || tank.isEmpty() || !tank.containsValidLiquid() || !LiquidConduitNetwork.areFluidsCompatable(getFluidType(), resource)) {
return null;
}
int amount = Math.min(resource.amount, tank.getFluidAmount());
amount = Math.min(amount, AdvancedLiquidConduit.MAX_IO_PER_TICK);
FluidStack result = resource.copy();
result.amount = amount;
if(doDrain) {
tank.addAmount(-amount);
}
return result;
}
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
if(tank.isEmpty() || !tank.containsValidLiquid()) {
return null;
}
int amount = Math.min(maxDrain, tank.getFluidAmount());
FluidStack result = tank.getFluid().copy();
result.amount = amount;
if(doDrain) {
tank.addAmount(-amount);
}
return result;
}
public boolean extractFrom(AdvancedLiquidConduit advancedLiquidConduit, ForgeDirection dir, int maxExtractPerTick) {
if(tank.isFull()) {
return false;
}
IFluidHandler extTank = getTankContainer(advancedLiquidConduit, dir);
if(extTank != null) {
int maxExtract = Math.min(maxExtractPerTick, tank.getAvailableSpace());
if(liquidType == null || !tank.containsValidLiquid()) {
FluidStack drained = extTank.drain(dir.getOpposite(), maxExtract, true);
if(drained == null || drained.amount <= 0) {
return false;
}
tank.setLiquid(drained.copy());
setFluidType(drained);
return true;
}
FluidStack couldDrain = liquidType.copy();
couldDrain.amount = maxExtract;
FluidStack drained = extTank.drain(dir.getOpposite(), couldDrain, true);
if(drained == null || drained.amount <= 0) {
return false;
}
tank.addAmount(drained.amount);
return true;
}
return false;
}
public IFluidHandler getTankContainer(BlockCoord bc) {
World w = getWorld();
if(w == null) {
return null;
}
TileEntity te = w.getBlockTileEntity(bc.x, bc.y, bc.z);
if(te instanceof IFluidHandler) {
if(te instanceof IPipeTile) {
if(((IPipeTile) te).getPipeType() != PipeType.FLUID) {
return null;
}
}
return (IFluidHandler) te;
}
return null;
}
public IFluidHandler getTankContainer(AdvancedLiquidConduit con, ForgeDirection dir) {
BlockCoord bc = con.getLocation().getLocation(dir);
return getTankContainer(bc);
}
World getWorld() {
if(conduits.isEmpty()) {
return null;
}
return conduits.get(0).getBundle().getWorld();
}
public void removeInput(LiquidOutput lo) {
outputs.remove(lo);
outputIterator = null;
}
public void addInput(LiquidOutput lo) {
outputs.add(lo);
outputIterator = null;
}
public void updateConduitVolumes() {
if(tank.getFluidAmount() == lastSyncedVolume) {
return;
}
setConduitVolumes();
lastSyncedVolume = tank.getFluidAmount();
}
}
@@ -0,0 +1,182 @@
package crazypants.enderio.conduit.liquid;
import static crazypants.render.CubeRenderer.addVecWithUV;
import java.util.List;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.Icon;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import crazypants.enderio.EnderIO;
import crazypants.enderio.conduit.ConnectionMode;
import crazypants.enderio.conduit.IConduit;
import crazypants.enderio.conduit.IConduitBundle;
import crazypants.enderio.conduit.geom.CollidableComponent;
import crazypants.enderio.conduit.geom.ConnectionModeGeometry;
import crazypants.enderio.conduit.geom.Offset;
import crazypants.enderio.conduit.render.ConduitBundleRenderer;
import crazypants.enderio.conduit.render.DefaultConduitRenderer;
import crazypants.render.BoundingBox;
import crazypants.render.RenderUtil;
import crazypants.vecmath.Vector3d;
import crazypants.vecmath.Vertex;
public class AdvancedLiquidConduitRenderer extends DefaultConduitRenderer {
@Override
public boolean isRendererForConduit(IConduit conduit) {
return conduit instanceof AdvancedLiquidConduit;
}
@Override
public void renderEntity(ConduitBundleRenderer conduitBundleRenderer, IConduitBundle te, IConduit conduit, double x, double y, double z, float partialTick,
float worldLight) {
super.renderEntity(conduitBundleRenderer, te, conduit, x, y, z, partialTick, worldLight);
if(!conduit.hasConnectionMode(ConnectionMode.INPUT) && !conduit.hasConnectionMode(ConnectionMode.OUTPUT)) {
return;
}
AdvancedLiquidConduit pc = (AdvancedLiquidConduit) conduit;
for (ForgeDirection dir : conduit.getExternalConnections()) {
Icon tex = null;
if(conduit.getConectionMode(dir) == ConnectionMode.INPUT) {
tex = pc.getTextureForInputMode();
} else if(conduit.getConectionMode(dir) == ConnectionMode.OUTPUT) {
tex = pc.getTextureForOutputMode();
}
if(tex != null) {
Offset offset = te.getOffset(ILiquidConduit.class, dir);
ConnectionModeGeometry.renderModeConnector(dir, offset, tex, true);
}
}
}
@Override
protected void renderConduit(Icon tex, IConduit conduit, CollidableComponent component, float brightness) {
super.renderConduit(tex, conduit, component, brightness);
if(isNSEWUD(component.dir)) {
AdvancedLiquidConduit lc = (AdvancedLiquidConduit) conduit;
FluidStack fluid = lc.getFluidType();
Icon texture = null;
if(fluid != null) {
texture = fluid.getFluid().getStillIcon();
if(texture == null) {
texture = fluid.getFluid().getIcon();
}
}
if(texture == null) {
texture = lc.getNotSetEdgeTexture();
}
float scaleFactor = 0.75f;
float xLen = Math.abs(component.dir.offsetX) == 1 ? 1 : scaleFactor;
float yLen = Math.abs(component.dir.offsetY) == 1 ? 1 : scaleFactor;
float zLen = Math.abs(component.dir.offsetZ) == 1 ? 1 : scaleFactor;
BoundingBox cube = component.bound;
BoundingBox bb = cube.scale(xLen, yLen, zLen);
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
if(d != component.dir && d != component.dir.getOpposite()) {
ForgeDirection vDir = RenderUtil.getVDirForFace(d);
if(component.dir == ForgeDirection.UP || component.dir == ForgeDirection.DOWN) {
vDir = RenderUtil.getUDirForFace(d);
} else if((component.dir == ForgeDirection.NORTH || component.dir == ForgeDirection.SOUTH) && d.offsetY != 0) {
vDir = RenderUtil.getUDirForFace(d);
}
float minU = texture.getMinU();
float maxU = texture.getMaxU();
float minV = texture.getMinV();
float maxV = texture.getMaxV();
float sideScale = Math.max(bb.sizeX(), bb.sizeY()) * 2 / 16f;
sideScale = Math.max(sideScale, bb.sizeZ() * 2 / 16f);
float width = Math.min(bb.sizeX(), bb.sizeY()) * 15f / 16f;
List<Vertex> corners = bb.getCornersWithUvForFace(d, minU, maxU, minV, maxV);
moveEdgeCorners(corners, vDir, width);
moveEdgeCorners(corners, component.dir.getOpposite(), sideScale);
for (Vertex c : corners) {
addVecWithUV(c.xyz, c.uv.x, c.uv.y);
}
corners = bb.getCornersWithUvForFace(d, minU, maxU, minV, maxV);
moveEdgeCorners(corners, vDir.getOpposite(), width);
moveEdgeCorners(corners, component.dir.getOpposite(), sideScale);
for (Vertex c : corners) {
addVecWithUV(c.xyz, c.uv.x, c.uv.y);
}
}
}
if(conduit.getConectionMode(component.dir) == ConnectionMode.DISABLED) {
tex = EnderIO.blockConduitBundle.getConnectorIcon();
List<Vertex> corners = component.bound.getCornersWithUvForFace(component.dir, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV());
Tessellator tessellator = Tessellator.instance;
for (Vertex c : corners) {
addVecWithUV(c.xyz, c.uv.x, c.uv.y);
}
//back face
for (int i = corners.size() - 1; i >= 0; i--) {
Vertex c = corners.get(i);
addVecWithUV(c.xyz, c.uv.x, c.uv.y);
}
}
}
}
@Override
protected void renderTransmission(IConduit conduit, Icon tex, CollidableComponent component, float selfIllum) {
super.renderTransmission(conduit, tex, component, selfIllum);
}
private void moveEdgeCorners(List<Vertex> vertices, ForgeDirection edge, float scaleFactor) {
int[] indices = getClosest(edge, vertices);
vertices.get(indices[0]).xyz.x -= scaleFactor * edge.offsetX;
vertices.get(indices[1]).xyz.x -= scaleFactor * edge.offsetX;
vertices.get(indices[0]).xyz.y -= scaleFactor * edge.offsetY;
vertices.get(indices[1]).xyz.y -= scaleFactor * edge.offsetY;
vertices.get(indices[0]).xyz.z -= scaleFactor * edge.offsetZ;
vertices.get(indices[1]).xyz.z -= scaleFactor * edge.offsetZ;
}
private int[] getClosest(ForgeDirection edge, List<Vertex> vertices) {
int[] res = new int[] { -1, -1 };
boolean highest = edge.offsetX > 0 || edge.offsetY > 0 || edge.offsetZ > 0;
double minMax = highest ? -Double.MAX_VALUE : Double.MAX_VALUE;
int index = 0;
for (Vertex v : vertices) {
double val = get(v.xyz, edge);
if(highest ? val >= minMax : val <= minMax) {
if(val != minMax) {
res[0] = index;
} else {
res[1] = index;
}
minMax = val;
}
index++;
}
return res;
}
private double get(Vector3d xyz, ForgeDirection edge) {
if(edge == ForgeDirection.EAST || edge == ForgeDirection.WEST) {
return xyz.x;
}
if(edge == ForgeDirection.UP || edge == ForgeDirection.DOWN) {
return xyz.y;
}
return xyz.z;
}
}
@@ -11,7 +11,6 @@ public class ConduitTank implements IFluidTank {
private FluidStack fluid;
private int capacity;
private int tankPressure = 0;
ConduitTank(int capacity) {
this.capacity = capacity;
@@ -144,7 +143,6 @@ public class ConduitTank implements IFluidTank {
}
public void setTankPressure(int pressure) {
this.tankPressure = pressure;
}
public String getLiquidName() {
@@ -174,4 +172,8 @@ public class ConduitTank implements IFluidTank {
return this;
}
public boolean isEmpty() {
return fluid == null || fluid.amount == 0;
}
}
@@ -1,8 +1,6 @@
package crazypants.enderio.conduit.liquid;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import crazypants.enderio.conduit.IConduit;
import crazypants.enderio.machine.RedstoneControlMode;
@@ -10,24 +8,6 @@ import crazypants.util.DyeColor;
public interface ILiquidConduit extends IConduit, IFluidHandler {
static final int VOLUME_PER_CONNECTION = FluidContainerRegistry.BUCKET_VOLUME / 4;
public static final String ICON_KEY = "enderio:liquidConduit";
public static final String ICON_EMPTY_KEY = "enderio:emptyLiquidConduit";
public static final String ICON_CORE_KEY = "enderio:liquidConduitCore";
public static final String ICON_EXTRACT_KEY = "enderio:liquidConduitExtract";
public static final String ICON_EMPTY_EXTRACT_KEY = "enderio:emptyLiquidConduitExtract";
public static final String ICON_INSERT_KEY = "enderio:liquidConduitInsert";
public static final String ICON_EMPTY_INSERT_KEY = "enderio:emptyLiquidConduitInsert";
void setFluidType(FluidStack fluidType);
FluidStack getFluidType();
ConduitTank getTank();
IFluidHandler getExternalHandler(ForgeDirection direction);
boolean canOutputToDir(ForgeDirection dir);
boolean isExtractingFromDir(ForgeDirection dir);
@@ -40,6 +20,4 @@ public interface ILiquidConduit extends IConduit, IFluidHandler {
DyeColor getExtractionSignalColor(ForgeDirection dir);
int fill(ForgeDirection from, FluidStack resource, boolean doFill, boolean doPush, int pushToken);
}
@@ -10,6 +10,8 @@ public class ItemLiquidConduit extends AbstractItemConduit {
private static ItemConduitSubtype[] subtypes = new ItemConduitSubtype[] {
new ItemConduitSubtype(ModObject.itemLiquidConduit.name(), "enderio:itemLiquidConduit"),
new ItemConduitSubtype(ModObject.itemLiquidConduit.name() + "Advanced", "enderio:itemLiquidConduitAdvanced")
};
public static ItemLiquidConduit create() {
@@ -29,7 +31,23 @@ public class ItemLiquidConduit extends AbstractItemConduit {
@Override
public IConduit createConduit(ItemStack stack) {
if(stack.getItemDamage() == 1) {
return new AdvancedLiquidConduit();
}
return new LiquidConduit();
}
//TODO
// @Override
// @SideOnly(Side.CLIENT)
// public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List list, boolean par4) {
// if(PREFIX == null) {
// POSTFIX = " " + PowerDisplayUtil.abrevation() + PowerDisplayUtil.perTick();
// PREFIX = Lang.localize("power.maxOutput") + " ";
// }
// super.addInformation(itemStack, par2EntityPlayer, list, par4);
// ICapacitor cap = PowerConduit.CAPACITORS[itemStack.getItemDamage()];
// list.add(PREFIX + PowerDisplayUtil.formatPower(cap.getMaxEnergyExtracted()) + POSTFIX);
// }
}
@@ -1,52 +1,47 @@
package crazypants.enderio.conduit.liquid;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.api.transport.IPipeTile;
import buildcraft.api.transport.IPipeTile.PipeType;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.Config;
import crazypants.enderio.ModObject;
import crazypants.enderio.conduit.AbstractConduit;
import crazypants.enderio.conduit.AbstractConduitNetwork;
import crazypants.enderio.conduit.ConduitPacketHandler;
import crazypants.enderio.conduit.ConduitUtil;
import crazypants.enderio.conduit.ConnectionMode;
import crazypants.enderio.conduit.IConduit;
import crazypants.enderio.conduit.IConduitBundle;
import crazypants.enderio.conduit.RaytraceResult;
import crazypants.enderio.conduit.geom.CollidableComponent;
import crazypants.enderio.machine.RedstoneControlMode;
import crazypants.enderio.machine.reservoir.TileReservoir;
import crazypants.render.IconUtil;
import crazypants.util.BlockCoord;
import crazypants.util.DyeColor;
public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
public class LiquidConduit extends AbstractTankConduit {
static final int VOLUME_PER_CONNECTION = FluidContainerRegistry.BUCKET_VOLUME / 4;
public static final String ICON_KEY = "enderio:liquidConduit";
public static final String ICON_KEY_LOCKED = "enderio:liquidConduitLocked";
public static final String ICON_CORE_KEY = "enderio:liquidConduitCore";
public static final String ICON_EXTRACT_KEY = "enderio:liquidConduitExtract";
public static final String ICON_EMPTY_EXTRACT_KEY = "enderio:emptyLiquidConduitExtract";
public static final String ICON_INSERT_KEY = "enderio:liquidConduitInsert";
public static final String ICON_EMPTY_INSERT_KEY = "enderio:emptyLiquidConduitInsert";
static final Map<String, Icon> ICONS = new HashMap<String, Icon>();
@@ -57,12 +52,12 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
@Override
public void registerIcons(IconRegister register) {
ICONS.put(ICON_KEY, register.registerIcon(ICON_KEY));
ICONS.put(ICON_EMPTY_KEY, register.registerIcon(ICON_EMPTY_KEY));
ICONS.put(ICON_CORE_KEY, register.registerIcon(ICON_CORE_KEY));
ICONS.put(ICON_EXTRACT_KEY, register.registerIcon(ICON_EXTRACT_KEY));
ICONS.put(ICON_EMPTY_EXTRACT_KEY, register.registerIcon(ICON_EMPTY_EXTRACT_KEY));
ICONS.put(ICON_EMPTY_INSERT_KEY, register.registerIcon(ICON_EMPTY_INSERT_KEY));
ICONS.put(ICON_INSERT_KEY, register.registerIcon(ICON_INSERT_KEY));
ICONS.put(ICON_KEY_LOCKED, register.registerIcon(ICON_KEY_LOCKED));
}
@Override
@@ -75,8 +70,6 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
private LiquidConduitNetwork network;
private ConduitTank tank = new ConduitTank(0);
private float lastSyncRatio = -99;
private int currentPushToken;
@@ -86,103 +79,16 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
private long lastEmptyTick = 0;
private int numEmptyEvents = 0;
private boolean stateDirty = false;
public static final int MAX_EXTRACT_PER_TICK = Config.fluidConduitExtractRate;
private int maxDrainPerTick = 100;
public static final int MAX_IO_PER_TICK = Config.fluidConduitMaxIoRate;
private ForgeDirection startPushDir = ForgeDirection.DOWN;
private final Set<BlockCoord> filledFromThisTick = new HashSet<BlockCoord>();
protected final EnumMap<ForgeDirection, RedstoneControlMode> extractionModes = new EnumMap<ForgeDirection, RedstoneControlMode>(ForgeDirection.class);
protected final EnumMap<ForgeDirection, DyeColor> extractionColors = new EnumMap<ForgeDirection, DyeColor>(ForgeDirection.class);
private final Map<ForgeDirection, Integer> externalRedstoneSignals = new HashMap<ForgeDirection, Integer>();
private boolean redstoneStateDirty = true;
private long ticksSinceFailedExtract = 0;
@Override
public boolean onBlockActivated(EntityPlayer player, RaytraceResult res, List<RaytraceResult> all) {
if(player.getCurrentEquippedItem() == null) {
return false;
}
if(ConduitUtil.isToolEquipped(player)) {
if(!getBundle().getEntity().worldObj.isRemote) {
if(res != null && res.component != null) {
ForgeDirection connDir = res.component.dir;
ForgeDirection faceHit = ForgeDirection.getOrientation(res.movingObjectPosition.sideHit);
if(connDir == ForgeDirection.UNKNOWN || connDir == faceHit) {
BlockCoord loc = getLocation().getLocation(faceHit);
ILiquidConduit neighbour = ConduitUtil.getConduit(getBundle().getEntity().worldObj, loc.x, loc.y, loc.z, ILiquidConduit.class);
if(neighbour == null) {
return false;
}
if(neighbour.getFluidType() == null || getFluidType() == null) {
FluidStack type = getFluidType();
type = type != null ? type : neighbour.getFluidType();
neighbour.setFluidType(type);
setFluidType(type);
}
return ConduitUtil.joinConduits(this, faceHit);
} else if(containsExternalConnection(connDir)) {
// Toggle extraction mode
setConnectionMode(connDir, getNextConnectionMode(connDir));
} else if(containsConduitConnection(connDir)) {
FluidStack curFluidType = null;
if(network != null) {
curFluidType = network.getFluidType();
}
ConduitUtil.disconectConduits(this, connDir);
setFluidType(curFluidType);
}
}
}
return true;
} else if(player.getCurrentEquippedItem().itemID == Item.bucketEmpty.itemID) {
if(!getBundle().getEntity().worldObj.isRemote) {
long curTick = getBundle().getEntity().worldObj.getWorldTime();
if(curTick - lastEmptyTick < 20) {
numEmptyEvents++;
} else {
numEmptyEvents = 1;
}
lastEmptyTick = curTick;
if(numEmptyEvents < 2) {
tank.setAmount(0);
} else if(network != null) {
network.setFluidType(null);
numEmptyEvents = 0;
}
}
return true;
} else {
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(player.getCurrentEquippedItem());
if(fluid != null) {
if(!getBundle().getEntity().worldObj.isRemote) {
if(network != null && (network.getFluidType() == null || network.getTotalVolume() < 500)) {
network.setFluidType(fluid);
ChatMessageComponent c = ChatMessageComponent.createFromText("Fluid type set to " + FluidRegistry.getFluidName(fluid));
player.sendChatToPlayer(c);
}
}
return true;
}
}
return false;
}
@Override
public void updateEntity(World world) {
super.updateEntity(world);
@@ -210,41 +116,6 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
}
}
@Override
public boolean onNeighborBlockChange(int blockId) {
redstoneStateDirty = true;
return super.onNeighborBlockChange(blockId);
}
@Override
public void setExtractionRedstoneMode(RedstoneControlMode mode, ForgeDirection dir) {
extractionModes.put(dir, mode);
redstoneStateDirty = true;
}
@Override
public RedstoneControlMode getExtractioRedstoneMode(ForgeDirection dir) {
RedstoneControlMode res = extractionModes.get(dir);
if(res == null) {
res = RedstoneControlMode.ON;
}
return res;
}
@Override
public void setExtractionSignalColor(ForgeDirection dir, DyeColor col) {
extractionColors.put(dir, col);
}
@Override
public DyeColor getExtractionSignalColor(ForgeDirection dir) {
DyeColor result = extractionColors.get(dir);
if(result == null) {
return DyeColor.RED;
}
return result;
}
private void doExtract() {
BlockCoord loc = getLocation();
@@ -266,7 +137,7 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
IFluidHandler extTank = getTankContainer(getLocation().getLocation(dir));
if(extTank != null) {
FluidStack couldDrain = extTank.drain(dir.getOpposite(), maxDrainPerTick, false);
FluidStack couldDrain = extTank.drain(dir.getOpposite(), MAX_EXTRACT_PER_TICK, false);
if(couldDrain != null && couldDrain.amount > 0 && canFill(dir, couldDrain.getFluid())) {
int used = pushLiquid(dir, couldDrain, true, network == null ? -1 : network.getNextPushToken());
extTank.drain(dir.getOpposite(), used, true);
@@ -283,80 +154,6 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
}
private boolean autoExtractForDir(ForgeDirection dir) {
if(!isExtractingFromDir(dir)) {
return false;
}
RedstoneControlMode mode = getExtractioRedstoneMode(dir);
if(mode == RedstoneControlMode.IGNORE) {
return true;
}
if(mode == RedstoneControlMode.NEVER) {
return false;
}
if(redstoneStateDirty) {
externalRedstoneSignals.clear();
redstoneStateDirty = false;
}
DyeColor col = getExtractionSignalColor(dir);
int signal = ConduitUtil.getInternalSignalForColor(getBundle(), col);
if(mode.isConditionMet(mode, signal)) {
return true;
}
int externalSignal = 0;
if(col == DyeColor.RED) {
Integer val = externalRedstoneSignals.get(dir);
if(val == null) {
TileEntity te = getBundle().getEntity();
externalSignal = te.worldObj.getStrongestIndirectPower(te.xCoord, te.yCoord, te.zCoord);
externalRedstoneSignals.put(dir, externalSignal);
} else {
externalSignal = val;
}
}
return mode.isConditionMet(mode, externalSignal);
}
@Override
public boolean canOutputToDir(ForgeDirection dir) {
if(isExtractingFromDir(dir) || getConectionMode(dir) == ConnectionMode.DISABLED) {
return false;
}
if(conduitConnections.contains(dir)) {
return true;
}
if(!externalConnections.contains(dir)) {
return false;
}
IFluidHandler ext = getExternalHandler(dir);
if(ext instanceof TileReservoir) { // dont push to an auto ejecting
// resevoir or we loop
TileReservoir tr = (TileReservoir) ext;
return !tr.isMultiblock() || !tr.isAutoEject();
}
return true;
}
@Override
public boolean isExtractingFromDir(ForgeDirection dir) {
return getConectionMode(dir) == ConnectionMode.INPUT;
}
@Override
public void setFluidType(FluidStack liquidType) {
if(tank.getFluid() != null && tank.getFluid().isFluidEqual(liquidType)) {
return;
}
if(liquidType != null) {
liquidType = liquidType.copy();
}
tank.setLiquid(liquidType);
stateDirty = true;
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
@@ -394,7 +191,6 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill, boolean doPush, int pushToken) {
if(resource == null || resource.amount <= 0) {
return 0;
@@ -412,7 +208,8 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
} else {
return 0;
}
int recieveAmount = resource.amount;
//int recieveAmount = resource.amount;
resource.amount = Math.min(MAX_IO_PER_TICK, resource.amount);
if(doPush) {
return pushLiquid(from, resource, doFill, pushToken);
@@ -532,75 +329,10 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
// -----------------------------
@Override
public void writeToNBT(NBTTagCompound nbtRoot) {
super.writeToNBT(nbtRoot);
if(tank.containsValidLiquid()) {
nbtRoot.setTag("tank", tank.getFluid().writeToNBT(new NBTTagCompound()));
} else {
FluidStack ft = getFluidType();
if(ConduitUtil.isFluidValid(ft)) {
ft = getFluidType().copy();
ft.amount = 0;
nbtRoot.setTag("tank", ft.writeToNBT(new NBTTagCompound()));
}
}
for (Entry<ForgeDirection, RedstoneControlMode> entry : extractionModes.entrySet()) {
if(entry.getValue() != null) {
short ord = (short) entry.getValue().ordinal();
nbtRoot.setShort("extRM." + entry.getKey().name(), ord);
}
}
for (Entry<ForgeDirection, DyeColor> entry : extractionColors.entrySet()) {
if(entry.getValue() != null) {
short ord = (short) entry.getValue().ordinal();
nbtRoot.setShort("extSC." + entry.getKey().name(), ord);
}
}
}
@Override
public void readFromNBT(NBTTagCompound nbtRoot) {
super.readFromNBT(nbtRoot);
updateTanksCapacity();
FluidStack liquid = FluidStack.loadFluidStackFromNBT(nbtRoot.getCompoundTag("tank"));
tank.setLiquid(liquid);
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
String key = "extRM." + dir.name();
if(nbtRoot.hasKey(key)) {
short ord = nbtRoot.getShort(key);
if(ord >= 0 && ord < RedstoneControlMode.values().length) {
extractionModes.put(dir, RedstoneControlMode.values()[ord]);
}
}
key = "extSC." + dir.name();
if(nbtRoot.hasKey(key)) {
short ord = nbtRoot.getShort(key);
if(ord >= 0 && ord < DyeColor.values().length) {
extractionColors.put(dir, DyeColor.values()[ord]);
}
}
}
}
@Override
protected void connectionsChanged() {
super.connectionsChanged();
updateTanksCapacity();
}
@Override
public ConduitTank getTank() {
return tank;
}
@Override
public Class<? extends IConduit> getBaseConduitType() {
return ILiquidConduit.class;
updateTank();
}
@Override
@@ -609,18 +341,21 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
}
@Override
public AbstractConduitNetwork<?> getNetwork() {
public AbstractConduitNetwork<?, ?> getNetwork() {
return network;
}
@Override
public boolean setNetwork(AbstractConduitNetwork<?> network) {
public boolean setNetwork(AbstractConduitNetwork<?, ?> network) {
if(network == null) {
this.network = null;
return true;
}
if(!(network instanceof AbstractTankConduitNetwork)) {
return false;
}
LiquidConduitNetwork n = (LiquidConduitNetwork) network;
AbstractTankConduitNetwork n = (AbstractTankConduitNetwork) network;
if(tank.getFluid() == null) {
tank.setLiquid(n.getFluidType() == null ? null : n.getFluidType().copy());
} else if(n.getFluidType() == null) {
@@ -632,41 +367,18 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
return true;
}
@Override
public boolean canConnectToExternal(ForgeDirection direction, boolean ignoreDisabled) {
return getExternalHandler(direction) != null;
}
@Override
public IFluidHandler getExternalHandler(ForgeDirection direction) {
IFluidHandler con = getTankContainer(getLocation().getLocation(direction));
return (con != null && !(con instanceof IConduitBundle)) ? con : null;
}
@Override
public boolean canConnectToConduit(ForgeDirection direction, IConduit con) {
if(!super.canConnectToConduit(direction, con)) {
return false;
}
if(!(con instanceof ILiquidConduit)) {
if(!(con instanceof LiquidConduit)) {
return false;
}
if(getFluidType() != null && ((ILiquidConduit) con).getFluidType() == null) {
if(getFluidType() != null && ((LiquidConduit) con).getFluidType() == null) {
return false;
}
return LiquidConduitNetwork.areFluidsCompatable(getFluidType(), ((ILiquidConduit) con).getFluidType());
}
@Override
public FluidStack getFluidType() {
FluidStack result = null;
if(network != null) {
result = network.getFluidType();
}
if(result == null) {
result = tank.getFluid();
}
return result;
return LiquidConduitNetwork.areFluidsCompatable(getFluidType(), ((LiquidConduit) con).getFluidType());
}
@Override
@@ -680,10 +392,10 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
if(getConectionMode(component.dir) == ConnectionMode.OUTPUT) {
return ICONS.get(getFluidType() == null ? ICON_EMPTY_INSERT_KEY : ICON_INSERT_KEY);
}
if(getFluidType() == null) {
return ICONS.get(ICON_EMPTY_KEY);
}
return ICONS.get(ICON_KEY);
// if(getFluidType() == null) {
// return ICONS.get(ICON_EMPTY_KEY);
// }
return fluidTypeLocked ? ICONS.get(ICON_KEY_LOCKED) : ICONS.get(ICON_KEY);
}
@Override
@@ -699,26 +411,20 @@ public class LiquidConduit extends AbstractConduit implements ILiquidConduit {
return tank.getFilledRatio();
}
private IFluidHandler getTankContainer(BlockCoord bc) {
return getTankContainer(bc.x, bc.y, bc.z);
}
private IFluidHandler getTankContainer(int x, int y, int z) {
TileEntity te = getBundle().getEntity().worldObj.getBlockTileEntity(x, y, z);
if(te instanceof IFluidHandler) {
if(te instanceof IPipeTile) {
if(((IPipeTile) te).getPipeType() != PipeType.FLUID) {
return null;
}
}
return (IFluidHandler) te;
}
return null;
}
private void updateTanksCapacity() {
@Override
protected void updateTank() {
int totalConnections = getConduitConnections().size() + getExternalConnections().size();
tank.setCapacity(totalConnections * VOLUME_PER_CONNECTION);
}
@Override
protected boolean canJoinNeighbour(ILiquidConduit n) {
return n instanceof LiquidConduit;
}
@Override
public AbstractTankConduitNetwork<? extends AbstractTankConduit> getTankNetwork() {
return network;
}
}
@@ -9,14 +9,16 @@ import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import crazypants.enderio.conduit.AbstractConduitNetwork;
import crazypants.enderio.conduit.ConduitUtil;
import crazypants.enderio.conduit.IConduit;
import crazypants.util.BlockCoord;
public class LiquidConduitNetwork extends AbstractConduitNetwork<ILiquidConduit> {
public class LiquidConduitNetwork extends AbstractTankConduitNetwork<LiquidConduit> {
public LiquidConduitNetwork() {
super(LiquidConduit.class);
}
private FluidStack liquidType;
private long timeAtLastApply;
private int maxFlowsPerTick = 10;
@@ -32,15 +34,6 @@ public class LiquidConduitNetwork extends AbstractConduitNetwork<ILiquidConduit>
private boolean inputLocked = false;
@Override
public Class<? extends ILiquidConduit> getBaseConduitType() {
return ILiquidConduit.class;
}
public FluidStack getFluidType() {
return liquidType;
}
public boolean lockNetworkForFill() {
if(inputLocked) {
return false;
@@ -53,46 +46,6 @@ public class LiquidConduitNetwork extends AbstractConduitNetwork<ILiquidConduit>
inputLocked = false;
}
@Override
public void addConduit(ILiquidConduit con) {
super.addConduit(con);
con.setFluidType(liquidType);
}
public void setFluidType(FluidStack newType) {
if(liquidType != null && liquidType.isFluidEqual(newType)) {
return;
}
if(newType != null) {
liquidType = newType.copy();
liquidType.amount = 0;
} else {
liquidType = null;
}
for (ILiquidConduit conduit : conduits) {
conduit.setFluidType(liquidType);
}
}
public boolean canAcceptLiquid(FluidStack acceptable) {
return areFluidsCompatable(liquidType, acceptable);
}
public static boolean areFluidsCompatable(FluidStack a, FluidStack b) {
if(a == null || b == null) {
return true;
}
return a.isFluidEqual(b);
}
public int getTotalVolume() {
int totalVolume = 0;
for (ILiquidConduit con : conduits) {
totalVolume += con.getTank().getFluidAmount();
}
return totalVolume;
}
@Override
public void onUpdateEntity(IConduit conduit) {
World world = conduit.getBundle().getEntity().worldObj;
@@ -119,6 +72,9 @@ public class LiquidConduitNetwork extends AbstractConduitNetwork<ILiquidConduit>
}
}
}
if(!fluidTypeLocked && isEmpty()) {
setFluidType(null);
}
}
@@ -154,8 +110,8 @@ public class LiquidConduitNetwork extends AbstractConduitNetwork<ILiquidConduit>
boolean result = !actions.isEmpty();
// Flush any tanks with a tiny bit left
List<ILiquidConduit> toEmpty = new ArrayList<ILiquidConduit>();
for (ILiquidConduit con : conduits) {
List<LiquidConduit> toEmpty = new ArrayList<LiquidConduit>();
for (LiquidConduit con : conduits) {
if(con != null && con.getTank().getFluidAmount() < 10) {
toEmpty.add(con);
} else {
@@ -169,7 +125,7 @@ public class LiquidConduitNetwork extends AbstractConduitNetwork<ILiquidConduit>
}
List<LocatedFluidHandler> externals = new ArrayList<LocatedFluidHandler>();
for (ILiquidConduit con : conduits) {
for (AbstractTankConduit con : conduits) {
Set<ForgeDirection> extCons = con.getExternalConnections();
for (ForgeDirection dir : extCons) {
@@ -185,14 +141,31 @@ public class LiquidConduitNetwork extends AbstractConduitNetwork<ILiquidConduit>
return result;
}
for (ILiquidConduit con : toEmpty) {
for (LiquidConduit con : toEmpty) {
drainConduitToNearestExternal(con, externals);
}
return result;
}
private void drainConduitToNearestExternal(ILiquidConduit con, List<LocatedFluidHandler> externals) {
@Override
public void setFluidTypeLocked(boolean fluidTypeLocked) {
super.setFluidTypeLocked(fluidTypeLocked);
if(!fluidTypeLocked && isEmpty()) {
setFluidType(null);
}
}
private boolean isEmpty() {
for (LiquidConduit con : conduits) {
if(con.tank.getFluidAmount() > 0) {
return false;
}
}
return true;
}
private void drainConduitToNearestExternal(LiquidConduit con, List<LocatedFluidHandler> externals) {
BlockCoord conLoc = con.getLocation();
FluidStack toDrain = con.getTank().getFluid();
if(toDrain == null) {
@@ -218,7 +191,7 @@ public class LiquidConduitNetwork extends AbstractConduitNetwork<ILiquidConduit>
}
private void flowFrom(ILiquidConduit con, List<FlowAction> actions, int pushPoken) {
private void flowFrom(LiquidConduit con, List<FlowAction> actions, int pushPoken) {
ConduitTank tank = con.getTank();
int totalAmount = tank.getFluidAmount();
@@ -231,9 +204,10 @@ public class LiquidConduitNetwork extends AbstractConduitNetwork<ILiquidConduit>
// First flow all we can down, then balance the rest
if(con.getConduitConnections().contains(ForgeDirection.DOWN)) {
BlockCoord loc = con.getLocation().getLocation(ForgeDirection.DOWN);
ILiquidConduit downCon = ConduitUtil.getConduit(con.getBundle().getEntity().worldObj, loc.x, loc.y, loc.z, ILiquidConduit.class);
if(downCon != null) {
int filled = downCon.fill(ForgeDirection.UP, tank.getFluid().copy(), false, false, pushPoken);
ILiquidConduit dc = ConduitUtil.getConduit(con.getBundle().getEntity().worldObj, loc.x, loc.y, loc.z, ILiquidConduit.class);
if(dc instanceof LiquidConduit) {
LiquidConduit downCon = (LiquidConduit) dc;
int filled = ((LiquidConduit) downCon).fill(ForgeDirection.UP, tank.getFluid().copy(), false, false, pushPoken);
int actual = filled;
actual = Math.min(actual, tank.getFluidAmount());
actual = Math.min(actual, downCon.getTank().getAvailableSpace());
@@ -294,7 +268,8 @@ public class LiquidConduitNetwork extends AbstractConduitNetwork<ILiquidConduit>
ConduitUtil.getConnectedConduits(con.getBundle().getEntity().worldObj,
loc.x, loc.y, loc.z, ILiquidConduit.class);
int numTargets = 0;
for (ILiquidConduit neighbour : connections) {
for (ILiquidConduit n : connections) {
LiquidConduit neighbour = (LiquidConduit) n;
if(canFlowTo(con, neighbour)) { // can only flow within same network
totalAmount += neighbour.getTank().getFluidAmount();
totalCapacity += neighbour.getTank().getCapacity();
@@ -310,7 +285,8 @@ public class LiquidConduitNetwork extends AbstractConduitNetwork<ILiquidConduit>
return; // dont bother with transfers of less than a thousands of a bucket
}
for (ILiquidConduit neigbour : connections) {
for (ILiquidConduit n : connections) {
LiquidConduit neigbour = (LiquidConduit) n;
if(canFlowTo(con, neigbour)) { // can only flow within same network
flowVolume = (int) Math.floor((targetRatio - neigbour.getTank().getFilledRatio()) * neigbour.getTank().getCapacity());
if(flowVolume != 0) {
@@ -321,7 +297,7 @@ public class LiquidConduitNetwork extends AbstractConduitNetwork<ILiquidConduit>
}
private boolean canFlowTo(ILiquidConduit con, ILiquidConduit neighbour) {
private boolean canFlowTo(LiquidConduit con, LiquidConduit neighbour) {
if(con == null || neighbour == null) {
return false;
}
@@ -339,11 +315,11 @@ public class LiquidConduitNetwork extends AbstractConduitNetwork<ILiquidConduit>
}
static class FlowAction {
final ILiquidConduit from;
final ILiquidConduit to;
final LiquidConduit from;
final LiquidConduit to;
final int amount;
FlowAction(ILiquidConduit fromIn, ILiquidConduit toIn, int amountIn) {
FlowAction(LiquidConduit fromIn, LiquidConduit toIn, int amountIn) {
if(amountIn < 0) {
to = fromIn;
from = toIn;
@@ -19,6 +19,7 @@ import crazypants.enderio.conduit.render.ConduitBundleRenderer;
import crazypants.enderio.conduit.render.DefaultConduitRenderer;
import crazypants.render.BoundingBox;
import crazypants.render.RenderUtil;
import crazypants.util.ForgeDirectionOffsets;
import crazypants.vecmath.Vector2f;
import crazypants.vecmath.Vector3d;
import crazypants.vecmath.Vector3f;
@@ -34,7 +35,7 @@ public class LiquidConduitRenderer extends DefaultConduitRenderer {
@Override
public boolean isRendererForConduit(IConduit conduit) {
if(conduit instanceof ILiquidConduit) {
if(conduit instanceof LiquidConduit) {
return true;
}
return false;
@@ -43,14 +44,14 @@ public class LiquidConduitRenderer extends DefaultConduitRenderer {
@Override
public void renderEntity(ConduitBundleRenderer conduitBundleRenderer, IConduitBundle te, IConduit conduit, double x, double y, double z, float partialTick,
float worldLight) {
calculateRatios((ILiquidConduit) conduit);
calculateRatios((LiquidConduit) conduit);
super.renderEntity(conduitBundleRenderer, te, conduit, x, y, z, partialTick, worldLight);
}
@Override
protected void renderConduit(Icon tex, IConduit conduit, CollidableComponent component, float brightness) {
if(isNSEWUP(component.dir)) {
ILiquidConduit lc = (ILiquidConduit) conduit;
if(isNSEWUD(component.dir)) {
LiquidConduit lc = (LiquidConduit) conduit;
FluidStack fluid = lc.getFluidType();
if(fluid != null) {
renderFluidOutline(component, fluid);
@@ -79,7 +80,11 @@ public class LiquidConduitRenderer extends DefaultConduitRenderer {
}
}
private void renderFluidOutline(CollidableComponent component, FluidStack fluid) {
public static void renderFluidOutline(CollidableComponent component, FluidStack fluid) {
renderFluidOutline(component, fluid, 1, 13f / 16f);
}
public static void renderFluidOutline(CollidableComponent component, FluidStack fluid, double scaleFactor, float outlineWidth) {
//TODO: Should cache these vertices as relatively heavy weight to calc each frame
Icon texture = fluid.getFluid().getStillIcon();
if(texture == null) {
@@ -88,32 +93,45 @@ public class LiquidConduitRenderer extends DefaultConduitRenderer {
return;
}
}
BoundingBox bbb = component.bound;
BoundingBox bbb;
if(scaleFactor == 1) {
bbb = component.bound;
} else {
double xScale = Math.abs(component.dir.offsetX) == 1 ? 1 : scaleFactor;
double yScale = Math.abs(component.dir.offsetY) == 1 ? 1 : scaleFactor;
double zScale = Math.abs(component.dir.offsetZ) == 1 ? 1 : scaleFactor;
bbb = component.bound.scale(xScale, yScale, zScale);
}
for (ForgeDirection face : ForgeDirection.VALID_DIRECTIONS) {
if(face != component.dir && face != component.dir.getOpposite()) {
Tessellator tes = Tessellator.instance;
tes.setNormal(face.offsetX, face.offsetY, face.offsetZ);
Vector3d offset = ForgeDirectionOffsets.offsetScaled(face, -0.005);
float scaleFactor = 13f / 16f;
Vector2f uv = new Vector2f();
List<ForgeDirection> edges = RenderUtil.getEdgesForFace(face);
for (ForgeDirection edge : edges) {
if(edge != component.dir && edge != component.dir.getOpposite()) {
float xLen = 1 - Math.abs(edge.offsetX) * scaleFactor;
float yLen = 1 - Math.abs(edge.offsetY) * scaleFactor;
float zLen = 1 - Math.abs(edge.offsetZ) * scaleFactor;
float xLen = 1 - Math.abs(edge.offsetX) * outlineWidth;
float yLen = 1 - Math.abs(edge.offsetY) * outlineWidth;
float zLen = 1 - Math.abs(edge.offsetZ) * outlineWidth;
BoundingBox bb = bbb.scale(xLen, yLen, zLen);
List<Vector3f> corners = bb.getCornersForFace(face);
for (Vector3f unitCorn : corners) {
Vector3d corner = new Vector3d(unitCorn);
corner.add(offset);
corner.x += (float) (edge.offsetX * 0.5 * bbb.sizeX()) - (Math.signum(edge.offsetX) * xLen / 2f * bbb.sizeX()) * 2f;
corner.y += (float) (edge.offsetY * 0.5 * bbb.sizeY()) - (Math.signum(edge.offsetY) * yLen / 2f * bbb.sizeY()) * 2f;
corner.z += (float) (edge.offsetZ * 0.5 * bbb.sizeZ()) - (Math.signum(edge.offsetZ) * zLen / 2f * bbb.sizeZ()) * 2f;
//polyOffset
RenderUtil.getUvForCorner(uv, corner, 0, 0, 0, face, texture);
tes.addVertexWithUV(corner.x, corner.y, corner.z, uv.x, uv.y);
@@ -139,21 +157,21 @@ public class LiquidConduitRenderer extends DefaultConduitRenderer {
public void renderDynamicEntity(ConduitBundleRenderer conduitBundleRenderer, IConduitBundle te, IConduit conduit, double x, double y, double z,
float partialTick, float worldLight) {
if(((ILiquidConduit) conduit).getTank().getFilledRatio() <= 0) {
if(((LiquidConduit) conduit).getTank().getFilledRatio() <= 0) {
return;
}
Collection<CollidableComponent> components = conduit.getCollidableComponents();
Tessellator tessellator = Tessellator.instance;
calculateRatios((ILiquidConduit) conduit);
calculateRatios((LiquidConduit) conduit);
transmissionScaleFactor = conduit.getTransmitionGeometryScale();
Icon tex;
for (CollidableComponent component : components) {
if(renderComponent(component)) {
float selfIllum = Math.max(worldLight, conduit.getSelfIlluminationForState(component));
if(isNSEWUP(component.dir) &&
if(isNSEWUD(component.dir) &&
conduit.getTransmitionTextureForState(component) != null) {
tessellator.setColorOpaque_F(1, 1, 1);
@@ -185,17 +203,17 @@ public class LiquidConduitRenderer extends DefaultConduitRenderer {
setupVertices(bound.translate(translation));
}
private void calculateRatios(ILiquidConduit conduit) {
private void calculateRatios(LiquidConduit conduit) {
ConduitTank tank = conduit.getTank();
int totalAmount = tank.getFluidAmount();
int upCapacity = 0;
if(conduit.containsConduitConnection(ForgeDirection.UP) || conduit.containsExternalConnection(ForgeDirection.UP)) {
upCapacity = ILiquidConduit.VOLUME_PER_CONNECTION;
upCapacity = LiquidConduit.VOLUME_PER_CONNECTION;
}
int downCapacity = 0;
if(conduit.containsConduitConnection(ForgeDirection.DOWN) || conduit.containsExternalConnection(ForgeDirection.DOWN)) {
downCapacity = ILiquidConduit.VOLUME_PER_CONNECTION;
downCapacity = LiquidConduit.VOLUME_PER_CONNECTION;
}
int flatCapacity = tank.getCapacity() - upCapacity - downCapacity;
@@ -0,0 +1,49 @@
package crazypants.enderio.conduit.liquid;
import net.minecraftforge.common.ForgeDirection;
import crazypants.util.BlockCoord;
public class LiquidOutput {
final ForgeDirection dir;
final BlockCoord location;
public LiquidOutput(BlockCoord bc, ForgeDirection dir) {
this.dir = dir;
this.location = bc;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((location == null) ? 0 : location.hashCode());
result = prime * result + ((dir == null) ? 0 : dir.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if(this == obj)
return true;
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
LiquidOutput other = (LiquidOutput) obj;
if(location == null) {
if(other.location != null)
return false;
} else if(!location.equals(other.location))
return false;
if(dir != other.dir)
return false;
return true;
}
@Override
public String toString() {
return "LiquidOutput [dir=" + dir + ", location=" + location + "]";
}
}
@@ -380,12 +380,12 @@ public class PowerConduit extends AbstractConduit implements IPowerConduit {
}
@Override
public AbstractConduitNetwork<?> getNetwork() {
public AbstractConduitNetwork<?, ?> getNetwork() {
return network;
}
@Override
public boolean setNetwork(AbstractConduitNetwork<?> network) {
public boolean setNetwork(AbstractConduitNetwork<?, ?> network) {
this.network = (PowerConduitNetwork) network;
return true;
}
@@ -7,20 +7,16 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import cofh.api.energy.IEnergyHandler;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.api.power.IPowerReceptor;
import crazypants.enderio.conduit.AbstractConduitNetwork;
import crazypants.enderio.conduit.IConduit;
import crazypants.enderio.conduit.IConduitBundle;
import crazypants.enderio.machine.power.TileCapacitorBank;
import crazypants.enderio.power.IPowerInterface;
import crazypants.util.BlockCoord;
public class PowerConduitNetwork extends AbstractConduitNetwork<IPowerConduit> {
public class PowerConduitNetwork extends AbstractConduitNetwork<IPowerConduit, IPowerConduit> {
// ----------------------------------------------------------------------
@@ -31,6 +27,7 @@ public class PowerConduitNetwork extends AbstractConduitNetwork<IPowerConduit> {
private long timeAtLastApply = -1;
public PowerConduitNetwork() {
super(IPowerConduit.class);
}
@Override
@@ -70,7 +67,7 @@ public class PowerConduitNetwork extends AbstractConduitNetwork<IPowerConduit> {
}
@Override
public Class<? extends IPowerConduit> getBaseConduitType() {
public Class<IPowerConduit> getBaseConduitType() {
return IPowerConduit.class;
}
@@ -129,11 +126,11 @@ public class PowerConduitNetwork extends AbstractConduitNetwork<IPowerConduit> {
IPowerConduit emmiter;
BlockCoord coord;
ForgeDirection direction;
IPowerInterface powerInterface;
public ReceptorEntry(IPowerInterface powerReceptor, BlockCoord coord, IPowerConduit emmiter, ForgeDirection direction) {
powerInterface =powerReceptor;
powerInterface = powerReceptor;
this.coord = coord;
this.emmiter = emmiter;
this.direction = direction;
@@ -67,12 +67,12 @@ public class RedstoneConduit extends AbstractConduit implements IRedstoneConduit
}
@Override
public AbstractConduitNetwork<IRedstoneConduit> getNetwork() {
public AbstractConduitNetwork<IRedstoneConduit, IRedstoneConduit> getNetwork() {
return network;
}
@Override
public boolean setNetwork(AbstractConduitNetwork<?> network) {
public boolean setNetwork(AbstractConduitNetwork<?, ?> network) {
this.network = (RedstoneConduitNetwork) network;
return true;
}
@@ -154,7 +154,7 @@ public class RedstoneConduit extends AbstractConduit implements IRedstoneConduit
}
@Override
public void updateEntity(World world) {
public void updateEntity(World world) {
super.updateEntity(world);
if(!world.isRemote && neighbourDirty) {
network.destroyNetwork();
@@ -17,7 +17,7 @@ import crazypants.enderio.conduit.IConduitBundle;
import crazypants.util.BlockCoord;
import crazypants.util.Util;
public class RedstoneConduitNetwork extends AbstractConduitNetwork<IRedstoneConduit> {
public class RedstoneConduitNetwork extends AbstractConduitNetwork<IRedstoneConduit, IRedstoneConduit> {
private final Set<Signal> signals = new HashSet<Signal>();
@@ -26,10 +26,11 @@ public class RedstoneConduitNetwork extends AbstractConduitNetwork<IRedstoneCond
private boolean networkEnabled = true;
public RedstoneConduitNetwork() {
super(IRedstoneConduit.class);
}
@Override
public Class<? extends IRedstoneConduit> getBaseConduitType() {
public Class<IRedstoneConduit> getBaseConduitType() {
return IRedstoneConduit.class;
}
@@ -47,7 +47,7 @@ public class DefaultConduitRenderer implements ConduitRenderer {
for (CollidableComponent component : components) {
if(renderComponent(component)) {
float selfIllum = Math.max(worldLight, conduit.getSelfIlluminationForState(component));
if(isNSEWUP(component.dir) &&
if(isNSEWUD(component.dir) &&
conduit.getTransmitionTextureForState(component) != null) {
tessellator.setBrightness((int) (worldLight));
tex = conduit.getTransmitionTextureForState(component);
@@ -73,7 +73,7 @@ public class DefaultConduitRenderer implements ConduitRenderer {
protected void renderConduit(Icon tex, IConduit conduit, CollidableComponent component, float brightness) {
if(isNSEWUP(component.dir)) {
if(isNSEWUD(component.dir)) {
float scaleFactor = 0.75f;
float xLen = Math.abs(component.dir.offsetX) == 1 ? 1 : scaleFactor;
@@ -117,7 +117,7 @@ public class DefaultConduitRenderer implements ConduitRenderer {
return true;
}
protected boolean isNSEWUP(ForgeDirection dir) {
protected boolean isNSEWUD(ForgeDirection dir) {
return dir == NORTH || dir == SOUTH || dir == EAST || dir == WEST || dir == UP || dir == DOWN;
}
@@ -56,7 +56,6 @@ public class TilePowerMonitor extends AbstractMachineEntity implements IInternal
}
public int getRednetOutputValue(ForgeDirection side, int subnet) {
//if(currentlyEmmittedSignal != null && subnet == signalColor.ordinal()) {
if(currentlyEmmittedSignal != null) {
return 15;
}
@@ -201,7 +200,7 @@ public class TilePowerMonitor extends AbstractMachineEntity implements IInternal
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
IPowerConduit con = ConduitUtil.getConduit(worldObj, this, dir, IPowerConduit.class);
if(con != null) {
AbstractConduitNetwork<?> n = con.getNetwork();
AbstractConduitNetwork<?, ?> n = con.getNetwork();
if(n instanceof PowerConduitNetwork) {
NetworkPowerManager pm = ((PowerConduitNetwork) n).getPowerManager();
if(pm != null) {
@@ -108,7 +108,7 @@ public class ConnectedTextureRenderer implements IRenderFace {
for (ForgeDirection edge : edges) {
//We need to move the 'centre' of the face so it doesn't overlap with the border
moveCorners(refVertices, edge, 1 - scaleFactor, face);
moveCorners(refVertices, edge, 1 - scaleFactor);
//Now create the geometry for this edge of the border
float xLen = 1 - Math.abs(edge.offsetX) * scaleFactor;
@@ -260,18 +260,8 @@ public class ConnectedTextureRenderer implements IRenderFace {
return false;
}
private void moveCornerVec(List<Vector3d> corners, Vector3d edge, float scaleFactor, ForgeDirection face) {
int[] indices = getClosestVec(edge, corners, face);
corners.get(indices[0]).x -= scaleFactor * edge.x;
corners.get(indices[1]).x -= scaleFactor * edge.x;
corners.get(indices[0]).y -= scaleFactor * edge.y;
corners.get(indices[1]).y -= scaleFactor * edge.y;
corners.get(indices[0]).z -= scaleFactor * edge.z;
corners.get(indices[1]).z -= scaleFactor * edge.z;
}
private void moveCorners(List<Vertex> vertices, ForgeDirection edge, float scaleFactor, ForgeDirection face) {
int[] indices = getClosest(edge, vertices, face);
private void moveCorners(List<Vertex> vertices, ForgeDirection edge, float scaleFactor) {
int[] indices = getClosest(edge, vertices);
vertices.get(indices[0]).xyz.x -= scaleFactor * edge.offsetX;
vertices.get(indices[1]).xyz.x -= scaleFactor * edge.offsetX;
vertices.get(indices[0]).xyz.y -= scaleFactor * edge.offsetY;
@@ -280,7 +270,7 @@ public class ConnectedTextureRenderer implements IRenderFace {
vertices.get(indices[1]).xyz.z -= scaleFactor * edge.offsetZ;
}
private int[] getClosest(ForgeDirection edge, List<Vertex> vertices, ForgeDirection face) {
private int[] getClosest(ForgeDirection edge, List<Vertex> vertices) {
int[] res = new int[] { -1, -1 };
boolean highest = edge.offsetX > 0 || edge.offsetY > 0 || edge.offsetZ > 0;
double minMax = highest ? -Double.MAX_VALUE : Double.MAX_VALUE;
@@ -300,26 +290,6 @@ public class ConnectedTextureRenderer implements IRenderFace {
return res;
}
private int[] getClosestVec(Vector3d edge, List<Vector3d> corners, ForgeDirection face) {
int[] res = new int[] { -1, -1 };
boolean highest = edge.x > 0 || edge.y > 0 || edge.z > 0;
double minMax = highest ? -Double.MAX_VALUE : Double.MAX_VALUE;
int index = 0;
for (Vector3d v : corners) {
double val = get(v, edge);
if(highest ? val >= minMax : val <= minMax) {
if(val != minMax) {
res[0] = index;
} else {
res[1] = index;
}
minMax = val;
}
index++;
}
return res;
}
private double get(Vector3d xyz, ForgeDirection edge) {
if(edge == ForgeDirection.EAST || edge == ForgeDirection.WEST) {
return xyz.x;
@@ -330,14 +300,44 @@ public class ConnectedTextureRenderer implements IRenderFace {
return xyz.z;
}
private double get(Vector3d xyz, Vector3d edge) {
if(Math.abs(edge.x) > 0.5) {
return xyz.x;
}
if(Math.abs(edge.y) > 0.5) {
return xyz.y;
}
return xyz.z;
}
// private void moveCornerVec(List<Vector3d> corners, Vector3d edge, float scaleFactor) {
// int[] indices = getClosestVec(edge, corners);
// corners.get(indices[0]).x -= scaleFactor * edge.x;
// corners.get(indices[1]).x -= scaleFactor * edge.x;
// corners.get(indices[0]).y -= scaleFactor * edge.y;
// corners.get(indices[1]).y -= scaleFactor * edge.y;
// corners.get(indices[0]).z -= scaleFactor * edge.z;
// corners.get(indices[1]).z -= scaleFactor * edge.z;
// }
//
// private int[] getClosestVec(Vector3d edge, List<Vector3d> corners) {
// int[] res = new int[] { -1, -1 };
// boolean highest = edge.x > 0 || edge.y > 0 || edge.z > 0;
// double minMax = highest ? -Double.MAX_VALUE : Double.MAX_VALUE;
// int index = 0;
// for (Vector3d v : corners) {
// double val = get(v, edge);
// if(highest ? val >= minMax : val <= minMax) {
// if(val != minMax) {
// res[0] = index;
// } else {
// res[1] = index;
// }
// minMax = val;
// }
// index++;
// }
// return res;
// }
//
// private double get(Vector3d xyz, Vector3d edge) {
// if(Math.abs(edge.x) > 0.5) {
// return xyz.x;
// }
// if(Math.abs(edge.y) > 0.5) {
// return xyz.y;
// }
// return xyz.z;
// }
}
+37
View File
@@ -373,6 +373,43 @@ public class RenderUtil {
return null;
}
public static ForgeDirection getVDirForFace(ForgeDirection face) {
switch (face) {
case DOWN:
case UP:
return ForgeDirection.SOUTH;
case EAST:
case WEST:
case NORTH:
case SOUTH:
return ForgeDirection.UP;
case UNKNOWN:
default:
break;
}
return null;
}
public static ForgeDirection getUDirForFace(ForgeDirection face) {
switch (face) {
case DOWN:
case UP:
return ForgeDirection.EAST;
case EAST:
return ForgeDirection.NORTH;
case WEST:
return ForgeDirection.SOUTH;
case NORTH:
return ForgeDirection.WEST;
case SOUTH:
return ForgeDirection.EAST;
case UNKNOWN:
default:
break;
}
return null;
}
private static class EdgeNeighbour {
final ForgeDirection dir;
final BlockCoord bc;
+3
View File
@@ -24,6 +24,9 @@ enderio.itemRedstoneConduitSwitch=Conduit Switch
enderio.itemRedstoneConduitInsulated=Insulated Redstone Conduit
enderio.itemLiquidConduit=Fluid Conduit
enderio.itemLiquidConduitAdvanced=Pressurized Fluid Conduit
enderio.itemLiquidConduit.lockedType=Fluid type locked to
enderio.itemLiquidConduit.unlockedType=Fluid type unlocked
enderio.itemItemConduit=Item Conduit
enderio.itemItemConduitEmpowered=Empowered Item Conduit
Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 833 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 761 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 864 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB