Rendering and transmitter performance enhancements, finish Rotary Condensentrator for the most part

This commit is contained in:
Aidan Brady 2013-11-28 21:43:53 -05:00
parent ccae995242
commit 00b4c6f3e3
27 changed files with 489 additions and 160 deletions

View file

@ -0,0 +1,8 @@
package mekanism.api;
public interface IClientTicker
{
public void clientTick();
public boolean needsTicks();
}

View file

@ -1,5 +1,6 @@
package mekanism.api.gas;
import mekanism.common.util.MekanismUtils;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Icon;
import net.minecraftforge.fluids.Fluid;
@ -9,7 +10,7 @@ public class Gas
{
private String name;
private String localizedName;
private String unlocalizedName;
private Fluid fluid;
@ -17,7 +18,7 @@ public class Gas
public Gas(String s)
{
name = s;
unlocalizedName = name = s;
}
public String getName()
@ -25,14 +26,19 @@ public class Gas
return name;
}
public String getLocalizedName()
public String getUnlocalizedName()
{
return localizedName;
return "gas." + unlocalizedName;
}
public Gas setLocalizedName(String s)
public String getLocalizedName()
{
localizedName = s;
return MekanismUtils.localize(getUnlocalizedName());
}
public Gas setUnlocalizedName(String s)
{
unlocalizedName = s;
return this;
}
@ -81,6 +87,11 @@ public class Gas
return fluid != null;
}
public Fluid getFluid()
{
return fluid;
}
public Gas registerFluid()
{
if(fluid == null)

View file

@ -21,9 +21,10 @@ public class GasNetwork extends DynamicNetwork<IGasAcceptor, GasNetwork>
{
public int transferDelay = 0;
public float gasScale;
public float prevGasScale;
public boolean didTransfer;
public boolean prevTransfer;
public float gasScale;
public Gas refGas = null;
public GasNetwork(ITransmitter<GasNetwork>... varPipes)
@ -96,16 +97,8 @@ public class GasNetwork extends DynamicNetwork<IGasAcceptor, GasNetwork>
if(sent > 0 && FMLCommonHandler.instance().getEffectiveSide().isServer())
{
if(stack.getGas() == refGas)
{
gasScale = Math.min(1, gasScale+((float)sent/100));
}
else if(refGas == null)
{
refGas = stack.getGas();
gasScale = Math.min(1, ((float)sent/100));
}
refGas = stack.getGas();
didTransfer = true;
transferDelay = 2;
}
@ -121,24 +114,39 @@ public class GasNetwork extends DynamicNetwork<IGasAcceptor, GasNetwork>
{
if(transferDelay == 0)
{
if(gasScale > 0)
{
gasScale = Math.max(0, gasScale-.02F);
}
else {
refGas = null;
}
didTransfer = false;
}
else {
transferDelay--;
}
if(gasScale != prevGasScale)
if(didTransfer != prevTransfer || needsUpdate)
{
MinecraftForge.EVENT_BUS.post(new GasTransferEvent(this, refGas != null ? refGas.getID() : -1, gasScale));
MinecraftForge.EVENT_BUS.post(new GasTransferEvent(this, refGas != null ? refGas.getID() : -1, didTransfer));
needsUpdate = false;
}
prevGasScale = gasScale;
prevTransfer = didTransfer;
}
}
@Override
public void clientTick()
{
super.clientTick();
if(didTransfer && gasScale < 1)
{
gasScale = Math.min(1, gasScale+0.02F);
}
else if(!didTransfer && gasScale > 0)
{
gasScale = Math.max(0, gasScale-0.02F);
if(gasScale == 0)
{
refGas = null;
}
}
}
@ -210,7 +218,7 @@ public class GasNetwork extends DynamicNetwork<IGasAcceptor, GasNetwork>
Set<GasNetwork> networks = new HashSet();
networks.add(this);
networks.add(network);
GasNetwork newNetwork = new GasNetwork(networks);
GasNetwork newNetwork = create(networks);
newNetwork.refresh();
}
}
@ -220,13 +228,13 @@ public class GasNetwork extends DynamicNetwork<IGasAcceptor, GasNetwork>
public final GasNetwork gasNetwork;
public final int transferType;
public final float gasScale;
public final boolean didTransfer;
public GasTransferEvent(GasNetwork network, int type, float scale)
public GasTransferEvent(GasNetwork network, int type, boolean did)
{
gasNetwork = network;
transferType = type;
gasScale = scale;
didTransfer = did;
}
}
@ -239,19 +247,39 @@ public class GasNetwork extends DynamicNetwork<IGasAcceptor, GasNetwork>
@Override
protected GasNetwork create(ITransmitter<GasNetwork>... varTransmitters)
{
return new GasNetwork(varTransmitters);
GasNetwork network = new GasNetwork(varTransmitters);
network.refGas = refGas;
network.gasScale = gasScale;
return network;
}
@Override
protected GasNetwork create(Collection<ITransmitter<GasNetwork>> collection)
{
return new GasNetwork(collection);
GasNetwork network = new GasNetwork(collection);
network.refGas = refGas;
network.gasScale = gasScale;
return network;
}
@Override
protected GasNetwork create(Set<GasNetwork> networks)
{
return new GasNetwork(networks);
GasNetwork network = new GasNetwork(networks);
network.refGas = refGas;
network.gasScale = gasScale;
for(GasNetwork iterNet : networks)
{
if(iterNet.refGas != null && iterNet.gasScale > 0)
{
network.refGas = iterNet.refGas;
network.gasScale = iterNet.gasScale;
break;
}
}
return network;
}
@Override

