v5.5.4 Golden Master #2

*Removed full/empty checks for liquid tanks.
*Fixed particles on Electrolytic Separator.
*Javadocs and cleanups.
*Fixed lighting on Mechanical Pipes and Universal Cables.
*Much more efficient client-side energy transferring.
This commit is contained in:
Aidan Brady 2013-04-22 18:15:03 -04:00
parent 4f5ce2f9e9
commit d6373f422b
11 changed files with 239 additions and 119 deletions

View file

@ -60,13 +60,13 @@ public class BlockTransmitter extends Block
{
if(mechanicalPipe.refLiquid.itemID == Block.lavaStill.blockID)
{
return (int)(mechanicalPipe.liquidScale*16F);
return (int)(mechanicalPipe.liquidScale*15F);
}
}
}
else if(tileEntity instanceof TileEntityUniversalCable)
{
return (int)(((TileEntityUniversalCable)tileEntity).liquidScale*16F);
return (int)(((TileEntityUniversalCable)tileEntity).liquidScale*15F);
}
return 0;

View file

@ -10,6 +10,7 @@ import java.util.Map;
import cpw.mods.fml.common.FMLCommonHandler;
import mekanism.api.IMechanicalPipe;
import mekanism.api.IStrictEnergyAcceptor;
import mekanism.api.IUniversalCable;
import net.minecraft.tileentity.TileEntity;
@ -135,6 +136,22 @@ public class EnergyTransferProtocol
}
}
/**
* Updates the client-side cables for rendering.
*/
public void clientUpdate()
{
loopThrough(pointer);
for(TileEntity tileEntity : iteratedCables)
{
if(tileEntity instanceof IUniversalCable)
{
((IUniversalCable)tileEntity).onTransfer();
}
}
}
/**
* Runs the protocol and distributes the energy.
* @return rejected energy
@ -185,15 +202,9 @@ public class EnergyTransferProtocol
}
}
if(prevNeeded > 0 && prevSending > 0)
if(prevNeeded > 0 && prevSending > 0 && FMLCommonHandler.instance().getEffectiveSide().isServer())
{
for(TileEntity tileEntity : iteratedCables)
{
if(tileEntity instanceof IUniversalCable)
{
((IUniversalCable)tileEntity).onTransfer();
}
}
PacketHandler.sendEnergyTransferUpdate(pointer);
}
return energyToSend;

View file

@ -11,34 +11,58 @@ public enum EnumPacketType
{
/** Used for sending a time update to the server. Send this along with an int between 0 and 24. */
TIME(0),
/** Used for sending a weather update to the server. Send this along with an EnumWeatherType. */
WEATHER(1),
/** Used for sending a tile entity update to all clients. Send this along with x, y, and z coordinates of the block. */
TILE_ENTITY(2),
/** Used for sending a control panel GUI request to the server. */
CONTROL_PANEL(3),
/** Used to send a portal FX packet to all clients. */
PORTAL_FX(4),
/** Used to send a teleport packet from an ItemStack to the server. */
PORTABLE_TELEPORT(5),
/** Used to send a digit update packet from a portable teleporter to the server. */
DIGIT_UPDATE(6),
/** Used to send a status update packet from a portable teleporter to the client. */
STATUS_UPDATE(7),
/** Used to request data from the server by tile entities. */
DATA_REQUEST(8),
/** Used to change a Configurator's state on the server side. */
CONFIGURATOR_STATE(9),
/** Used to change an Electric Bow's state on the server side. */
ELECTRIC_BOW_STATE(10),
/** Used to open an Electric Chest's GUI on the server side. */
ELECTRIC_CHEST_SERVER_OPEN(11),
/** Used to open an Electric Chest's GUI on the client side. */
ELECTRIC_CHEST_CLIENT_OPEN(12),
/** Used to send a password update packet to the server. */
ELECTRIC_CHEST_PASSWORD(13),
/** Used to send a lock update packet to the server. */
ELECTRIC_CHEST_LOCK(14),
/** Used to send a liquid transfer update packet to all clients. */
LIQUID_TRANSFER_UPDATE(15),
/** Used to send an energy transfer update packet to all clients. */
ENERGY_TRANSFER_UPDATE(16),
/** Used to send an electrolytic separator particle to all clients. */
ELECTROLYTIC_SEPARATOR_PARTICLE(17),
/** A custom packet type. Handled in PacketHandler. */
CUSTOM(-1);

