Search in sources :

Example 1 with BlockPosFace

use of gregtech.api.util.BlockPosFace in project GregTech by GregTechCEu.

the class MetaTileEntityCentralMonitor method writeCovers.

private void writeCovers(PacketBuffer buf) {
    if (netCovers == null) {
        buf.writeInt(0);
    } else {
        buf.writeInt(netCovers.size());
        for (BlockPosFace cover : netCovers) {
            buf.writeBlockPos(cover.pos);
            buf.writeByte(cover.facing.getIndex());
        }
    }
    if (remoteCovers == null) {
        buf.writeInt(0);
    } else {
        buf.writeInt(remoteCovers.size());
        for (BlockPosFace cover : remoteCovers) {
            buf.writeBlockPos(cover.pos);
            buf.writeByte(cover.facing.getIndex());
        }
    }
}
Also used : BlockPosFace(gregtech.api.util.BlockPosFace)

Example 2 with BlockPosFace

use of gregtech.api.util.BlockPosFace in project GregTech by GregTechCEu.

the class MetaTileEntityCentralMonitor method readCovers.

private void readCovers(PacketBuffer buf) {
    netCovers = new HashSet<>();
    remoteCovers = new HashSet<>();
    int size = buf.readInt();
    for (int i = 0; i < size; i++) {
        netCovers.add(new BlockPosFace(buf.readBlockPos(), EnumFacing.byIndex(buf.readByte())));
    }
    size = buf.readInt();
    for (int i = 0; i < size; i++) {
        remoteCovers.add(new BlockPosFace(buf.readBlockPos(), EnumFacing.byIndex(buf.readByte())));
    }
}
Also used : BlockPosFace(gregtech.api.util.BlockPosFace)

Example 3 with BlockPosFace

use of gregtech.api.util.BlockPosFace in project GregTech by GregTechCEu.

the class MetaTileEntityMonitorScreen method readSync.

private void readSync(PacketBuffer buf) {
    if (buf.readBoolean()) {
        BlockPos pos = buf.readBlockPos();
        EnumFacing side = EnumFacing.byIndex(buf.readByte());
        BlockPosFace pair = new BlockPosFace(pos, side);
        if (!pair.equals(this.coverPos)) {
            this.coverTMP = null;
            this.coverPos = pair;
        }
    } else {
        this.coverPos = null;
        this.coverTMP = null;
    }
    this.mode = CoverDigitalInterface.MODE.VALUES[buf.readByte()];
    this.slot = buf.readVarInt();
    this.scale = buf.readFloat();
    this.frameColor = buf.readVarInt();
    updateProxyPlugin();
}
Also used : BlockPosFace(gregtech.api.util.BlockPosFace) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with BlockPosFace

use of gregtech.api.util.BlockPosFace in project GregTech by GregTechCEu.

the class MetaTileEntityCentralMonitor method checkCovers.

private boolean checkCovers() {
    boolean dirty = false;
    updateNodes();
    Set<BlockPosFace> checkCovers = new HashSet<>();
    World world = this.getWorld();
    for (BlockPos pos : activeNodes) {
        TileEntity tileEntityCable = world.getTileEntity(pos);
        if (!(tileEntityCable instanceof TileEntityPipeBase)) {
            continue;
        }
        for (EnumFacing facing : EnumFacing.VALUES) {
            if (((TileEntityPipeBase<?, ?>) tileEntityCable).isConnected(facing)) {
                TileEntity tileEntity = world.getTileEntity(pos.offset(facing));
                if (tileEntity instanceof MetaTileEntityHolder) {
                    MetaTileEntity metaTileEntity = ((MetaTileEntityHolder) tileEntity).getMetaTileEntity();
                    if (metaTileEntity != null) {
                        CoverBehavior cover = metaTileEntity.getCoverAtSide(facing.getOpposite());
                        if (cover instanceof CoverDigitalInterface && ((CoverDigitalInterface) cover).isProxy()) {
                            checkCovers.add(new BlockPosFace(metaTileEntity.getPos(), cover.attachedSide));
                        }
                    }
                }
            }
        }
    }
    Iterator<BlockPosFace> iterator = remoteCovers.iterator();
    while (iterator.hasNext()) {
        BlockPosFace blockPosFace = iterator.next();
        TileEntity tileEntity = world.getTileEntity(blockPosFace.pos);
        if (tileEntity instanceof MetaTileEntityHolder) {
            MetaTileEntity metaTileEntity = ((MetaTileEntityHolder) tileEntity).getMetaTileEntity();
            if (metaTileEntity != null) {
                CoverBehavior cover = metaTileEntity.getCoverAtSide(blockPosFace.facing);
                if (cover instanceof CoverDigitalInterface && ((CoverDigitalInterface) cover).isProxy()) {
                    continue;
                }
            }
        }
        iterator.remove();
        dirty = true;
    }
    if (checkCovers.size() != netCovers.size() || !netCovers.containsAll(checkCovers)) {
        netCovers = checkCovers;
        dirty = true;
    }
    return dirty;
}
Also used : MetaTileEntityHolder(gregtech.api.metatileentity.MetaTileEntityHolder) BlockPosFace(gregtech.api.util.BlockPosFace) EnumFacing(net.minecraft.util.EnumFacing) CoverDigitalInterface(gregtech.common.covers.CoverDigitalInterface) World(net.minecraft.world.World) TileEntityPipeBase(gregtech.api.pipenet.tile.TileEntityPipeBase) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) IFastRenderMetaTileEntity(gregtech.api.metatileentity.IFastRenderMetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) IFastRenderMetaTileEntity(gregtech.api.metatileentity.IFastRenderMetaTileEntity) BlockPos(net.minecraft.util.math.BlockPos) CoverBehavior(gregtech.api.cover.CoverBehavior)