View file

@ -3,29 +3,22 @@ package mekanism.api.gas;
import java.util.ArrayList;
import java.util.List;
import net.minecraftforge.fluids.Fluid;
public class GasRegistry
{
private static ArrayList<Gas> registeredGasses = new ArrayList<Gas>();
public static void registerOxygen()
public static Gas register(Gas gas)
{
if(getGas("oxygen") == null)
if(gas == null)
{
register(new Gas("oxygen").setLocalizedName("Oxygen"));
return null;
}
}
public static void registerHydrogen()
{
if(getGas("hydrogen") == null)
{
register(new Gas("hydrogen").setLocalizedName("Hydrogen"));
}
}
public static void register(Gas gas)
{
registeredGasses.add(gas);
return getGas(gas.getName());
}
public static Gas getGas(int id)
@ -38,6 +31,19 @@ public class GasRegistry
return registeredGasses.get(id);
}
public static Gas getGas(Fluid f)
{
for(Gas gas : getRegisteredGasses())
{
if(gas.hasFluid() && gas.getFluid() == f)
{
return gas;
}
}
return null;
}
public static boolean containsGas(String name)
{
return getGas(name) != null;

View file

@ -3,23 +3,26 @@ package mekanism.api.transmitters;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import cpw.mods.fml.common.FMLCommonHandler;
import mekanism.api.IClientTicker;
import mekanism.api.Object3D;
import mekanism.client.ClientTickHandler;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.network.PacketDataRequest;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import cpw.mods.fml.common.FMLCommonHandler;
public abstract class DynamicNetwork<A, N> implements ITransmitterNetwork<A, N>
public abstract class DynamicNetwork<A, N> implements ITransmitterNetwork<A, N>, IClientTicker
{
public HashSet<ITransmitter<N>> transmitters = new HashSet<ITransmitter<N>>();
@ -62,9 +65,15 @@ public abstract class DynamicNetwork<A, N> implements ITransmitterNetwork<A, N>
try {
ITransmitter<N> aTransmitter = transmitters.iterator().next();
if(aTransmitter instanceof TileEntity && !((TileEntity)aTransmitter).worldObj.isRemote)
if(aTransmitter instanceof TileEntity)
{
TransmitterNetworkRegistry.getInstance().registerNetwork(this);
if(!((TileEntity)aTransmitter).worldObj.isRemote)
{
TransmitterNetworkRegistry.getInstance().registerNetwork(this);
}
else {
ClientTickHandler.tickingSet.add(this);
}
}
} catch(NoSuchElementException e) {}
}
@ -73,7 +82,14 @@ public abstract class DynamicNetwork<A, N> implements ITransmitterNetwork<A, N>
public void deregister()
{
transmitters.clear();
TransmitterNetworkRegistry.getInstance().removeNetwork(this);
if(FMLCommonHandler.instance().getEffectiveSide().isServer())
{
TransmitterNetworkRegistry.getInstance().removeNetwork(this);
}
else {
ClientTickHandler.tickingSet.remove(this);
}
}
@Override
@ -221,6 +237,24 @@ public abstract class DynamicNetwork<A, N> implements ITransmitterNetwork<A, N>
fixed = value;
}
@Override
public boolean needsTicks()
{
return getSize() > 0;
}
@Override
public void clientTick()
{
ticksSinceCreate++;
if(ticksSinceCreate == 5 && getSize() > 0)
{
TileEntity tile = (TileEntity)transmitters.iterator().next();
PacketHandler.sendPacket(Transmission.SERVER, new PacketDataRequest().setParams(Object3D.get(tile)));
}
}
public void addUpdate(EntityPlayer player)
{
updateQueue.add(new DelayQueue(player));
@ -247,7 +281,7 @@ public abstract class DynamicNetwork<A, N> implements ITransmitterNetwork<A, N>
{
for(int i = 0; i < ignore.length; i++)
{
this.toIgnore.add(ignore[i]);
toIgnore.add(ignore[i]);
}
}
}

View file

