Search in sources :

Example 1 with IPipeSign

use of logisticspipes.pipes.signs.IPipeSign in project LogisticsPipes by RS485.

the class CoreRoutedPipe method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
    super.writeToNBT(nbttagcompound);
    synchronized (routerIdLock) {
        if (routerId == null || routerId.isEmpty()) {
            if (router != null) {
                routerId = router.getId().toString();
            } else {
                routerId = UUID.randomUUID().toString();
            }
        }
    }
    nbttagcompound.setString("routerId", routerId);
    nbttagcompound.setLong("stat_lifetime_sent", stat_lifetime_sent);
    nbttagcompound.setLong("stat_lifetime_recieved", stat_lifetime_recieved);
    nbttagcompound.setLong("stat_lifetime_relayed", stat_lifetime_relayed);
    if (getLogisticsModule() != null) {
        getLogisticsModule().writeToNBT(nbttagcompound);
    }
    NBTTagCompound upgradeNBT = new NBTTagCompound();
    upgradeManager.writeToNBT(upgradeNBT);
    nbttagcompound.setTag("upgradeManager", upgradeNBT);
    NBTTagCompound powerNBT = new NBTTagCompound();
    powerHandler.writeToNBT(powerNBT);
    if (!powerNBT.hasNoTags()) {
        nbttagcompound.setTag("powerHandler", powerNBT);
    }
    NBTTagList sendqueue = new NBTTagList();
    for (Triplet<IRoutedItem, ForgeDirection, ItemSendMode> p : _sendQueue) {
        NBTTagCompound tagentry = new NBTTagCompound();
        NBTTagCompound tagentityitem = new NBTTagCompound();
        p.getValue1().writeToNBT(tagentityitem);
        tagentry.setTag("entityitem", tagentityitem);
        tagentry.setByte("from", (byte) (p.getValue2().ordinal()));
        tagentry.setByte("mode", (byte) (p.getValue3().ordinal()));
        sendqueue.appendTag(tagentry);
    }
    nbttagcompound.setTag("sendqueue", sendqueue);
    for (int i = 0; i < 6; i++) {
        if (signItem[i] != null) {
            nbttagcompound.setBoolean("PipeSign_" + i, true);
            int signType = -1;
            List<Class<? extends IPipeSign>> typeClasses = ItemPipeSignCreator.signTypes;
            for (int j = 0; j < typeClasses.size(); j++) {
                if (typeClasses.get(j) == signItem[i].getClass()) {
                    signType = j;
                    break;
                }
            }
            nbttagcompound.setInteger("PipeSign_" + i + "_type", signType);
            NBTTagCompound tag = new NBTTagCompound();
            signItem[i].writeToNBT(tag);
            nbttagcompound.setTag("PipeSign_" + i + "_tags", tag);
        } else {
            nbttagcompound.setBoolean("PipeSign_" + i, false);
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IPipeSign(logisticspipes.pipes.signs.IPipeSign) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 2 with IPipeSign

use of logisticspipes.pipes.signs.IPipeSign in project LogisticsPipes by RS485.

the class ItemPipeSignCreator method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int sideinput, float hitX, float hitY, float hitZ) {
    if (MainProxy.isClient(world)) {
        return false;
    }
    if (itemStack.getItemDamage() > this.getMaxDamage() || itemStack.stackSize == 0) {
        return false;
    }
    TileEntity tile = world.getTileEntity(x, y, z);
    if (!(tile instanceof LogisticsTileGenericPipe)) {
        return false;
    }
    if (!itemStack.hasTagCompound()) {
        itemStack.setTagCompound(new NBTTagCompound());
    }
    itemStack.getTagCompound().setInteger("PipeClicked", 0);
    int mode = itemStack.getTagCompound().getInteger("CreatorMode");
    ForgeDirection dir = ForgeDirection.getOrientation(sideinput);
    if (dir == ForgeDirection.UNKNOWN) {
        return false;
    }
    if (!(((LogisticsTileGenericPipe) tile).pipe instanceof CoreRoutedPipe)) {
        return false;
    }
    CoreRoutedPipe pipe = (CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe;
    if (pipe == null) {
        return false;
    }
    if (!player.isSneaking()) {
        if (pipe.hasPipeSign(dir)) {
            pipe.activatePipeSign(dir, player);
            return true;
        } else if (mode >= 0 && mode < ItemPipeSignCreator.signTypes.size()) {
            Class<? extends IPipeSign> signClass = ItemPipeSignCreator.signTypes.get(mode);
            try {
                IPipeSign sign = signClass.newInstance();
                if (sign.isAllowedFor(pipe)) {
                    itemStack.damageItem(1, player);
                    sign.addSignTo(pipe, dir, player);
                    return true;
                } else {
                    return false;
                }
            } catch (InstantiationException | IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        } else {
            return false;
        }
    } else {
        if (pipe.hasPipeSign(dir)) {
            pipe.removePipeSign(dir, player);
            itemStack.damageItem(-1, player);
        }
        return true;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPipeSign(logisticspipes.pipes.signs.IPipeSign) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe)

Example 3 with IPipeSign

use of logisticspipes.pipes.signs.IPipeSign in project LogisticsPipes by RS485.

the class ItemAmountSignUpdatePacket method processPacket.

@Override
public void processPacket(EntityPlayer player) {
    LogisticsTileGenericPipe pipe = this.getPipe(player.getEntityWorld());
    if (pipe == null || !pipe.isInitialized()) {
        return;
    }
    IPipeSign sign = ((CoreRoutedPipe) pipe.pipe).getPipeSign(ForgeDirection.getOrientation(getInteger()));
    if (sign == null) {
        return;
    }
    ((ItemAmountPipeSign) sign).amount = getInteger2();
    ((ItemAmountPipeSign) sign).itemTypeInv.setInventorySlotContents(0, stack);
}
Also used : IPipeSign(logisticspipes.pipes.signs.IPipeSign) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe)

Example 4 with IPipeSign

use of logisticspipes.pipes.signs.IPipeSign in project LogisticsPipes by RS485.

the class CoreRoutedPipe method sendSignData.

public void sendSignData(EntityPlayer player) {
    List<Integer> types = new ArrayList<>();
    for (int i = 0; i < 6; i++) {
        if (signItem[i] == null) {
            types.add(-1);
        } else {
            List<Class<? extends IPipeSign>> typeClasses = ItemPipeSignCreator.signTypes;
            for (int j = 0; j < typeClasses.size(); j++) {
                if (typeClasses.get(j) == signItem[i].getClass()) {
                    types.add(j);
                    break;
                }
            }
        }
    }
    ModernPacket packet = PacketHandler.getPacket(PipeSignTypes.class).setTypes(types).setTilePos(container);
    MainProxy.sendPacketToAllWatchingChunk(getX(), getZ(), MainProxy.getDimensionForWorld(getWorld()), packet);
    MainProxy.sendPacketToPlayer(packet, player);
    for (int i = 0; i < 6; i++) {
        if (signItem[i] != null) {
            packet = signItem[i].getPacket();
            if (packet != null) {
                MainProxy.sendPacketToAllWatchingChunk(getX(), getZ(), MainProxy.getDimensionForWorld(getWorld()), packet);
                MainProxy.sendPacketToPlayer(packet, player);
            }
        }
    }
    refreshRender(false);
}
Also used : IPipeSign(logisticspipes.pipes.signs.IPipeSign) ModernPacket(logisticspipes.network.abstractpackets.ModernPacket) ArrayList(java.util.ArrayList)

Aggregations

IPipeSign (logisticspipes.pipes.signs.IPipeSign)4 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)2 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)2 ArrayList (java.util.ArrayList)1 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)1 ModernPacket (logisticspipes.network.abstractpackets.ModernPacket)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 TileEntity (net.minecraft.tileentity.TileEntity)1