View file

@ -142,6 +142,23 @@ public class LiquidTransferProtocol
}
}
/**
* Updates the client-side pipes for rendering.
* @param transferred - the LiquidStack of server-side transferred liquid
*/
public void clientUpdate(LiquidStack transferred)
{
loopThrough(pointer);
for(TileEntity tileEntity : iteratedPipes)
{
if(tileEntity instanceof IMechanicalPipe)
{
((IMechanicalPipe)tileEntity).onTransfer(transferred);
}
}
}
/**
* Runs the protocol and distributes the liquid.
* @return liquid transferred
@ -200,17 +217,11 @@ public class LiquidTransferProtocol
}
}
if(liquidSent > 0)
if(liquidSent > 0 && FMLCommonHandler.instance().getEffectiveSide().isServer())
{
for(TileEntity tileEntity : iteratedPipes)
{
if(tileEntity instanceof IMechanicalPipe)
{
LiquidStack sendStack = liquidToSend.copy();
sendStack.amount = liquidSent;
((IMechanicalPipe)tileEntity).onTransfer(sendStack);
}
}
LiquidStack sendStack = liquidToSend.copy();
sendStack.amount = liquidSent;
PacketHandler.sendLiquidTransferUpdate(pointer, sendStack);
}
return liquidSent;

View file

@ -49,7 +49,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Mekanism mod -- adds in Tools, Armor, Weapons, Machines, and Magic. Universal source.
* Mekanism - the mod in which no true definition fits.
* @author AidanBrady
*
*/

View file