@ -65,6 +65,7 @@ public class ClientConnectionHandler implements IConnectionHandler
}
}
ClientTickHandler.tickingSet.clear();
Mekanism.proxy.unloadSoundHandler();
}

View file

@ -431,12 +431,9 @@ public class ClientProxy extends CommonProxy
{
GuiScreen screen = FMLClientHandler.instance().getClient().currentScreen;
if(screen != null)
if(screen != null && screen.doesGuiPauseGame())
{
if(screen.doesGuiPauseGame())
{
return true;
}
return true;
}
}

View file

@ -2,9 +2,13 @@ package mekanism.client;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import mekanism.api.IClientTicker;
import mekanism.common.Mekanism;
import mekanism.common.ObfuscatedNames;
import mekanism.common.util.MekanismUtils;
@ -40,6 +44,8 @@ public class ClientTickHandler implements ITickHandler
private Map<String, CapeBufferDownload> donateDownload = new HashMap<String, CapeBufferDownload>();
private Map<String, CapeBufferDownload> aidanDownload = new HashMap<String, CapeBufferDownload>();
public static Set<IClientTicker> tickingSet = new HashSet<IClientTicker>();
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
@ -63,6 +69,21 @@ public class ClientTickHandler implements ITickHandler
hasNotified = true;
}
if(!Mekanism.proxy.isPaused())
{
for(Iterator<IClientTicker> iter = tickingSet.iterator(); iter.hasNext();)
{
IClientTicker ticker = iter.next();
ticker.clientTick();
if(!ticker.needsTicks())
{
iter.remove();
}
}
}
if(mc.theWorld != null)
{
for(EntityPlayer entityPlayer : (List<EntityPlayer>)mc.theWorld.playerEntities)

View file

@ -33,6 +33,8 @@ public class GuiRotaryCondensentrator extends GuiMekanism
{
super(new ContainerRotaryCondensentrator(inventory, tentity));
tileEntity = tentity;
guiElements.add(new GuiRedstoneControl(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiRotaryCondensentrator.png")));
}
@Override
@ -102,6 +104,15 @@ public class GuiRotaryCondensentrator extends GuiMekanism
else {
drawTexturedModalRect(guiWidth + 4, guiHeight + 4, 176, 18, 18, 18);
}
if(tileEntity.mode == 0)
{
drawTexturedModalRect(guiWidth + 64, guiHeight + 39, 176, tileEntity.isActive ? 123 : 107, 48, 8);
}
else if(tileEntity.mode == 1)
{
drawTexturedModalRect(guiWidth + 64, guiHeight + 39, 176, tileEntity.isActive ? 115 : 99, 48, 8);
}
}
@Override
@ -127,7 +138,7 @@ public class GuiRotaryCondensentrator extends GuiMekanism
public void displayGauge(int xPos, int yPos, int scale, FluidStack fluid, GasStack gas)
{
if(fluid == null)
if(fluid == null && gas == null)
{
return;
}
@ -168,6 +179,6 @@ public class GuiRotaryCondensentrator extends GuiMekanism
}
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiRotaryCondensentrator.png"));
drawTexturedModalRect(guiWidth + xPos, guiHeight + yPos, 176, 40, 16, 60);
drawTexturedModalRect(guiWidth + xPos, guiHeight + yPos, 176, 40, 16, 59);
}
}

View file

@ -86,7 +86,7 @@ public class MachineRenderingHandler implements ISimpleBlockRenderingHandler
{
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
GL11.glRotatef(270F, 0.0F, -1.0F, 0.0F);
GL11.glTranslatef(0.0F, -1F, -0.15F);
GL11.glTranslatef(0.0F, -1F, 0.05F);
Minecraft.getMinecraft().renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "RotaryCondensentrator.png"));
rotaryCondensentrator.render(0.0625F);
}

View file

@ -315,7 +315,8 @@ public class RenderDynamicTank extends TileEntitySpecialRenderer
@Override
public boolean equals(Object data)
{
return data instanceof RenderData && ((RenderData)data).location.equals(location) && ((RenderData)data).height == height;
return data instanceof RenderData && ((RenderData)data).location.equals(location) && ((RenderData)data).height == height &&
((RenderData)data).length == length && ((RenderData)data).width == width;
}
}

View file

