Remove INetworkTile, the mod should be now much performant on servers. Packets are only sent when needed.
This commit is contained in:
@@ -7,8 +7,11 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||||||
import net.minecraft.nbt.NBTTagIntArray;
|
import net.minecraft.nbt.NBTTagIntArray;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.util.Constants;
|
import net.minecraftforge.common.util.Constants;
|
||||||
|
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
import refinedstorage.inventory.InventorySimple;
|
import refinedstorage.inventory.InventorySimple;
|
||||||
import refinedstorage.item.ItemUpgrade;
|
import refinedstorage.item.ItemUpgrade;
|
||||||
|
|
||||||
@@ -287,4 +290,14 @@ public class RefinedStorageUtils {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void sendToAllAround(World world, BlockPos pos, IMessage message) {
|
||||||
|
NetworkRegistry.TargetPoint target = new NetworkRegistry.TargetPoint(world.provider.getDimensionType().getId(), pos.getX(), pos.getY(), pos.getZ(), 64);
|
||||||
|
|
||||||
|
RefinedStorage.NETWORK.sendToAllAround(message, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reRenderBlock(World world, BlockPos pos) {
|
||||||
|
world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 1 | 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
62
src/main/java/refinedstorage/network/MessageControllerEnergyUpdate.java
Executable file
62
src/main/java/refinedstorage/network/MessageControllerEnergyUpdate.java
Executable file
@@ -0,0 +1,62 @@
|
|||||||
|
package refinedstorage.network;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||||
|
import refinedstorage.RefinedStorageUtils;
|
||||||
|
import refinedstorage.tile.TileController;
|
||||||
|
|
||||||
|
public class MessageControllerEnergyUpdate implements IMessage, IMessageHandler<MessageControllerEnergyUpdate, IMessage> {
|
||||||
|
private int x;
|
||||||
|
private int y;
|
||||||
|
private int z;
|
||||||
|
private int energy;
|
||||||
|
|
||||||
|
public MessageControllerEnergyUpdate() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageControllerEnergyUpdate(TileController controller) {
|
||||||
|
this.x = controller.getPos().getX();
|
||||||
|
this.y = controller.getPos().getY();
|
||||||
|
this.z = controller.getPos().getZ();
|
||||||
|
this.energy = controller.getEnergyStored(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
x = buf.readInt();
|
||||||
|
y = buf.readInt();
|
||||||
|
z = buf.readInt();
|
||||||
|
energy = buf.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
buf.writeInt(x);
|
||||||
|
buf.writeInt(y);
|
||||||
|
buf.writeInt(z);
|
||||||
|
buf.writeInt(energy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMessage onMessage(MessageControllerEnergyUpdate message, MessageContext ctx) {
|
||||||
|
BlockPos pos = new BlockPos(message.x, message.y, message.z);
|
||||||
|
|
||||||
|
World world = Minecraft.getMinecraft().theWorld;
|
||||||
|
|
||||||
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
|
|
||||||
|
if (tile instanceof TileController) {
|
||||||
|
((TileController) tile).setEnergyStored(message.energy);
|
||||||
|
|
||||||
|
RefinedStorageUtils.reRenderBlock(world, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
62
src/main/java/refinedstorage/network/MessageDetectorPoweredUpdate.java
Executable file
62
src/main/java/refinedstorage/network/MessageDetectorPoweredUpdate.java
Executable file
@@ -0,0 +1,62 @@
|
|||||||
|
package refinedstorage.network;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||||
|
import refinedstorage.RefinedStorageUtils;
|
||||||
|
import refinedstorage.tile.TileDetector;
|
||||||
|
|
||||||
|
public class MessageDetectorPoweredUpdate implements IMessage, IMessageHandler<MessageDetectorPoweredUpdate, IMessage> {
|
||||||
|
private int x;
|
||||||
|
private int y;
|
||||||
|
private int z;
|
||||||
|
private boolean powered;
|
||||||
|
|
||||||
|
public MessageDetectorPoweredUpdate() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageDetectorPoweredUpdate(TileDetector detector) {
|
||||||
|
this.x = detector.getPos().getX();
|
||||||
|
this.y = detector.getPos().getY();
|
||||||
|
this.z = detector.getPos().getZ();
|
||||||
|
this.powered = detector.isPowered();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
x = buf.readInt();
|
||||||
|
y = buf.readInt();
|
||||||
|
z = buf.readInt();
|
||||||
|
powered = buf.readBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
buf.writeInt(x);
|
||||||
|
buf.writeInt(y);
|
||||||
|
buf.writeInt(z);
|
||||||
|
buf.writeBoolean(powered);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMessage onMessage(MessageDetectorPoweredUpdate message, MessageContext ctx) {
|
||||||
|
BlockPos pos = new BlockPos(message.x, message.y, message.z);
|
||||||
|
|
||||||
|
World world = Minecraft.getMinecraft().theWorld;
|
||||||
|
|
||||||
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
|
|
||||||
|
if (tile instanceof TileDetector) {
|
||||||
|
((TileDetector) tile).setPowered(message.powered);
|
||||||
|
|
||||||
|
RefinedStorageUtils.reRenderBlock(world, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
62
src/main/java/refinedstorage/network/MessageMachineConnectedUpdate.java
Executable file
62
src/main/java/refinedstorage/network/MessageMachineConnectedUpdate.java
Executable file
@@ -0,0 +1,62 @@
|
|||||||
|
package refinedstorage.network;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||||
|
import refinedstorage.RefinedStorageUtils;
|
||||||
|
import refinedstorage.tile.TileMachine;
|
||||||
|
|
||||||
|
public class MessageMachineConnectedUpdate implements IMessage, IMessageHandler<MessageMachineConnectedUpdate, IMessage> {
|
||||||
|
private int x;
|
||||||
|
private int y;
|
||||||
|
private int z;
|
||||||
|
private boolean connected;
|
||||||
|
|
||||||
|
public MessageMachineConnectedUpdate() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageMachineConnectedUpdate(TileMachine machine) {
|
||||||
|
this.x = machine.getPos().getX();
|
||||||
|
this.y = machine.getPos().getY();
|
||||||
|
this.z = machine.getPos().getZ();
|
||||||
|
this.connected = machine.isConnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
x = buf.readInt();
|
||||||
|
y = buf.readInt();
|
||||||
|
z = buf.readInt();
|
||||||
|
connected = buf.readBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
buf.writeInt(x);
|
||||||
|
buf.writeInt(y);
|
||||||
|
buf.writeInt(z);
|
||||||
|
buf.writeBoolean(connected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMessage onMessage(MessageMachineConnectedUpdate message, MessageContext ctx) {
|
||||||
|
BlockPos pos = new BlockPos(message.x, message.y, message.z);
|
||||||
|
|
||||||
|
World world = Minecraft.getMinecraft().theWorld;
|
||||||
|
|
||||||
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
|
|
||||||
|
if (tile instanceof TileMachine) {
|
||||||
|
((TileMachine) tile).setConnected(message.connected);
|
||||||
|
|
||||||
|
RefinedStorageUtils.reRenderBlock(world, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
62
src/main/java/refinedstorage/network/MessageSoldererWorkingUpdate.java
Executable file
62
src/main/java/refinedstorage/network/MessageSoldererWorkingUpdate.java
Executable file
@@ -0,0 +1,62 @@
|
|||||||
|
package refinedstorage.network;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||||
|
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||||
|
import refinedstorage.RefinedStorageUtils;
|
||||||
|
import refinedstorage.tile.solderer.TileSolderer;
|
||||||
|
|
||||||
|
public class MessageSoldererWorkingUpdate implements IMessage, IMessageHandler<MessageSoldererWorkingUpdate, IMessage> {
|
||||||
|
private int x;
|
||||||
|
private int y;
|
||||||
|
private int z;
|
||||||
|
private boolean working;
|
||||||
|
|
||||||
|
public MessageSoldererWorkingUpdate() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageSoldererWorkingUpdate(TileSolderer solderer) {
|
||||||
|
this.x = solderer.getPos().getX();
|
||||||
|
this.y = solderer.getPos().getY();
|
||||||
|
this.z = solderer.getPos().getZ();
|
||||||
|
this.working = solderer.isWorking();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
x = buf.readInt();
|
||||||
|
y = buf.readInt();
|
||||||
|
z = buf.readInt();
|
||||||
|
working = buf.readBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
buf.writeInt(x);
|
||||||
|
buf.writeInt(y);
|
||||||
|
buf.writeInt(z);
|
||||||
|
buf.writeBoolean(working);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMessage onMessage(MessageSoldererWorkingUpdate message, MessageContext ctx) {
|
||||||
|
BlockPos pos = new BlockPos(message.x, message.y, message.z);
|
||||||
|
|
||||||
|
World world = Minecraft.getMinecraft().theWorld;
|
||||||
|
|
||||||
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
|
|
||||||
|
if (tile instanceof TileSolderer) {
|
||||||
|
((TileSolderer) tile).setWorking(message.working);
|
||||||
|
|
||||||
|
RefinedStorageUtils.reRenderBlock(world, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||||
import refinedstorage.tile.INetworkTile;
|
import refinedstorage.tile.ISynchronizedContainer;
|
||||||
|
|
||||||
public class MessageTileContainerUpdate implements IMessage, IMessageHandler<MessageTileContainerUpdate, IMessage> {
|
public class MessageTileContainerUpdate implements IMessage, IMessageHandler<MessageTileContainerUpdate, IMessage> {
|
||||||
private TileEntity tile;
|
private TileEntity tile;
|
||||||
@@ -31,8 +31,8 @@ public class MessageTileContainerUpdate implements IMessage, IMessageHandler<Mes
|
|||||||
if (Minecraft.getMinecraft().theWorld != null) {
|
if (Minecraft.getMinecraft().theWorld != null) {
|
||||||
tile = Minecraft.getMinecraft().theWorld.getTileEntity(new BlockPos(x, y, z));
|
tile = Minecraft.getMinecraft().theWorld.getTileEntity(new BlockPos(x, y, z));
|
||||||
|
|
||||||
if (tile instanceof INetworkTile) {
|
if (tile instanceof ISynchronizedContainer) {
|
||||||
((INetworkTile) tile).receiveContainerData(buf);
|
((ISynchronizedContainer) tile).receiveContainerData(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,8 +43,8 @@ public class MessageTileContainerUpdate implements IMessage, IMessageHandler<Mes
|
|||||||
buf.writeInt(tile.getPos().getY());
|
buf.writeInt(tile.getPos().getY());
|
||||||
buf.writeInt(tile.getPos().getZ());
|
buf.writeInt(tile.getPos().getZ());
|
||||||
|
|
||||||
if (tile instanceof INetworkTile) {
|
if (tile instanceof ISynchronizedContainer) {
|
||||||
((INetworkTile) tile).sendContainerData(buf);
|
((ISynchronizedContainer) tile).sendContainerData(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
package refinedstorage.network;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
|
||||||
import refinedstorage.tile.INetworkTile;
|
|
||||||
|
|
||||||
public class MessageTileUpdate implements IMessage, IMessageHandler<MessageTileUpdate, IMessage> {
|
|
||||||
private TileEntity tile;
|
|
||||||
private int x;
|
|
||||||
private int y;
|
|
||||||
private int z;
|
|
||||||
|
|
||||||
public MessageTileUpdate() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageTileUpdate(TileEntity tile) {
|
|
||||||
this.tile = tile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fromBytes(ByteBuf buf) {
|
|
||||||
x = buf.readInt();
|
|
||||||
y = buf.readInt();
|
|
||||||
z = buf.readInt();
|
|
||||||
|
|
||||||
if (Minecraft.getMinecraft().theWorld != null) {
|
|
||||||
tile = Minecraft.getMinecraft().theWorld.getTileEntity(new BlockPos(x, y, z));
|
|
||||||
|
|
||||||
if (tile instanceof INetworkTile) {
|
|
||||||
((INetworkTile) tile).receiveData(buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void toBytes(ByteBuf buf) {
|
|
||||||
buf.writeInt(tile.getPos().getX());
|
|
||||||
buf.writeInt(tile.getPos().getY());
|
|
||||||
buf.writeInt(tile.getPos().getZ());
|
|
||||||
|
|
||||||
if (tile instanceof INetworkTile) {
|
|
||||||
((INetworkTile) tile).sendData(buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IMessage onMessage(MessageTileUpdate message, MessageContext ctx) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -33,7 +33,6 @@ import static refinedstorage.RefinedStorage.ID;
|
|||||||
|
|
||||||
public class CommonProxy {
|
public class CommonProxy {
|
||||||
public void preInit(FMLPreInitializationEvent e) {
|
public void preInit(FMLPreInitializationEvent e) {
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageTileUpdate.class, MessageTileUpdate.class, 0, Side.CLIENT);
|
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageTileContainerUpdate.class, MessageTileContainerUpdate.class, 15, Side.CLIENT);
|
RefinedStorage.NETWORK.registerMessage(MessageTileContainerUpdate.class, MessageTileContainerUpdate.class, 15, Side.CLIENT);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageRedstoneModeUpdate.class, MessageRedstoneModeUpdate.class, 1, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageRedstoneModeUpdate.class, MessageRedstoneModeUpdate.class, 1, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageGridStoragePush.class, MessageGridStoragePush.class, 2, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageGridStoragePush.class, MessageGridStoragePush.class, 2, Side.SERVER);
|
||||||
@@ -56,6 +55,10 @@ public class CommonProxy {
|
|||||||
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridCraftingStart.class, MessageWirelessGridCraftingStart.class, 21, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageWirelessGridCraftingStart.class, MessageWirelessGridCraftingStart.class, 21, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageGridPatternCreate.class, MessageGridPatternCreate.class, 22, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageGridPatternCreate.class, MessageGridPatternCreate.class, 22, Side.SERVER);
|
||||||
RefinedStorage.NETWORK.registerMessage(MessageCraftingMonitorCancel.class, MessageCraftingMonitorCancel.class, 23, Side.SERVER);
|
RefinedStorage.NETWORK.registerMessage(MessageCraftingMonitorCancel.class, MessageCraftingMonitorCancel.class, 23, Side.SERVER);
|
||||||
|
RefinedStorage.NETWORK.registerMessage(MessageControllerEnergyUpdate.class, MessageControllerEnergyUpdate.class, 24, Side.CLIENT);
|
||||||
|
RefinedStorage.NETWORK.registerMessage(MessageSoldererWorkingUpdate.class, MessageSoldererWorkingUpdate.class, 25, Side.CLIENT);
|
||||||
|
RefinedStorage.NETWORK.registerMessage(MessageMachineConnectedUpdate.class, MessageMachineConnectedUpdate.class, 26, Side.CLIENT);
|
||||||
|
RefinedStorage.NETWORK.registerMessage(MessageDetectorPoweredUpdate.class, MessageDetectorPoweredUpdate.class, 27, Side.CLIENT);
|
||||||
|
|
||||||
NetworkRegistry.INSTANCE.registerGuiHandler(RefinedStorage.INSTANCE, new GuiHandler());
|
NetworkRegistry.INSTANCE.registerGuiHandler(RefinedStorage.INSTANCE, new GuiHandler());
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,7 @@ package refinedstorage.tile;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
|
|
||||||
public interface INetworkTile {
|
public interface ISynchronizedContainer {
|
||||||
void receiveData(ByteBuf buf);
|
|
||||||
|
|
||||||
void sendData(ByteBuf buf);
|
|
||||||
|
|
||||||
void receiveContainerData(ByteBuf buf);
|
void receiveContainerData(ByteBuf buf);
|
||||||
|
|
||||||
void sendContainerData(ByteBuf buf);
|
void sendContainerData(ByteBuf buf);
|
||||||
@@ -13,17 +13,13 @@ import net.minecraft.util.EnumFacing;
|
|||||||
import net.minecraft.util.ITickable;
|
import net.minecraft.util.ITickable;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
|
|
||||||
import refinedstorage.RefinedStorage;
|
import refinedstorage.RefinedStorage;
|
||||||
import refinedstorage.network.MessageTileContainerUpdate;
|
import refinedstorage.network.MessageTileContainerUpdate;
|
||||||
import refinedstorage.network.MessageTileUpdate;
|
|
||||||
|
|
||||||
public abstract class TileBase extends TileEntity implements ITickable {
|
public abstract class TileBase extends TileEntity implements ITickable {
|
||||||
public static final String NBT_DIRECTION = "Direction";
|
public static final String NBT_DIRECTION = "Direction";
|
||||||
public static final String NBT_ENERGY = "Energy";
|
public static final String NBT_ENERGY = "Energy";
|
||||||
|
|
||||||
public static final int UPDATE_RANGE = 64;
|
|
||||||
|
|
||||||
private EnumFacing direction = EnumFacing.NORTH;
|
private EnumFacing direction = EnumFacing.NORTH;
|
||||||
|
|
||||||
protected int ticks;
|
protected int ticks;
|
||||||
@@ -33,13 +29,9 @@ public abstract class TileBase extends TileEntity implements ITickable {
|
|||||||
ticks++;
|
ticks++;
|
||||||
|
|
||||||
if (!worldObj.isRemote) {
|
if (!worldObj.isRemote) {
|
||||||
if (this instanceof INetworkTile) {
|
if (this instanceof ISynchronizedContainer) {
|
||||||
TargetPoint target = new TargetPoint(worldObj.provider.getDimensionType().getId(), pos.getX(), pos.getY(), pos.getZ(), UPDATE_RANGE);
|
|
||||||
|
|
||||||
RefinedStorage.NETWORK.sendToAllAround(new MessageTileUpdate(this), target);
|
|
||||||
|
|
||||||
for (EntityPlayer player : worldObj.playerEntities) {
|
for (EntityPlayer player : worldObj.playerEntities) {
|
||||||
if (((INetworkTile) this).getContainer() == player.openContainer.getClass()) {
|
if (((ISynchronizedContainer) this).getContainer() == player.openContainer.getClass()) {
|
||||||
RefinedStorage.NETWORK.sendTo(new MessageTileContainerUpdate(this), (EntityPlayerMP) player);
|
RefinedStorage.NETWORK.sendTo(new MessageTileContainerUpdate(this), (EntityPlayerMP) player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import refinedstorage.container.ContainerController;
|
|||||||
import refinedstorage.item.ItemPattern;
|
import refinedstorage.item.ItemPattern;
|
||||||
import refinedstorage.item.ItemWirelessGrid;
|
import refinedstorage.item.ItemWirelessGrid;
|
||||||
import refinedstorage.network.GridPullFlags;
|
import refinedstorage.network.GridPullFlags;
|
||||||
|
import refinedstorage.network.MessageControllerEnergyUpdate;
|
||||||
import refinedstorage.network.MessageWirelessGridItems;
|
import refinedstorage.network.MessageWirelessGridItems;
|
||||||
import refinedstorage.storage.IStorage;
|
import refinedstorage.storage.IStorage;
|
||||||
import refinedstorage.storage.IStorageProvider;
|
import refinedstorage.storage.IStorageProvider;
|
||||||
@@ -37,7 +38,7 @@ import refinedstorage.tile.grid.WirelessGridConsumer;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class TileController extends TileBase implements IEnergyReceiver, INetworkTile, IRedstoneModeConfig {
|
public class TileController extends TileBase implements IEnergyReceiver, ISynchronizedContainer, IRedstoneModeConfig {
|
||||||
public class ClientSideMachine {
|
public class ClientSideMachine {
|
||||||
public ItemStack stack;
|
public ItemStack stack;
|
||||||
public int energyUsage;
|
public int energyUsage;
|
||||||
@@ -73,7 +74,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
|
|
||||||
private int wirelessGridRange;
|
private int wirelessGridRange;
|
||||||
|
|
||||||
private long lastEnergyRender;
|
private long lastEnergyUpdate;
|
||||||
|
|
||||||
public void addMachine(TileMachine machine) {
|
public void addMachine(TileMachine machine) {
|
||||||
machinesToAdd.add(machine);
|
machinesToAdd.add(machine);
|
||||||
@@ -203,6 +204,12 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
|
|
||||||
if (lastEnergy != energy.getEnergyStored()) {
|
if (lastEnergy != energy.getEnergyStored()) {
|
||||||
worldObj.updateComparatorOutputLevel(pos, RefinedStorageBlocks.CONTROLLER);
|
worldObj.updateComparatorOutputLevel(pos, RefinedStorageBlocks.CONTROLLER);
|
||||||
|
|
||||||
|
if (System.currentTimeMillis() - lastEnergyUpdate > 3000) {
|
||||||
|
RefinedStorageUtils.sendToAllAround(worldObj, pos, new MessageControllerEnergyUpdate(this));
|
||||||
|
|
||||||
|
lastEnergyUpdate = System.currentTimeMillis();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -397,6 +404,10 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
return newStack;
|
return newStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEnergyStored(int amount) {
|
||||||
|
energy.setEnergyStored(amount);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean onOpenWirelessGrid(EntityPlayer player, EnumHand hand) {
|
public boolean onOpenWirelessGrid(EntityPlayer player, EnumHand hand) {
|
||||||
boolean inRange = (int) Math.sqrt(Math.pow(getPos().getX() - player.posX, 2) + Math.pow(getPos().getY() - player.posY, 2) + Math.pow(getPos().getZ() - player.posZ, 2)) < getWirelessGridRange();
|
boolean inRange = (int) Math.sqrt(Math.pow(getPos().getX() - player.posX, 2) + Math.pow(getPos().getY() - player.posY, 2) + Math.pow(getPos().getZ() - player.posZ, 2)) < getWirelessGridRange();
|
||||||
|
|
||||||
@@ -549,24 +560,6 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
return clientSideMachines;
|
return clientSideMachines;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void receiveData(ByteBuf buf) {
|
|
||||||
int lastEnergy = energy.getEnergyStored();
|
|
||||||
|
|
||||||
energy.setEnergyStored(buf.readInt());
|
|
||||||
|
|
||||||
if (lastEnergy != energy.getEnergyStored() && System.currentTimeMillis() - lastEnergyRender > 3000) {
|
|
||||||
lastEnergyRender = System.currentTimeMillis();
|
|
||||||
|
|
||||||
worldObj.notifyBlockUpdate(pos, worldObj.getBlockState(pos), worldObj.getBlockState(pos), 2 | 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendData(ByteBuf buf) {
|
|
||||||
buf.writeInt(energy.getEnergyStored());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveContainerData(ByteBuf buf) {
|
public void receiveContainerData(ByteBuf buf) {
|
||||||
energyUsage = buf.readInt();
|
energyUsage = buf.readInt();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import refinedstorage.RefinedStorageBlocks;
|
|||||||
import refinedstorage.RefinedStorageUtils;
|
import refinedstorage.RefinedStorageUtils;
|
||||||
import refinedstorage.container.ContainerDetector;
|
import refinedstorage.container.ContainerDetector;
|
||||||
import refinedstorage.inventory.InventorySimple;
|
import refinedstorage.inventory.InventorySimple;
|
||||||
|
import refinedstorage.network.MessageDetectorPoweredUpdate;
|
||||||
import refinedstorage.storage.ItemGroup;
|
import refinedstorage.storage.ItemGroup;
|
||||||
import refinedstorage.tile.config.ICompareConfig;
|
import refinedstorage.tile.config.ICompareConfig;
|
||||||
import refinedstorage.tile.config.RedstoneMode;
|
import refinedstorage.tile.config.RedstoneMode;
|
||||||
@@ -87,6 +88,8 @@ public class TileDetector extends TileMachine implements ICompareConfig {
|
|||||||
|
|
||||||
if (powered != lastPowered) {
|
if (powered != lastPowered) {
|
||||||
worldObj.notifyNeighborsOfStateChange(pos, RefinedStorageBlocks.DETECTOR);
|
worldObj.notifyNeighborsOfStateChange(pos, RefinedStorageBlocks.DETECTOR);
|
||||||
|
|
||||||
|
RefinedStorageUtils.sendToAllAround(worldObj, pos, new MessageDetectorPoweredUpdate(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,6 +98,10 @@ public class TileDetector extends TileMachine implements ICompareConfig {
|
|||||||
return powered;
|
return powered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPowered(boolean powered) {
|
||||||
|
this.powered = powered;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCompare() {
|
public int getCompare() {
|
||||||
return compare;
|
return compare;
|
||||||
@@ -157,26 +164,6 @@ public class TileDetector extends TileMachine implements ICompareConfig {
|
|||||||
RefinedStorageUtils.saveInventory(inventory, 0, nbt);
|
RefinedStorageUtils.saveInventory(inventory, 0, nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void receiveData(ByteBuf buf) {
|
|
||||||
super.receiveData(buf);
|
|
||||||
|
|
||||||
boolean lastPowered = powered;
|
|
||||||
|
|
||||||
powered = buf.readBoolean();
|
|
||||||
|
|
||||||
if (powered != lastPowered) {
|
|
||||||
worldObj.notifyBlockUpdate(pos, worldObj.getBlockState(pos), worldObj.getBlockState(pos), 2 | 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendData(ByteBuf buf) {
|
|
||||||
super.sendData(buf);
|
|
||||||
|
|
||||||
buf.writeBoolean(powered);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendContainerData(ByteBuf buf) {
|
public void sendContainerData(ByteBuf buf) {
|
||||||
super.sendContainerData(buf);
|
super.sendContainerData(buf);
|
||||||
|
|||||||
@@ -4,14 +4,16 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import refinedstorage.RefinedStorageUtils;
|
||||||
import refinedstorage.block.BlockMachine;
|
import refinedstorage.block.BlockMachine;
|
||||||
|
import refinedstorage.network.MessageMachineConnectedUpdate;
|
||||||
import refinedstorage.tile.config.IRedstoneModeConfig;
|
import refinedstorage.tile.config.IRedstoneModeConfig;
|
||||||
import refinedstorage.tile.config.RedstoneMode;
|
import refinedstorage.tile.config.RedstoneMode;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public abstract class TileMachine extends TileBase implements INetworkTile, IRedstoneModeConfig {
|
public abstract class TileMachine extends TileBase implements ISynchronizedContainer, IRedstoneModeConfig {
|
||||||
protected boolean connected = false;
|
protected boolean connected = false;
|
||||||
protected RedstoneMode redstoneMode = RedstoneMode.IGNORE;
|
protected RedstoneMode redstoneMode = RedstoneMode.IGNORE;
|
||||||
protected TileController controller;
|
protected TileController controller;
|
||||||
@@ -56,6 +58,8 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
|
|
||||||
if (worldObj.getBlockState(pos).getBlock() == block) {
|
if (worldObj.getBlockState(pos).getBlock() == block) {
|
||||||
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, true));
|
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, true));
|
||||||
|
|
||||||
|
RefinedStorageUtils.sendToAllAround(worldObj, pos, new MessageMachineConnectedUpdate(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
worldObj.notifyNeighborsOfStateChange(pos, block);
|
worldObj.notifyNeighborsOfStateChange(pos, block);
|
||||||
@@ -83,6 +87,10 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
return connected;
|
return connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setConnected(boolean connected) {
|
||||||
|
this.connected = connected;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RedstoneMode getRedstoneMode() {
|
public RedstoneMode getRedstoneMode() {
|
||||||
return redstoneMode;
|
return redstoneMode;
|
||||||
@@ -100,22 +108,6 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void receiveData(ByteBuf buf) {
|
|
||||||
boolean lastConnected = connected;
|
|
||||||
|
|
||||||
connected = buf.readBoolean();
|
|
||||||
|
|
||||||
if (lastConnected != connected) {
|
|
||||||
worldObj.notifyBlockUpdate(pos, worldObj.getBlockState(pos), worldObj.getBlockState(pos), 2 | 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendData(ByteBuf buf) {
|
|
||||||
buf.writeBoolean(connected);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveContainerData(ByteBuf buf) {
|
public void receiveContainerData(ByteBuf buf) {
|
||||||
redstoneMode = RedstoneMode.getById(buf.readInt());
|
redstoneMode = RedstoneMode.getById(buf.readInt());
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import refinedstorage.RefinedStorageUtils;
|
|||||||
import refinedstorage.container.ContainerSolderer;
|
import refinedstorage.container.ContainerSolderer;
|
||||||
import refinedstorage.inventory.InventorySimple;
|
import refinedstorage.inventory.InventorySimple;
|
||||||
import refinedstorage.item.ItemUpgrade;
|
import refinedstorage.item.ItemUpgrade;
|
||||||
|
import refinedstorage.network.MessageSoldererWorkingUpdate;
|
||||||
import refinedstorage.tile.TileMachine;
|
import refinedstorage.tile.TileMachine;
|
||||||
|
|
||||||
public class TileSolderer extends TileMachine implements IInventory, ISidedInventory {
|
public class TileSolderer extends TileMachine implements IInventory, ISidedInventory {
|
||||||
@@ -43,6 +44,8 @@ public class TileSolderer extends TileMachine implements IInventory, ISidedInven
|
|||||||
public void updateMachine() {
|
public void updateMachine() {
|
||||||
ISoldererRecipe newRecipe = SoldererRegistry.getRecipe(inventory);
|
ISoldererRecipe newRecipe = SoldererRegistry.getRecipe(inventory);
|
||||||
|
|
||||||
|
boolean lastWorking = working;
|
||||||
|
|
||||||
if (newRecipe == null) {
|
if (newRecipe == null) {
|
||||||
reset();
|
reset();
|
||||||
} else if (newRecipe != recipe) {
|
} else if (newRecipe != recipe) {
|
||||||
@@ -74,6 +77,10 @@ public class TileSolderer extends TileMachine implements IInventory, ISidedInven
|
|||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (working != lastWorking) {
|
||||||
|
RefinedStorageUtils.sendToAllAround(worldObj, pos, new MessageSoldererWorkingUpdate(this));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -134,31 +141,15 @@ public class TileSolderer extends TileMachine implements IInventory, ISidedInven
|
|||||||
buf.writeInt(recipe != null ? recipe.getDuration() : 0);
|
buf.writeInt(recipe != null ? recipe.getDuration() : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void receiveData(ByteBuf buf) {
|
|
||||||
super.receiveData(buf);
|
|
||||||
|
|
||||||
boolean lastWorking = working;
|
|
||||||
|
|
||||||
working = buf.readBoolean();
|
|
||||||
|
|
||||||
if (working != lastWorking) {
|
|
||||||
worldObj.notifyBlockUpdate(pos, worldObj.getBlockState(pos), worldObj.getBlockState(pos), 2 | 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendData(ByteBuf buf) {
|
|
||||||
super.sendData(buf);
|
|
||||||
|
|
||||||
buf.writeBoolean(working);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<? extends Container> getContainer() {
|
public Class<? extends Container> getContainer() {
|
||||||
return ContainerSolderer.class;
|
return ContainerSolderer.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setWorking(boolean working) {
|
||||||
|
this.working = working;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isWorking() {
|
public boolean isWorking() {
|
||||||
return working;
|
return working;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user