Example 5 with BlockPosFace

use of gregtech.api.util.BlockPosFace in project GregTech by GregTechCEu.

the class MetaTileEntityMonitorScreen method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound data) {
    super.readFromNBT(data);
    this.frameColor = data.hasKey("color") ? data.getInteger("color") : 0XFF00Ff00;
    this.scale = data.hasKey("scale") ? data.getFloat("scale") : 1;
    this.slot = data.hasKey("slot") ? data.getInteger("slot") : 0;
    this.mode = CoverDigitalInterface.MODE.VALUES[data.hasKey("mode") ? data.getByte("mode") : 0];
    this.inventory.deserializeNBT(data.getCompoundTag("Inventory"));
    if (data.hasKey("coverPos") && data.hasKey("coverSide")) {
        BlockPos pos = NBTUtil.getPosFromTag(data.getCompoundTag("coverPos"));
        EnumFacing side = EnumFacing.byIndex(data.getByte("coverSide"));
        this.coverPos = new BlockPosFace(pos, side);
    } else {
        this.coverPos = null;
    }
    MonitorPluginBaseBehavior behavior = MonitorPluginBaseBehavior.getBehavior(this.inventory.getStackInSlot(0));
    if (behavior == null) {
        unloadPlugin();
    } else {
        loadPlugin(behavior);
    }
}
Also used : BlockPosFace(gregtech.api.util.BlockPosFace) BlockPos(net.minecraft.util.math.BlockPos) MonitorPluginBaseBehavior(gregtech.api.items.behavior.MonitorPluginBaseBehavior)

Aggregations

BlockPosFace (gregtech.api.util.BlockPosFace)7 BlockPos (net.minecraft.util.math.BlockPos)5 World (net.minecraft.world.World)3 CoverBehavior (gregtech.api.cover.CoverBehavior)2 MonitorPluginBaseBehavior (gregtech.api.items.behavior.MonitorPluginBaseBehavior)2 MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)2 MetaTileEntityHolder (gregtech.api.metatileentity.MetaTileEntityHolder)2 TileEntityPipeBase (gregtech.api.pipenet.tile.TileEntityPipeBase)2 CoverDigitalInterface (gregtech.common.covers.CoverDigitalInterface)2 IBlockState (net.minecraft.block.state.IBlockState)2 TileEntity (net.minecraft.tileentity.TileEntity)2 RayTraceResult (net.minecraft.util.math.RayTraceResult)2 Vec3d (net.minecraft.util.math.Vec3d)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 CuboidRayTraceResult (codechicken.lib.raytracer.CuboidRayTraceResult)1 GregtechCapabilities (gregtech.api.capability.GregtechCapabilities)1 GregtechDataCodes (gregtech.api.capability.GregtechDataCodes)1 ICoverable (gregtech.api.cover.ICoverable)1 GuiTextures (gregtech.api.gui.GuiTextures)1 ModularUI (gregtech.api.gui.ModularUI)1