@ -35,6 +35,7 @@ public class RenderPressurizedTube extends TileEntitySpecialRenderer
private boolean[] connectable;
private HashMap<BooleanArray, HashMap<Gas, DisplayInteger>> cachedCenterGasses = new HashMap<BooleanArray, HashMap<Gas, DisplayInteger>>();
private HashMap<TubeRenderData, HashMap<Gas, DisplayInteger>> cachedSideGasses = new HashMap<TubeRenderData, HashMap<Gas, DisplayInteger>>();
private static final double offset = 0.015;
@ -200,14 +201,31 @@ public class RenderPressurizedTube extends TileEntitySpecialRenderer
return display;
}
Model3D toReturn = new Model3D();
toReturn.baseBlock = Block.waterStill;
toReturn.setTexture(type.getIcon());
TubeRenderData data = TubeRenderData.get(side, block);
toReturn.setSideRender(side, false);
toReturn.setSideRender(side.getOpposite(), false);
DisplayInteger display = DisplayInteger.createAndStart();
if(cachedSideGasses.containsKey(data) && cachedSideGasses.get(data).containsKey(type))
{
return cachedSideGasses.get(data).get(type);
}
Model3D toReturn = new Model3D();
toReturn.baseBlock = Block.waterStill;
toReturn.setTexture(type.getIcon());
toReturn.setSideRender(side, false);
toReturn.setSideRender(side.getOpposite(), false);
DisplayInteger display = DisplayInteger.createAndStart();
if(cachedSideGasses.containsKey(data))
{
cachedSideGasses.get(data).put(type, display);
}
else {
HashMap<Gas, DisplayInteger> map = new HashMap<Gas, DisplayInteger>();
map.put(type, display);
cachedSideGasses.put(data, map);
}
switch(side)
{
@ -284,4 +302,53 @@ public class RenderPressurizedTube extends TileEntitySpecialRenderer
return display;
}
public static class TubeRenderData
{
public double minX;
public double maxX;
public double minY;
public double maxY;
public double minZ;
public double maxZ;
public ForgeDirection side;
@Override
public int hashCode()
{
int code = 1;
code = 31 * code + new Double(minX).hashCode();
code = 31 * code + new Double(maxX).hashCode();
code = 31 * code + new Double(minY).hashCode();
code = 31 * code + new Double(maxY).hashCode();
code = 31 * code + new Double(minZ).hashCode();
code = 31 * code + new Double(maxZ).hashCode();
code = 31 * code + side.ordinal();
return code;
}
@Override
public boolean equals(Object data)
{
return data instanceof TubeRenderData && ((TubeRenderData)data).minX == minX && ((TubeRenderData)data).maxX == maxX &&
((TubeRenderData)data).minY == minY && ((TubeRenderData)data).maxY == maxY && ((TubeRenderData)data).minZ == minZ &&
((TubeRenderData)data).maxZ == maxZ && ((TubeRenderData)data).side == side;
}
public static TubeRenderData get(ForgeDirection dir, Block b)
{
TubeRenderData data = new TubeRenderData();
data.side = dir;
data.minX = b.getBlockBoundsMinX();
data.maxX = b.getBlockBoundsMaxX();
data.minY = b.getBlockBoundsMinY();
data.maxY = b.getBlockBoundsMaxY();
data.minZ = b.getBlockBoundsMinZ();
data.maxZ = b.getBlockBoundsMaxZ();
return data;
}
}
}

View file

@ -187,6 +187,7 @@ public class CommonProxy
Mekanism.purificationChamberUsage = Mekanism.configuration.get("usage", "PurificationChamberUsage", 50).getDouble(50);
Mekanism.energizedSmelterUsage = Mekanism.configuration.get("usage", "EnergizedSmelterUsage", 50).getDouble(50);
Mekanism.digitalMinerUsage = Mekanism.configuration.get("usage", "DigitalMinerUsage", 100).getDouble(100);
Mekanism.rotaryCondensentratorUsage = Mekanism.configuration.get("usage", "RotaryCondensentratorUsage", 50).getDouble(50);
Mekanism.configuration.save();
}

View file

@ -350,7 +350,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
Set<EnergyNetwork> networks = new HashSet<EnergyNetwork>();
networks.add(this);
networks.add(network);
EnergyNetwork newNetwork = new EnergyNetwork(networks);
EnergyNetwork newNetwork = create(networks);
newNetwork.refresh();
}
}

View file