@ -9,6 +9,7 @@ import java.util.Random;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.item.IItemElectric;
import mekanism.generators.common.TileEntityElectrolyticSeparator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
@ -16,6 +17,8 @@ import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.LiquidStack;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
@ -388,6 +391,61 @@ public class PacketHandler implements IPacketHandler
e.printStackTrace();
}
}
else if(packetType == EnumPacketType.LIQUID_TRANSFER_UPDATE.id)
{
try {
int x = dataStream.readInt();
int y = dataStream.readInt();
int z = dataStream.readInt();
TileEntity tileEntity = entityplayer.worldObj.getBlockTileEntity(x, y, z);
LiquidStack liquidStack = new LiquidStack(dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
if(tileEntity != null)
{
new LiquidTransferProtocol(tileEntity, null, liquidStack).clientUpdate(liquidStack);
}
} catch(Exception e) {
System.err.println("[Mekanism] Error while handling liquid transfer update packet.");
e.printStackTrace();
}
}
else if(packetType == EnumPacketType.ENERGY_TRANSFER_UPDATE.id)
{
try {
int x = dataStream.readInt();
int y = dataStream.readInt();
int z = dataStream.readInt();
TileEntity tileEntity = entityplayer.worldObj.getBlockTileEntity(x, y, z);
if(tileEntity != null)
{
new EnergyTransferProtocol(tileEntity, null, new ArrayList()).clientUpdate();
}
} catch(Exception e) {
System.err.println("[Mekanism] Error while handling energy transfer update packet.");
e.printStackTrace();
}
}
else if(packetType == EnumPacketType.ELECTROLYTIC_SEPARATOR_PARTICLE.id)
{
try {
int x = dataStream.readInt();
int y = dataStream.readInt();
int z = dataStream.readInt();
TileEntityElectrolyticSeparator tileEntity = (TileEntityElectrolyticSeparator)entityplayer.worldObj.getBlockTileEntity(x, y, z);
if(tileEntity != null)
{
tileEntity.spawnParticle();
}
} catch(Exception e) {
System.err.println("[Mekanism] Error while handling energy transfer update packet.");
e.printStackTrace();
}
}
} catch(Exception e) {
System.err.println("[Mekanism] Error while handling packet.");
e.printStackTrace();
@ -520,8 +578,13 @@ public class PacketHandler implements IPacketHandler
packet.data = bytes.toByteArray();
packet.length = packet.data.length;
if(distance == 0) PacketDispatcher.sendPacketToAllPlayers(packet);
else PacketDispatcher.sendPacketToAllAround(sender.xCoord, sender.yCoord, sender.zCoord, distance, sender.worldObj.provider.dimensionId, packet);
if(distance == 0)
{
PacketDispatcher.sendPacketToAllPlayers(packet);
}
else {
PacketDispatcher.sendPacketToAllAround(sender.xCoord, sender.yCoord, sender.zCoord, distance, sender.worldObj.provider.dimensionId, packet);
}
} catch (IOException e) {
System.err.println("[Mekanism] Error while writing tile entity packet.");
e.printStackTrace();
@ -826,6 +889,92 @@ public class PacketHandler implements IPacketHandler
}
}
/**
* Sends a packet to the client-side with a LiquidTransferProtocol's information. Used for render updates.
* @param head - head TileEntity of the calculation
* @param resource - the LiquidStack transferred by the server
*/
public static void sendLiquidTransferUpdate(TileEntity head, LiquidStack resource)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(bytes);
try {
output.writeInt(EnumPacketType.LIQUID_TRANSFER_UPDATE.id);
output.writeInt(head.xCoord);
output.writeInt(head.yCoord);
output.writeInt(head.zCoord);
output.writeInt(resource.itemID);
output.writeInt(resource.amount);
output.writeInt(resource.itemMeta);
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = "Mekanism";
packet.data = bytes.toByteArray();
packet.length = packet.data.length;
PacketDispatcher.sendPacketToAllPlayers(packet);
} catch (IOException e) {
System.err.println("[Mekanism] Error while writing tile entity packet.");
e.printStackTrace();
}
}
/**
* Sends a packet to the client-side with an EnergyTransferProtocol's information. Used for render updates.
* @param head - head TileEntity of the calculation
*/
public static void sendEnergyTransferUpdate(TileEntity head)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(bytes);
try {
output.writeInt(EnumPacketType.ENERGY_TRANSFER_UPDATE.id);
output.writeInt(head.xCoord);
output.writeInt(head.yCoord);
output.writeInt(head.zCoord);
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = "Mekanism";
packet.data = bytes.toByteArray();
packet.length = packet.data.length;
PacketDispatcher.sendPacketToAllPlayers(packet);
} catch (IOException e) {
System.err.println("[Mekanism] Error while writing tile entity packet.");
e.printStackTrace();
}
}
/**
* Sends a request to clients near an Electrolytic Separator to emit a gas dump particle.
* @param tileEntity - TileEntity who is emitting the particle
*/
public static void sendElectrolyticSeparatorParticle(TileEntityElectrolyticSeparator tileEntity)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(bytes);
try {
output.writeInt(EnumPacketType.ELECTROLYTIC_SEPARATOR_PARTICLE.id);
output.writeInt(tileEntity.xCoord);
output.writeInt(tileEntity.yCoord);
output.writeInt(tileEntity.zCoord);
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = "Mekanism";
packet.data = bytes.toByteArray();
packet.length = packet.data.length;
PacketDispatcher.sendPacketToAllAround(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, 40, tileEntity.worldObj.provider.dimensionId, packet);
} catch (IOException e) {
System.err.println("[Mekanism] Error while writing tile entity packet.");
e.printStackTrace();
}
}
/**
* Sends the server the defined packet data int.
* @param type - packet type

View file

@ -47,11 +47,6 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
/** The nodes that have already been sucked up, but are held on to in order to remove dead blocks */
public Set<BlockVector> cleaningNodes = new HashSet<BlockVector>();
/** Random for this pump */
public Random random = new Random();
public boolean prevEmpty;
public TileEntityElectricPump()
{
super("Electric Pump", 10000);
@ -121,16 +116,6 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
super.onUpdate();
if(!worldObj.isRemote)
{
if(prevEmpty != (liquidTank.getLiquid() == null || liquidTank.getLiquid().amount == 0))
{
PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList()));
}
prevEmpty = liquidTank.getLiquid() == null;
}
if(liquidTank.getLiquid() != null)
{
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)

View file

