This commit is contained in:
Aidan Brady 2013-08-03 14:14:28 -04:00
parent 8278bb7794
commit ec9835aa53
4 changed files with 94 additions and 11 deletions

View file

@ -5,6 +5,7 @@ package resonantinduction;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager;
@ -52,6 +53,19 @@ public class PacketHandler implements IPacketHandler
((IPacketReceiver) tileEntity).handle(dataStream);
}
}
else if (packetType == PacketType.DATA_REQUEST.ordinal())
{
int x = dataStream.readInt();
int y = dataStream.readInt();
int z = dataStream.readInt();
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof IPacketReceiver)
{
sendTileEntityPacketToClients(tileEntity, ((IPacketReceiver) tileEntity).getNetworkedData(new ArrayList()));
}
}
}
catch (Exception e)
{
@ -90,12 +104,40 @@ public class PacketHandler implements IPacketHandler
{
output.writeByte((Byte) data);
}
else if (data instanceof Object[])
{
encode((Object[])data, output);
}
}
}
catch (Exception e)
{
}
}
public static void sendDataRequest(TileEntity tileEntity)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream(bytes);
try
{
data.writeInt(PacketType.DATA_REQUEST.ordinal());
data.writeInt(tileEntity.xCoord);
data.writeInt(tileEntity.yCoord);
data.writeInt(tileEntity.zCoord);
}
catch (Exception e)
{
}
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = ResonantInduction.CHANNEL;
packet.data = bytes.toByteArray();
packet.length = packet.data.length;
PacketDispatcher.sendPacketToServer(packet);
}
public static void sendTileEntityPacketToServer(TileEntity tileEntity, Object... dataValues)
{
@ -135,6 +177,7 @@ public class PacketHandler implements IPacketHandler
public static enum PacketType
{
TILE
TILE,
DATA_REQUEST
}
}

View file

@ -1,8 +1,12 @@
package resonantinduction.base;
import java.util.ArrayList;
import com.google.common.io.ByteArrayDataInput;
public interface IPacketReceiver
{
public void handle(ByteArrayDataInput input);
public ArrayList getNetworkedData(ArrayList data);
}

View file

@ -1,7 +1,13 @@
package resonantinduction.contractor;
import java.util.ArrayList;
import java.util.List;
import com.google.common.io.ByteArrayDataInput;
import resonantinduction.PacketHandler;
import resonantinduction.base.IPacketReceiver;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
@ -10,7 +16,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
public class TileEntityEMContractor extends TileEntity
public class TileEntityEMContractor extends TileEntity implements IPacketReceiver
{
public static int MAX_REACH = 40;
public static double MAX_SPEED = .1;
@ -30,7 +36,6 @@ public class TileEntityEMContractor extends TileEntity
@Override
public void updateEntity()
{
System.out.println(facing + " " + worldObj.isRemote);
pushDelay = Math.max(0, pushDelay--);
if(!suck && pushDelay == 0)
@ -41,11 +46,6 @@ public class TileEntityEMContractor extends TileEntity
if(operationBounds != null)
{
List<Entity> list = worldObj.getEntitiesWithinAABB(Entity.class, operationBounds);
if(!list.isEmpty())
{
System.out.println("GOood");
}
for(Entity entity : list)
{
@ -175,6 +175,17 @@ public class TileEntityEMContractor extends TileEntity
}
}
@Override
public void validate()
{
super.validate();
if(worldObj.isRemote)
{
PacketHandler.sendDataRequest(this);
}
}
public void updateBounds()
{
switch(facing)
@ -228,6 +239,12 @@ public class TileEntityEMContractor extends TileEntity
public void setFacing(ForgeDirection side)
{
facing = side;
if(!worldObj.isRemote)
{
PacketHandler.sendTileEntityPacketToClients(this, getNetworkedData(new ArrayList()));
}
updateBounds();
}
@ -248,4 +265,19 @@ public class TileEntityEMContractor extends TileEntity
nbtTags.setInteger("facing", facing.ordinal());
nbtTags.setBoolean("suck", suck);
}
@Override
public void handle(ByteArrayDataInput input)
{
try {
facing = ForgeDirection.getOrientation(input.readInt());
} catch(Exception e) {}
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
data.add(facing.ordinal());
return data;
}
}

View file

@ -3,18 +3,16 @@
*/
package resonantinduction.tesla;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.minecraft.block.BlockFurnace;
import net.minecraft.entity.Entity;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.AxisAlignedBB;
import resonantinduction.ITesla;
import resonantinduction.PacketHandler;
import resonantinduction.ResonantInduction;
@ -179,6 +177,12 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
{
return PacketHandler.getTileEntityPacket(this, (byte) 1, this.getEnergyStored(), this.dyeID);
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
return null;
}
@Override
public void handle(ByteArrayDataInput input)