@ -9,6 +9,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import mekanism.api.gas.GasNetwork;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.ITransmitter;
import mekanism.api.transmitters.TransmissionType;
@ -27,9 +28,10 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
{
public int transferDelay = 0;
public float fluidScale;
public float prevFluidScale;
public boolean didTransfer;
public boolean prevTransfer;
public float fluidScale;
public Fluid refFluid = null;
public FluidNetwork(ITransmitter<FluidNetwork>... varPipes)
@ -118,18 +120,9 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
if(doTransfer && fluidSent > 0 && FMLCommonHandler.instance().getEffectiveSide().isServer())
{
FluidStack sendStack = fluidToSend.copy();
sendStack.amount = fluidSent;
if(sendStack.getFluid() == refFluid)
{
fluidScale = Math.min(1, fluidScale+((float)sendStack.amount/1000F));
}
else if(refFluid == null)
{
refFluid = sendStack.getFluid();
fluidScale = Math.min(1, ((float)sendStack.amount/1000F));
}
refFluid = fluidToSend.getFluid();
didTransfer = true;
transferDelay = 2;
transferDelay = 2;
}
@ -146,24 +139,39 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
{
if(transferDelay == 0)
{
if(fluidScale > 0)
{
fluidScale = Math.max(0, fluidScale-.02F);
}
else {
refFluid = null;
}
didTransfer = false;
}
else {
transferDelay--;
}
if(fluidScale != prevFluidScale)
if(didTransfer != prevTransfer || needsUpdate)
{
MinecraftForge.EVENT_BUS.post(new FluidTransferEvent(this, refFluid != null ? refFluid.getID() : -1, fluidScale));
MinecraftForge.EVENT_BUS.post(new FluidTransferEvent(this, refFluid != null ? refFluid.getID() : -1, didTransfer));
needsUpdate = false;
}
prevFluidScale = fluidScale;
prevTransfer = didTransfer;
}
}
@Override
public void clientTick()
{
super.clientTick();
if(didTransfer && fluidScale < 1)
{
fluidScale = Math.min(1, fluidScale+0.02F);
}
else if(!didTransfer && fluidScale > 0)
{
fluidScale = Math.max(0, fluidScale-0.02F);
if(fluidScale == 0)
{
refFluid = null;
}
}
}
@ -232,7 +240,7 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
Set<FluidNetwork> networks = new HashSet<FluidNetwork>();
networks.add(this);
networks.add(network);
FluidNetwork newNetwork = new FluidNetwork(networks);
FluidNetwork newNetwork = create(networks);
newNetwork.refresh();
}
}
@ -242,13 +250,13 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
public final FluidNetwork fluidNetwork;
public final int fluidType;
public final float fluidScale;
public final boolean didTransfer;
public FluidTransferEvent(FluidNetwork network, int type, float scale)
public FluidTransferEvent(FluidNetwork network, int type, boolean did)
{
fluidNetwork = network;
fluidType = type;
fluidScale = scale;
didTransfer = did;
}
}
@ -261,19 +269,39 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
@Override
protected FluidNetwork create(ITransmitter<FluidNetwork>... varTransmitters)
{
return new FluidNetwork(varTransmitters);
FluidNetwork network = new FluidNetwork(varTransmitters);
network.refFluid = refFluid;
network.fluidScale = fluidScale;
return network;
}
@Override
protected FluidNetwork create(Collection<ITransmitter<FluidNetwork>> collection)
{
return new FluidNetwork(collection);
FluidNetwork network = new FluidNetwork(collection);
network.refFluid = refFluid;
network.fluidScale = fluidScale;
return network;
}
@Override
protected FluidNetwork create(Set<FluidNetwork> networks)
{
return new FluidNetwork(networks);
FluidNetwork network = new FluidNetwork(networks);
network.refFluid = refFluid;
network.fluidScale = fluidScale;
for(FluidNetwork iterNet : networks)
{
if(iterNet.refFluid != null && iterNet.fluidScale > 0)
{
network.refFluid = iterNet.refFluid;
network.fluidScale = iterNet.fluidScale;
break;
}
}
return network;
}
@Override

View file

@ -14,8 +14,9 @@ import java.util.Set;
import java.util.logging.Logger;
import mekanism.api.Object3D;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasNetwork.GasTransferEvent;
import mekanism.api.gas.GasRegistry;
import mekanism.api.infuse.InfuseObject;
import mekanism.api.infuse.InfuseRegistry;
import mekanism.api.infuse.InfuseType;
@ -254,6 +255,7 @@ public class Mekanism
public static double purificationChamberUsage;
public static double energizedSmelterUsage;
public static double digitalMinerUsage;
public static double rotaryCondensentratorUsage;
/**
* Adds all in-game crafting and smelting recipes.
@ -1072,8 +1074,8 @@ public class Mekanism
System.out.println("[Mekanism] Detected Tekkit in root directory - hello, fellow user!");
}
GasRegistry.registerHydrogen();
GasRegistry.registerOxygen();
GasRegistry.register(new Gas("hydrogen")).registerFluid();
GasRegistry.register(new Gas("oxygen")).registerFluid();
Mekanism.proxy.preInit();
@ -1183,7 +1185,7 @@ public class Mekanism
public void onGasTransferred(GasTransferEvent event)
{
try {
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTransmitterUpdate().setParams(PacketType.GAS, event.gasNetwork.transmitters.iterator().next(), event.transferType, event.gasScale));
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTransmitterUpdate().setParams(PacketType.GAS, event.gasNetwork.transmitters.iterator().next(), event.transferType, event.didTransfer));
} catch(Exception e) {}
}
@ -1191,7 +1193,7 @@ public class Mekanism
public void onLiquidTransferred(FluidTransferEvent event)
{
try {
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTransmitterUpdate().setParams(PacketType.FLUID, event.fluidNetwork.transmitters.iterator().next(), event.fluidType, event.fluidScale));
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTransmitterUpdate().setParams(PacketType.FLUID, event.fluidNetwork.transmitters.iterator().next(), event.fluidType, event.didTransfer));
} catch(Exception e) {}
}

View file

@ -14,7 +14,7 @@ import net.minecraftforge.common.ForgeDirection;
public class TankUpdateProtocol
{
public static final int FLUID_PER_TANK = 32000;
public static final int FLUID_PER_TANK = 16000;
/** The dynamic tank nodes that have already been iterated over. */
public Set<TileEntityDynamicTank> iteratedNodes = new HashSet<TileEntityDynamicTank>();

