Merge branch 'master' into development

Conflicts:
	build.gradle
	build.properties
	common/mekanism/common/network/PacketPortableTeleport.java
	common/mekanism/tools/common/MekanismTools.java
	etc/core/mcmod.info
	etc/generators/mcmod.info
	etc/tools/mcmod.info
	src/main/java/mekanism/common/EnergyNetwork.java
	src/main/java/mekanism/common/Mekanism.java
	src/main/java/mekanism/common/PacketHandler.java
	src/main/java/mekanism/common/network/PacketTransmitterUpdate.java
	src/main/java/mekanism/common/tile/TileEntityChargepad.java
	src/main/java/mekanism/common/tile/TileEntityEnergyCube.java
	src/main/java/mekanism/common/tile/TileEntityLogisticalSorter.java
	src/main/java/mekanism/generators/common/MekanismGenerators.java
This commit is contained in:
Aidan C. Brady 2014-06-08 12:01:08 +02:00
commit d436c70421
4 changed files with 72 additions and 172 deletions

View file

@ -14,6 +14,7 @@ import mekanism.api.Coord4D;
import mekanism.api.IClientTicker;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.common.MinecraftForge;
@ -28,6 +29,8 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
public HashMap<A, ForgeDirection> acceptorDirections = new HashMap<A, ForgeDirection>();
private List<DelayQueue> updateQueue = new ArrayList<DelayQueue>();
protected AxisAlignedBB packetRange = null;
protected int ticksSinceCreate = 0;
@ -54,6 +57,65 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
{
return transmitters.iterator().next().equals(transmitter);
}
public AxisAlignedBB getPacketRange()
{
if(packetRange == null)
{
return genPacketRange();
}
return packetRange;
}
public int getDimension()
{
if(getSize() == 0)
{
return 0;
}
return transmitters.iterator().next().getLocation().dimensionId;
}
protected AxisAlignedBB genPacketRange()
{
if(getSize() == 0)
{
deregister();
return null;
}
Coord4D initCoord = transmitters.iterator().next().getLocation();
int minX = initCoord.xCoord;
int minY = initCoord.yCoord;
int minZ = initCoord.zCoord;
int maxX = initCoord.xCoord;
int maxY = initCoord.yCoord;
int maxZ = initCoord.zCoord;
for(IGridTransmitter transmitter : transmitters)
{
Coord4D coord = transmitter.getLocation();
if(coord.xCoord < minX) minX = coord.xCoord;
if(coord.yCoord < minY) minY = coord.yCoord;
if(coord.zCoord < minZ) minZ = coord.zCoord;
if(coord.xCoord > maxX) maxX = coord.xCoord;
if(coord.yCoord > maxY) maxY = coord.yCoord;
if(coord.zCoord > maxZ) maxZ = coord.zCoord;
}
minX -= 40;
minY -= 40;
minZ -= 40;
maxX += 40;
maxY += 40;
maxZ += 40;
return AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
}
@Override
public void removeTransmitter(IGridTransmitter<N> transmitter)

View file

@ -1,5 +1,6 @@
package mekanism.api.transmitters;
import mekanism.api.Coord4D;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
@ -60,4 +61,6 @@ public interface IGridTransmitter<N extends DynamicNetwork<?, N>> extends ITrans
public String getTransmitterNetworkFlow();
public int getCapacity();
public Coord4D getLocation();
}

View file

