Search in sources :

Example 1 with Packet

use of buildcraft.core.lib.network.base.Packet in project BuildCraft by BuildCraft.

the class TileGenericPipe method update.

@Override
public void update() {
    try {
        if (!worldObj.isRemote) {
            if (deletePipe) {
                worldObj.setBlockToAir(getPos());
            }
            if (pipe == null || coreState.pipeId == null) {
                return;
            }
            if (!initialized) {
                initialize(pipe);
            }
        }
        if (attachPluggables) {
            attachPluggables = false;
            // Attach callback
            for (int i = 0; i < EnumFacing.VALUES.length; i++) {
                if (sideProperties.pluggables[i] != null) {
                    pipe.eventBus.registerHandler(sideProperties.pluggables[i]);
                    sideProperties.pluggables[i].onAttachedPipe(this, EnumFacing.getFront(i));
                }
            }
            notifyBlockChanged();
        }
        if (!BlockGenericPipe.isValid(pipe)) {
            return;
        }
        pipe.updateEntity();
        for (EnumFacing direction : EnumFacing.VALUES) {
            PipePluggable p = getPipePluggable(direction);
            if (p != null) {
                p.update(this, direction);
            }
        }
        if (worldObj.isRemote) {
            if (resyncGateExpansions) {
                syncGateExpansions();
            }
            return;
        }
        if (blockNeighborChange) {
            for (int i = 0; i < 6; i++) {
                if ((blockNeighborChangedSides & (1 << i)) != 0) {
                    blockNeighborChangedSides ^= 1 << i;
                    computeConnection(EnumFacing.getFront(i));
                }
            }
            pipe.onNeighborBlockChange(0);
            blockNeighborChange = false;
            refreshRenderState = true;
        }
        if (refreshRenderState) {
            refreshRenderState();
            refreshRenderState = false;
        }
        if (sendClientUpdate) {
            sendClientUpdate = false;
            if (!worldObj.isRemote) {
                Packet updatePacket = getBCDescriptionPacket();
                BuildCraftCore.instance.sendToPlayersNear(updatePacket, this);
            }
        }
    } catch (Throwable t) {
        BCLog.logger.warn("CRASH! OH NO!", t);
        Throwables.propagate(t);
    }
}
Also used : Packet(buildcraft.core.lib.network.base.Packet) EnumFacing(net.minecraft.util.EnumFacing) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable)

Example 2 with Packet

use of buildcraft.core.lib.network.base.Packet in project BuildCraft by BuildCraft.

the class TileGenericPipe method getUpdatePacket.

@Override
public SPacketUpdateTileEntity getUpdatePacket() {
    NBTTagCompound nbt = new NBTTagCompound();
    nbt.setString("net-type", "desc-packet");
    Packet p = getBCDescriptionPacket();
    ByteBuf buf = Unpooled.buffer();
    p.writeData(buf);
    byte[] bytes = new byte[buf.readableBytes()];
    buf.readBytes(bytes);
    nbt.setByteArray("net-data", bytes);
    SPacketUpdateTileEntity tileUpdate = new SPacketUpdateTileEntity(getPos(), 0, nbt);
    return tileUpdate;
}
Also used : Packet(buildcraft.core.lib.network.base.Packet) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ByteBuf(io.netty.buffer.ByteBuf) SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity)

Example 3 with Packet

use of buildcraft.core.lib.network.base.Packet in project BuildCraft by BuildCraft.

the class TileZonePlan method importMap.

private void importMap(ItemStack stack) {
    if (stack != null && stack.getItem() instanceof IMapLocation) {
        final IZone zone = ((IMapLocation) stack.getItem()).getZone(stack);
        if (zone != null && zone instanceof ZonePlan) {
            selectedAreas[currentSelectedArea] = (ZonePlan) zone;
            for (EntityPlayerMP e : MinecraftServer.getServer().getConfigurationManager().playerEntityList) {
                if (e.openContainer != null && e.openContainer instanceof ContainerZonePlan && ((ContainerZonePlan) e.openContainer).getTile() == this) {
                    Packet p = new PacketCommand(e.openContainer, "areaLoaded", new CommandWriter() {

                        @Override
                        public void write(ByteBuf data) {
                            ((ZonePlan) zone).writeData(data);
                        }
                    });
                    BuildCraftCore.instance.sendToPlayer(e, p);
                }
            }
        }
    }
}
Also used : Packet(buildcraft.core.lib.network.base.Packet) ContainerZonePlan(buildcraft.robotics.gui.ContainerZonePlan) ZonePlan(buildcraft.robotics.zone.ZonePlan) IMapLocation(buildcraft.api.items.IMapLocation) PacketCommand(buildcraft.core.lib.network.command.PacketCommand) IZone(buildcraft.api.core.IZone) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ContainerZonePlan(buildcraft.robotics.gui.ContainerZonePlan) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf)

Example 4 with Packet

use of buildcraft.core.lib.network.base.Packet in project BuildCraft by BuildCraft.

the class TileBuildCraft method getUpdatePacket.

@Override
public SPacketUpdateTileEntity getUpdatePacket() {
    NBTTagCompound nbt = new NBTTagCompound();
    nbt.setString("net-type", "desc-packet");
    Packet p = getPacketUpdate();
    ByteBuf buf = Unpooled.buffer();
    p.writeData(buf);
    byte[] bytes = new byte[buf.readableBytes()];
    buf.readBytes(bytes);
    nbt.setByteArray("net-data", bytes);
    SPacketUpdateTileEntity tileUpdate = new SPacketUpdateTileEntity(getPos(), 0, nbt);
    return tileUpdate;
}
Also used : Packet(buildcraft.core.lib.network.base.Packet) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ByteBuf(io.netty.buffer.ByteBuf) SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity)

Example 5 with Packet

use of buildcraft.core.lib.network.base.Packet in project BuildCraft by BuildCraft.

the class PacketPipeTransportItemStackRequest method sendDataToPlayer.

public void sendDataToPlayer(EntityPlayer player) {
    if (item != null) {
        Packet packet = new PacketPipeTransportItemStack(player.worldObj, travelerID, item.getItemStack());
        BuildCraftTransport.instance.sendToPlayer(player, packet);
    }
}
Also used : Packet(buildcraft.core.lib.network.base.Packet)

Aggregations

Packet (buildcraft.core.lib.network.base.Packet)5 ByteBuf (io.netty.buffer.ByteBuf)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 SPacketUpdateTileEntity (net.minecraft.network.play.server.SPacketUpdateTileEntity)2 IZone (buildcraft.api.core.IZone)1 IMapLocation (buildcraft.api.items.IMapLocation)1 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)1 CommandWriter (buildcraft.core.lib.network.command.CommandWriter)1 PacketCommand (buildcraft.core.lib.network.command.PacketCommand)1 ContainerZonePlan (buildcraft.robotics.gui.ContainerZonePlan)1 ZonePlan (buildcraft.robotics.zone.ZonePlan)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 EnumFacing (net.minecraft.util.EnumFacing)1