View file

@ -4,13 +4,13 @@ import java.io.DataOutputStream;
import java.util.ArrayList;
import mekanism.api.Object3D;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.ITransmitter;
import mekanism.api.transmitters.TransmissionType;
import mekanism.common.ITileNetwork;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.tileentity.TileEntityDynamicTank;
import mekanism.common.tileentity.TileEntityUniversalCable;
import mekanism.common.tileentity.TileEntityMechanicalPipe;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
@ -57,10 +57,19 @@ public class PacketDataRequest implements IMekanismPacket
((TileEntityDynamicTank)tileEntity).sendStructure = true;
}
if(tileEntity instanceof TileEntityUniversalCable)
if(tileEntity instanceof ITransmitter)
{
((TileEntityUniversalCable)tileEntity).getTransmitterNetwork().addUpdate(player);
return;
ITransmitter transmitter = (ITransmitter)tileEntity;
if(transmitter.getTransmitterNetwork() instanceof DynamicNetwork)
{
((DynamicNetwork)transmitter.getTransmitterNetwork()).addUpdate(player);
}
if(!(tileEntity instanceof TileEntityMechanicalPipe))
{
return;
}
}
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Object3D.get(worldServer.getBlockTileEntity(x, y, z)), ((ITileNetwork)worldServer.getBlockTileEntity(x, y, z)).getNetworkedData(new ArrayList())));

View file

@ -25,10 +25,10 @@ public class PacketTransmitterUpdate implements IMekanismPacket
public double power;
public int gasType;
public float gasScale;
public boolean didGasTransfer;
public int fluidType;
public float fluidScale;
public boolean didFluidTransfer;
@Override
public String getName()
@ -49,11 +49,11 @@ public class PacketTransmitterUpdate implements IMekanismPacket
break;
case GAS:
gasType = (Integer)data[2];
gasScale = (Float)data[3];
didGasTransfer = (Boolean)data[3];
break;
case FLUID:
fluidType = (Integer)data[2];
fluidScale = (Float)data[3];
didFluidTransfer = (Boolean)data[3];
break;
}
@ -94,12 +94,12 @@ public class PacketTransmitterUpdate implements IMekanismPacket
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
Gas gasType = GasRegistry.getGas(dataStream.readInt());
gasScale = dataStream.readFloat();
didGasTransfer = dataStream.readBoolean();
if(tileEntity != null)
{
((TileEntityPressurizedTube)tileEntity).getTransmitterNetwork().refGas = gasType;
((TileEntityPressurizedTube)tileEntity).getTransmitterNetwork().gasScale = gasScale;
((TileEntityPressurizedTube)tileEntity).getTransmitterNetwork().didTransfer = didGasTransfer;
}
}
else if(transmitterType == 3)
@ -108,12 +108,12 @@ public class PacketTransmitterUpdate implements IMekanismPacket
int type = dataStream.readInt();
Fluid fluidType = type != -1 ? FluidRegistry.getFluid(type) : null;
fluidScale = dataStream.readFloat();
didFluidTransfer = dataStream.readBoolean();
if(tileEntity != null)
{
((TileEntityMechanicalPipe)tileEntity).getTransmitterNetwork().refFluid = fluidType;
((TileEntityMechanicalPipe)tileEntity).getTransmitterNetwork().fluidScale = fluidScale;
((TileEntityMechanicalPipe)tileEntity).getTransmitterNetwork().didTransfer = didFluidTransfer;
}
}
}
@ -134,11 +134,11 @@ public class PacketTransmitterUpdate implements IMekanismPacket
break;
case GAS:
dataStream.writeInt(gasType);
dataStream.writeFloat(gasScale);
dataStream.writeBoolean(didGasTransfer);
break;
case FLUID:
dataStream.writeInt(fluidType);
dataStream.writeFloat(fluidScale);
dataStream.writeBoolean(didFluidTransfer);
break;
}
}

View file

@ -492,7 +492,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
super.readFromNBT(nbtTags);
clientActive = isActive = nbtTags.getBoolean("isActive");
recipeType = nbtTags.getInteger("recipeType");
recipeType = Math.min(5, nbtTags.getInteger("recipeType"));
recipeTicks = nbtTags.getInteger("recipeTicks");
controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")];
secondaryEnergyStored = nbtTags.getInteger("secondaryEnergyStored");