@ -25,8 +25,6 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
{
public LiquidTank dummyTank = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME);
public LiquidStack prevLiquid;
public LiquidStack refLiquid = null;
public boolean isActive = false;
@ -58,16 +56,14 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
@Override
public void updateEntity()
{
if(!worldObj.isRemote)
if(worldObj.isRemote)
{
if(liquidScale != prevScale || refLiquid != prevLiquid)
if(liquidScale != prevScale)
{
worldObj.updateAllLightTypes(xCoord, yCoord, zCoord);
PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList()));
}
prevScale = liquidScale;
prevLiquid = refLiquid;
if(liquidScale > 0)
{
@ -76,7 +72,8 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
else {
refLiquid = null;
}
}
else {
if(isActive)
{
ITankContainer[] connectedAcceptors = PipeUtils.getConnectedAcceptors(this);

View file

@ -2,25 +2,20 @@ package mekanism.common;
import java.util.ArrayList;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mekanism.api.IUniversalCable;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework;
import buildcraft.api.power.PowerProvider;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidStack;
import mekanism.api.IUniversalCable;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class TileEntityUniversalCable extends TileEntity implements IUniversalCable, IPowerReceptor, ITileNetwork
public class TileEntityUniversalCable extends TileEntity implements IUniversalCable, IPowerReceptor
{
public CablePowerProvider powerProvider;
@ -40,12 +35,11 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa
@Override
public void updateEntity()
{
if(!worldObj.isRemote)
if(worldObj.isRemote)
{
if(liquidScale != prevScale)
{
worldObj.updateAllLightTypes(xCoord, yCoord, zCoord);
PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList()));
}
prevScale = liquidScale;
@ -57,30 +51,6 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa
}
}
@Override
public void validate()
{
super.validate();
if(worldObj.isRemote)
{
PacketHandler.sendDataRequest(this);
}
}
@Override
public void handlePacketData(ByteArrayDataInput dataStream)
{
liquidScale = dataStream.readFloat();
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
data.add(liquidScale);
return data;
}
@Override
public boolean canTransferEnergy(TileEntity fromTile)
{

View file

@ -6,6 +6,7 @@ import ic2.api.IElectricItem;
import ic2.api.energy.tile.IEnergySink;
import java.util.ArrayList;
import java.util.Random;
import mekanism.api.EnumGas;
import mekanism.api.GasTransmission;
@ -65,12 +66,6 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
/** Type type of gas this block is dumping. */
public EnumGas dumpType;
/** Previous tank full state. */
public boolean prevTankFull;
/** Previous tank empty state. */
public boolean prevTankEmpty;
public TileEntityElectrolyticSeparator()
{
@ -209,23 +204,15 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
}
}
if(prevTankFull != (waterTank.getLiquid() != null && waterTank.getLiquid().amount == waterTank.getCapacity()) || prevTankEmpty != (waterTank.getLiquid() == null || waterTank.getLiquid().amount == 0))
{
PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList()));
}
prevTankFull = waterTank.getLiquid() != null && waterTank.getLiquid().amount == waterTank.getCapacity();
prevTankEmpty = waterTank.getLiquid() == null;
}
if(dumpType != EnumGas.NONE && getGas(dumpType) > 0)
{
if(!worldObj.isRemote)
if(dumpType != EnumGas.NONE && getGas(dumpType) > 0)
{
setGas(dumpType, (getGas(dumpType) - 8));
if(new Random().nextInt(3) == 2)
{
PacketHandler.sendElectrolyticSeparatorParticle(this);
}
}
spawnParticle();
}
}

View file

@ -37,12 +37,6 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements ITan
/** The amount of electricity this machine can produce with a unit of fuel. */
public final int GENERATION = 80;
/** Previous tank full state. */
public boolean prevTankFull;
/** Previous tank empty state. */
public boolean prevTankEmpty;
public TileEntityHeatGenerator()
{
super("Heat Generator", 160000, 160);
@ -113,14 +107,6 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements ITan
else {
setActive(false);
}
if(prevTankFull != (lavaTank.getLiquid() != null && lavaTank.getLiquid().amount == lavaTank.getCapacity()) || prevTankEmpty != (lavaTank.getLiquid() == null || lavaTank.getLiquid().amount == 0))
{
PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList()));
}
prevTankFull = lavaTank.getLiquid() != null && lavaTank.getLiquid().amount == lavaTank.getCapacity();
prevTankEmpty = lavaTank.getLiquid() == null;
}
}