@ -4,69 +4,13 @@ import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
/**
* Mekanism packet handler. As always, use packets sparingly!
* @author AidanBrady
*
*/
public class PacketHandler //implements IPacketHandler
public class PacketHandler
{
/*
/** The ArrayList of registered packet classes, who's index tells which packet is which. *
public static List<Class<? extends IMekanismPacket>> packets = new ArrayList<Class<? extends IMekanismPacket>>();
@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player)
{
ByteArrayDataInput dataStream = ByteStreams.newDataInput(packet.data);
EntityPlayer entityplayer = (EntityPlayer)player;
if(packet.channel.equals("MEK"))
{
try {
int packetIndex = dataStream.readInt();
if(packets.get(packetIndex) == null)
{
Mekanism.logger.error("Received unknown packet identifier '" + packetIndex + ".' Ignorning!");
return;
}
IMekanismPacket packetType = packets.get(packetIndex).newInstance();
if(packetType == null)
{
Mekanism.logger.error("Unable to create instance of packet type '" + packetIndex + ".' Ignoring!");
return;
}
try {
packetType.read(dataStream, entityplayer, entityplayer.worldObj);
} catch(Exception e) {
Mekanism.logger.error("Error while reading '" + packetType.getName() + "' packet.");
e.printStackTrace();
}
} catch(Exception e) {
Mekanism.logger.error("Error while handling packet.");
e.printStackTrace();
}
}
}
/**
* Registers a packet class for identification and reflection purposes. This MUST be called both server-side and client-side,
* otherwise the packet will not be handled correctly.
* @param packetClass - class of the packet to register
*
public static void registerPacket(Class<? extends IMekanismPacket> packetClass)
{
if(!packets.contains(packetClass))
{
packets.add(packetClass);
}
}*/
/**
* Encodes an Object[] of data into a DataOutputStream.
* @param dataValues - an Object[] of data to encode
@ -136,119 +80,4 @@ public class PacketHandler //implements IPacketHandler
{
return new String(input.readBytes(input.readInt()).array());
}
/*/**
* Sends a packet with the defined type of transmission.
* @param trans - the type of transmission to use with this packet
* @param packetType - the object representing this packet, both registered and properly using write()
* @param transParams - any extra parameters the transmission type requires
*
public static void sendPacket(Transmission trans, IMekanismPacket packetType, Object... transParams)
{
if(packetType == null)
{
Mekanism.logger.error("Attempted to send null packet, ignoring!");
return;
}
if(!packets.contains(packetType.getClass()))
{
Mekanism.logger.error("Attempted to send unregistered packet '" + packetType.getName() + ",' ignoring!");
return;
}
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream(bytes);
try {
data.writeInt(packets.indexOf(packetType.getClass()));
packetType.write(data);
} catch(Exception e) {
Mekanism.logger.error("Error while encoding packet data.");
e.printStackTrace();
}
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = "MEK";
packet.data = bytes.toByteArray();
packet.length = packet.data.length;
switch(trans)
{
case SERVER:
PacketDispatcher.sendPacketToServer(packet);
break;
case ALL_CLIENTS:
PacketDispatcher.sendPacketToAllPlayers(packet);
break;
case CLIENTS_RANGE:
Coord4D obj = (Coord4D)transParams[0];
PacketDispatcher.sendPacketToAllAround(obj.xCoord, obj.yCoord, obj.zCoord, (Double)transParams[1], obj.dimensionId, packet);
break;
case CLIENTS_DIM:
PacketDispatcher.sendPacketToAllInDimension(packet, (Integer)transParams[0]);
break;
case SINGLE_CLIENT:
((EntityPlayerMP)transParams[0]).playerNetServerHandler.sendPacketToPlayer(packet);
break;
}
log(trans, packetType, transParams);
}
/**
* Writes a log to the console with information about a packet recently sent.
* @param trans - transmission type this packet used when it was sent
* @param packetType - object representing this packet
* @param transParams - any extra parameters the transmission type requires
*
private static void log(Transmission trans, IMekanismPacket packetType, Object[] transParams)
{
if(Mekanism.logPackets)
{
switch(trans)
{
case SERVER:
Mekanism.logger.info("Sent '" + packetType.getName() + "' packet to server.");
break;
case ALL_CLIENTS:
Mekanism.logger.info("Sent '" + packetType.getName() + "' packet to all clients.");
break;
case CLIENTS_RANGE:
Mekanism.logger.info("Sent '" + packetType.getName() + "' packet to clients in a " + (Double)transParams[1] + " block range.");
break;
case CLIENTS_DIM:
Mekanism.logger.info("Sent '" + packetType.getName() + "' packet to clients in dimension ID " + (Integer)transParams[0] + ".");
break;
case SINGLE_CLIENT:
Mekanism.logger.info("Sent '" + packetType.getName() + "' packet to " + ((EntityPlayer)transParams[0]).username);
break;
}
}
}
public static enum Transmission
{
/** No additional parameters. *
SERVER(0),
/** No additional parameters. *
ALL_CLIENTS(0),
/** 2 parameters - Object3D representing the location of the transmission, and a double of the distance this packet can be sent in. *
CLIENTS_RANGE(2),
/** 1 parameter - int representing the dimension ID to send this packet to. *
CLIENTS_DIM(1),
/** 1 parameter - EntityPlayer to send this packet to. *
SINGLE_CLIENT(1),
public int parameters;
private Transmission(int params)
{
parameters = params;
}
}*/
}

View file

@ -216,6 +216,12 @@ public abstract class PartTransmitter<N extends DynamicNetwork<?, N>> extends Pa
Mekanism.packetPipeline.sendToDimension(new PacketTransmitterUpdate(PacketType.UPDATE, tile()), world().provider.dimensionId);
}
}
@Override
public Coord4D getLocation()
{
return Coord4D.get(tile());
}
@Override
public void chunkLoad() {}