View file

@ -9,7 +9,6 @@ import mekanism.api.transmitters.ITransmitter;
import mekanism.api.transmitters.TransmissionType;
import mekanism.api.transmitters.TransmitterNetworkRegistry;
import mekanism.common.FluidNetwork;
import mekanism.common.ITileNetwork;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.PipeUtils;
@ -30,7 +29,7 @@ import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class TileEntityMechanicalPipe extends TileEntityTransmitter<FluidNetwork> implements IFluidHandler, ITileNetwork
public class TileEntityMechanicalPipe extends TileEntityTransmitter<FluidNetwork> implements IFluidHandler
{
/** The fake tank used for fluid transfer calculations. */
public FluidTank dummyTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
@ -145,11 +144,11 @@ public class TileEntityMechanicalPipe extends TileEntityTransmitter<FluidNetwork
if(container != null)
{
FluidStack received = container.drain(side, 100, false);
FluidStack received = container.drain(side.getOpposite(), 100, false);
if(received != null && received.amount != 0)
{
container.drain(side, getTransmitterNetwork().emit(received, true, (TileEntity)container), true);
container.drain(side.getOpposite(), getTransmitterNetwork().emit(received, true, (TileEntity)container), true);
}
}
}

View file

@ -10,6 +10,9 @@ import mekanism.api.gas.ITubeConnection;
import mekanism.api.transmitters.ITransmitter;
import mekanism.api.transmitters.TransmissionType;
import mekanism.api.transmitters.TransmitterNetworkRegistry;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.network.PacketDataRequest;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;

View file

@ -12,7 +12,9 @@ import mekanism.api.gas.IGasAcceptor;
import mekanism.api.gas.IGasStorage;
import mekanism.api.gas.ITubeConnection;
import mekanism.common.IActiveState;
import mekanism.common.IRedstoneControl;
import mekanism.common.ISustainedTank;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.block.BlockMachine.MachineType;
@ -33,7 +35,7 @@ import net.minecraftforge.fluids.IFluidHandler;
import com.google.common.io.ByteArrayDataInput;
public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock implements IActiveState, ISustainedTank, IFluidHandler, IGasStorage, IGasAcceptor, ITubeConnection
public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock implements IActiveState, ISustainedTank, IFluidHandler, IGasStorage, IGasAcceptor, ITubeConnection, IRedstoneControl
{
public GasStack gasTank;
@ -52,6 +54,13 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
public boolean clientActive;
public double prevEnergy;
public final double ENERGY_USAGE = Mekanism.rotaryCondensentratorUsage;
/** This machine's current RedstoneControl type. */
public RedstoneControl controlType = RedstoneControl.DISABLED;
public TileEntityRotaryCondensentrator()
{
super("RotaryCondensentrator", MachineType.ROTARY_CONDENSENTRATOR.baseEnergy);
@ -137,6 +146,20 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
}
}
}
if(getEnergy() >= ENERGY_USAGE && MekanismUtils.canFunction(this) && isValidGas(gasTank) && (fluidTank.getFluid() == null || (fluidTank.getFluid().amount < 10000 && gasEquals(gasTank, fluidTank.getFluid()))))
{
setActive(true);
fluidTank.fill(new FluidStack(getGas().getGas().getFluid(), 1), true);
setGas(new GasStack(getGas().getGas(), getGas().amount-1));
setEnergy(getEnergy() - ENERGY_USAGE);
}
else {
if(prevEnergy >= getEnergy())
{
setActive(false);
}
}
}
else if(mode == 1)
{
@ -215,10 +238,56 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
}
}
}
if(getEnergy() >= ENERGY_USAGE && MekanismUtils.canFunction(this) && isValidFluid(fluidTank.getFluid()) && (gasTank == null || (gasTank.amount < MAX_GAS && gasEquals(gasTank, fluidTank.getFluid()))))
{
setActive(true);
setGas(new GasStack(GasRegistry.getGas(fluidTank.getFluid().getFluid()), getGas() != null ? getGas().amount+1 : 1));
fluidTank.drain(1, true);
setEnergy(getEnergy() - ENERGY_USAGE);
}
else {
if(prevEnergy >= getEnergy())
{
setActive(false);
}
}
}
prevEnergy = getEnergy();
}
}
public boolean isValidGas(GasStack g)
{
if(g == null)
{
return false;
}
return g.getGas().hasFluid();
}
public boolean gasEquals(GasStack gas, FluidStack fluid)
{
if(fluid == null || gas == null || !gas.getGas().hasFluid())
{
return false;
}
return gas.getGas().getFluid() == fluid.getFluid();
}
public boolean isValidFluid(FluidStack f)
{
if(f == null)
{
return false;
}
return GasRegistry.getGas(f.getFluid()) != null;
}
@Override
public void handlePacketData(ByteArrayDataInput dataStream)
{
@ -242,6 +311,8 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
super.handlePacketData(dataStream);
mode = dataStream.readInt();
isActive = dataStream.readBoolean();
controlType = RedstoneControl.values()[dataStream.readInt()];
if(dataStream.readBoolean())
{
@ -269,6 +340,8 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
super.getNetworkedData(data);
data.add(mode);
data.add(isActive);
data.add(controlType.ordinal());
if(fluidTank.getFluid() != null)
{
@ -299,6 +372,9 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
super.readFromNBT(nbtTags);
mode = nbtTags.getInteger("mode");
isActive = nbtTags.getBoolean("isActive");
controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")];
gasTank = GasStack.readFromNBT(nbtTags.getCompoundTag("gasTank"));
if(nbtTags.hasKey("fluidTank"))
@ -313,6 +389,8 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
super.writeToNBT(nbtTags);
nbtTags.setInteger("mode", mode);
nbtTags.setBoolean("isActive", isActive);
nbtTags.setInteger("controlType", controlType.ordinal());
if(gasTank != null)
{
@ -325,6 +403,12 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
}
}
@Override
public boolean canSetFacing(int i)
{
return i != 0 && i != 1;
}
public int getScaledFluidLevel(int i)
{
return fluidTank.getFluid() != null ? fluidTank.getFluid().amount*i / 10000 : 0;
@ -494,4 +578,17 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
return null;
}
@Override
public RedstoneControl getControlType()
{
return controlType;
}
@Override
public void setControlType(RedstoneControl type)
{
controlType = type;
MekanismUtils.saveChunk(this);
}
}

View file

@ -1,14 +1,19 @@
package mekanism.common.tileentity;
import java.util.ArrayList;
import com.google.common.io.ByteArrayDataInput;
import mekanism.api.transmitters.ITransmitter;
import mekanism.api.transmitters.TransmitterNetworkRegistry;
import mekanism.common.ITileNetwork;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public abstract class TileEntityTransmitter<N> extends TileEntity implements ITransmitter<N>
public abstract class TileEntityTransmitter<N> extends TileEntity implements ITransmitter<N>, ITileNetwork
{
public N theNetwork;
@ -81,4 +86,13 @@ public abstract class TileEntityTransmitter<N> extends TileEntity implements ITr
@Override
public void chunkLoad() {}
@Override
public void handlePacketData(ByteArrayDataInput dataStream) throws Exception {}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
return data;
}
}

View file

@ -14,7 +14,6 @@ import mekanism.api.transmitters.ITransmitter;
import mekanism.api.transmitters.TransmissionType;
import mekanism.api.transmitters.TransmitterNetworkRegistry;
import mekanism.common.EnergyNetwork;
import mekanism.common.ITileNetwork;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
@ -34,9 +33,7 @@ import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import cofh.api.energy.IEnergyHandler;
import com.google.common.io.ByteArrayDataInput;
public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwork> implements IPowerReceptor, IEnergySink, IConductor, ITileNetwork, IEnergyHandler
public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwork> implements IPowerReceptor, IEnergySink, IConductor, IEnergyHandler
{
/** A fake power handler used to initiate energy transfer calculations. */
public PowerHandler powerHandler;
@ -244,17 +241,6 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
}
}
@Override
public void validate()
{
super.validate();
if(worldObj.isRemote)
{
PacketHandler.sendPacket(Transmission.SERVER, new PacketDataRequest().setParams(Object3D.get(this)));
}
}
public void setCachedEnergy(double scale)
{
energyScale = scale;
@ -350,15 +336,6 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
{
return Integer.MAX_VALUE;
}
@Override
public void handlePacketData(ByteArrayDataInput dataStream) throws Exception {}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
return data;
}
@Override
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)

View file

@ -49,6 +49,7 @@ import net.minecraft.network.packet.Packet3Chat;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
@ -424,9 +425,9 @@ public final class MekanismUtils
case 3:
return ForgeDirection.WEST;
case 4:
return ForgeDirection.SOUTH;
default:
return ForgeDirection.NORTH;
default:
return ForgeDirection.SOUTH;
}
}
@ -530,6 +531,11 @@ public final class MekanismUtils
return side;
}
public static String localize(String s)
{
return StatCollector.translateToLocal(s);
}
/**
* Increments the output type of a machine's side.
* @param config - configurable machine

View file

@ -113,6 +113,14 @@ item.bronzeIngot.name=Bronze Ingot
item.glowstoneIngot.name=Glowstone Ingot
item.steelIngot.name=Steel Ingot
//Gasses
gas.hydrogen=Hydrogen
gas.oxygen=Oxygen
//Fluids
fluid.hydrogen=Liquid Hydrogen
fluid.oxygen=Liquid Oxygen
//Creative tab
itemGroup.tabMekanism=Mekanism