Search in sources :

Example 66 with LogisticsTileGenericPipe

use of logisticspipes.pipes.basic.LogisticsTileGenericPipe in project LogisticsPipes by RS485.

the class LogisticsSolderingTileEntity method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    if (MainProxy.isClient(getWorldObj())) {
        return;
    }
    hasWork = hasWork();
    if (hasWork && heat < 100) {
        boolean usedEnergy = false;
        if (Configs.LOGISTICS_POWER_USAGE_DISABLED) {
            if (heat < 100) {
                heat += 5;
            }
            if (heat > 100) {
                heat = 100;
            }
            usedEnergy = true;
        } else {
            for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
                DoubleCoordinates pos = CoordinateUtils.add(new DoubleCoordinates(this), dir);
                TileEntity tile = pos.getTileEntity(getWorldObj());
                if (!(tile instanceof LogisticsTileGenericPipe)) {
                    continue;
                }
                LogisticsTileGenericPipe tPipe = (LogisticsTileGenericPipe) tile;
                if (!(tPipe.pipe instanceof CoreRoutedPipe)) {
                    continue;
                }
                CoreRoutedPipe pipe = (CoreRoutedPipe) tPipe.pipe;
                if (pipe.useEnergy(50)) {
                    heat += 5;
                    if (heat > 100) {
                        heat = 100;
                    }
                    updateHeat();
                    usedEnergy = true;
                    break;
                }
            }
        }
        if (!usedEnergy && getWorldObj().getTotalWorldTime() % 5 == 0) {
            heat--;
            if (heat < 0) {
                heat = 0;
            }
            updateHeat();
        }
    } else if (!hasWork && heat > 0) {
        heat--;
        updateHeat();
    }
    if (hasWork && heat >= 100) {
        for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
            DoubleCoordinates pos = CoordinateUtils.add(new DoubleCoordinates(this), dir);
            TileEntity tile = pos.getTileEntity(getWorldObj());
            if (!(tile instanceof LogisticsTileGenericPipe)) {
                continue;
            }
            LogisticsTileGenericPipe tPipe = (LogisticsTileGenericPipe) tile;
            if (!(tPipe.pipe instanceof CoreRoutedPipe)) {
                continue;
            }
            CoreRoutedPipe pipe = (CoreRoutedPipe) tPipe.pipe;
            if (pipe.useEnergy(30)) {
                progress += 3;
            } else if (pipe.useEnergy(20)) {
                progress += 2;
            } else if (pipe.useEnergy(10)) {
                progress += 1;
            }
            if (progress >= 100) {
                if (tryCraft()) {
                    progress = 0;
                } else {
                    progress -= 50;
                }
            }
            updateProgress();
        }
    } else if (!hasWork && progress != 0) {
        progress = 0;
        updateProgress();
    }
}
Also used : IGuiTileEntity(logisticspipes.interfaces.IGuiTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 67 with LogisticsTileGenericPipe

use of logisticspipes.pipes.basic.LogisticsTileGenericPipe in project LogisticsPipes by RS485.

the class LogisticsEventListener method onPlayerInteract.

@SubscribeEvent
public void onPlayerInteract(final PlayerInteractEvent event) {
    if (MainProxy.isServer(event.entityPlayer.worldObj)) {
        if (event.action == Action.LEFT_CLICK_BLOCK) {
            final TileEntity tile = event.entityPlayer.worldObj.getTileEntity(event.x, event.y, event.z);
            if (tile instanceof LogisticsTileGenericPipe) {
                if (((LogisticsTileGenericPipe) tile).pipe instanceof CoreRoutedPipe) {
                    if (!((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).canBeDestroyedByPlayer(event.entityPlayer)) {
                        event.setCanceled(true);
                        event.entityPlayer.addChatComponentMessage(new ChatComponentTranslation("lp.chat.permissiondenied"));
                        ((LogisticsTileGenericPipe) tile).scheduleNeighborChange();
                        event.entityPlayer.worldObj.markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord);
                        ((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).delayTo = System.currentTimeMillis() + 200;
                        ((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).repeatFor = 10;
                    } else {
                        ((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).setDestroyByPlayer();
                    }
                }
            }
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK) {
            WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(event.entityPlayer.worldObj, event.x, event.y, event.z);
            TileEntity tileEntity = worldCoordinates.getTileEntity();
            if (tileEntity instanceof TileEntityChest || SimpleServiceLocator.ironChestProxy.isIronChest(tileEntity)) {
                //@formatter:off
                List<WeakReference<ModuleQuickSort>> list = worldCoordinates.getAdjacentTileEntities().filter(adjacent -> adjacent.tileEntity instanceof LogisticsTileGenericPipe).filter(adjacent -> ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe instanceof PipeLogisticsChassi).filter(adjacent -> ((PipeLogisticsChassi) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).getPointedOrientation() == adjacent.direction.getOpposite()).map(adjacent -> (PipeLogisticsChassi) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).flatMap(pipeLogisticsChassi -> Arrays.stream(pipeLogisticsChassi.getModules().getModules())).filter(logisticsModule -> logisticsModule instanceof ModuleQuickSort).map(logisticsModule -> new WeakReference<>((ModuleQuickSort) logisticsModule)).collect(Collectors.toList());
                if (!list.isEmpty()) {
                    LogisticsEventListener.chestQuickSortConnection.put(event.entityPlayer, list);
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Action(net.minecraftforge.event.entity.player.PlayerInteractEvent.Action) Arrays(java.util.Arrays) ModuleQuickSort(logisticspipes.modules.ModuleQuickSort) MainProxy(logisticspipes.proxy.MainProxy) VersionChecker(logisticspipes.ticks.VersionChecker) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) Configs(logisticspipes.config.Configs) ChestGuiOpened(logisticspipes.network.packets.chassis.ChestGuiOpened) ChatComponentText(net.minecraft.util.ChatComponentText) LogisticsHUDRenderer(logisticspipes.renderer.LogisticsHUDRenderer) LogisticsGuiOverrenderer(logisticspipes.renderer.LogisticsGuiOverrenderer) Map(java.util.Map) FMLClientHandler(cpw.mods.fml.client.FMLClientHandler) PlayerLoggedInEvent(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent) PlayerLoggedOutEvent(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent) ClientConnectedToServerEvent(cpw.mods.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent) EntityItem(net.minecraft.entity.item.EntityItem) ChestGuiClosed(logisticspipes.network.packets.chassis.ChestGuiClosed) Side(cpw.mods.fml.relauncher.Side) SideOnly(cpw.mods.fml.relauncher.SideOnly) UnWatch(net.minecraftforge.event.world.ChunkWatchEvent.UnWatch) WorldEvent(net.minecraftforge.event.world.WorldEvent) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PacketHandler(logisticspipes.network.PacketHandler) Collectors(java.util.stream.Collectors) List(java.util.List) EntityJoinWorldEvent(net.minecraftforge.event.entity.EntityJoinWorldEvent) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) PipeLogisticsChassi(logisticspipes.pipes.PipeLogisticsChassi) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent) PlayerIdentifier(logisticspipes.utils.PlayerIdentifier) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) Queue(java.util.Queue) PlayerConfig(logisticspipes.config.PlayerConfig) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ChunkCoordIntPair(net.minecraft.world.ChunkCoordIntPair) Setter(lombok.Setter) Getter(lombok.Getter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) GuiReopenPacket(logisticspipes.network.packets.gui.GuiReopenPacket) HashMap(java.util.HashMap) PlayerConfigToClientPacket(logisticspipes.network.packets.PlayerConfigToClientPacket) Watch(net.minecraftforge.event.world.ChunkWatchEvent.Watch) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ItemStack(net.minecraft.item.ItemStack) IItemAdvancedExistance(logisticspipes.interfaces.IItemAdvancedExistance) TextureStitchEvent(net.minecraftforge.client.event.TextureStitchEvent) EntityClientPlayerMP(net.minecraft.client.entity.EntityClientPlayerMP) WeakReference(java.lang.ref.WeakReference) LinkedList(java.util.LinkedList) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) WeakHashMap(java.util.WeakHashMap) IOException(java.io.IOException) GuiChest(net.minecraft.client.gui.inventory.GuiChest) GuiOpenEvent(net.minecraftforge.client.event.GuiOpenEvent) QuickSortChestMarkerStorage(logisticspipes.utils.QuickSortChestMarkerStorage) TileEntity(net.minecraft.tileentity.TileEntity) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) AllArgsConstructor(lombok.AllArgsConstructor) TileEntityChest(net.minecraft.tileentity.TileEntityChest) PipeLogisticsChassi(logisticspipes.pipes.PipeLogisticsChassi) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) WeakReference(java.lang.ref.WeakReference) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ModuleQuickSort(logisticspipes.modules.ModuleQuickSort) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 68 with LogisticsTileGenericPipe

use of logisticspipes.pipes.basic.LogisticsTileGenericPipe in project LogisticsPipes by RS485.

the class ItemModule method onItemUse.

@Override
public boolean onItemUse(final ItemStack par1ItemStack, final EntityPlayer par2EntityPlayer, final World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) {
    if (MainProxy.isServer(par2EntityPlayer.worldObj)) {
        TileEntity tile = par3World.getTileEntity(par4, par5, par6);
        if (tile instanceof LogisticsTileGenericPipe) {
            if (par2EntityPlayer.getDisplayName().equals("ComputerCraft")) {
                //Allow turtle to place modules in pipes.
                CoreUnroutedPipe pipe = LogisticsBlockGenericPipe.getPipe(par3World, par4, par5, par6);
                if (LogisticsBlockGenericPipe.isValid(pipe)) {
                    pipe.blockActivated(par2EntityPlayer);
                }
            }
            return true;
        }
        openConfigGui(par1ItemStack, par2EntityPlayer, par3World);
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CoreUnroutedPipe(logisticspipes.pipes.basic.CoreUnroutedPipe) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe)

Example 69 with LogisticsTileGenericPipe

use of logisticspipes.pipes.basic.LogisticsTileGenericPipe 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 70 with LogisticsTileGenericPipe

use of logisticspipes.pipes.basic.LogisticsTileGenericPipe in project LogisticsPipes by RS485.

the class ChassiGuiProvider method getContainer.

@Override
public DummyContainer getContainer(EntityPlayer player) {
    LogisticsTileGenericPipe pipe = getPipe(player.getEntityWorld());
    if (pipe == null || !(pipe.pipe instanceof PipeLogisticsChassi)) {
        return null;
    }
    final PipeLogisticsChassi _chassiPipe = (PipeLogisticsChassi) pipe.pipe;
    IInventory _moduleInventory = _chassiPipe.getModuleInventory();
    DummyContainer dummy = new DummyContainer(player.inventory, _moduleInventory);
    if (_chassiPipe.getChassiSize() < 5) {
        dummy.addNormalSlotsForPlayerInventory(18, 97);
    } else {
        dummy.addNormalSlotsForPlayerInventory(18, 174);
    }
    if (_chassiPipe.getChassiSize() > 0) {
        dummy.addModuleSlot(0, _moduleInventory, 19, 9, _chassiPipe);
    }
    if (_chassiPipe.getChassiSize() > 1) {
        dummy.addModuleSlot(1, _moduleInventory, 19, 29, _chassiPipe);
    }
    if (_chassiPipe.getChassiSize() > 2) {
        dummy.addModuleSlot(2, _moduleInventory, 19, 49, _chassiPipe);
    }
    if (_chassiPipe.getChassiSize() > 3) {
        dummy.addModuleSlot(3, _moduleInventory, 19, 69, _chassiPipe);
    }
    if (_chassiPipe.getChassiSize() > 4) {
        dummy.addModuleSlot(4, _moduleInventory, 19, 89, _chassiPipe);
        dummy.addModuleSlot(5, _moduleInventory, 19, 109, _chassiPipe);
        dummy.addModuleSlot(6, _moduleInventory, 19, 129, _chassiPipe);
        dummy.addModuleSlot(7, _moduleInventory, 19, 149, _chassiPipe);
    }
    if (_chassiPipe.getUpgradeManager().hasUpgradeModuleUpgrade()) {
        for (int i = 0; i < _chassiPipe.getChassiSize(); i++) {
            final int fI = i;
            ModuleUpgradeManager upgradeManager = _chassiPipe.getModuleUpgradeManager(i);
            dummy.addUpgradeSlot(0, upgradeManager, 0, 145, 9 + i * 20, itemStack -> ChassiGuiProvider.checkStack(itemStack, _chassiPipe, fI));
            dummy.addUpgradeSlot(1, upgradeManager, 1, 165, 9 + i * 20, itemStack -> ChassiGuiProvider.checkStack(itemStack, _chassiPipe, fI));
        }
    }
    return dummy;
}
Also used : IInventory(net.minecraft.inventory.IInventory) DummyContainer(logisticspipes.utils.gui.DummyContainer) PipeLogisticsChassi(logisticspipes.pipes.PipeLogisticsChassi) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ModuleUpgradeManager(logisticspipes.pipes.upgrades.ModuleUpgradeManager)

Aggregations

LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)115 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)47 TileEntity (net.minecraft.tileentity.TileEntity)45 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)21 EnumFacing (net.minecraft.util.EnumFacing)15 ArrayList (java.util.ArrayList)14 List (java.util.List)12 EntityPlayer (net.minecraft.entity.player.EntityPlayer)10 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)10 BlockPos (net.minecraft.util.math.BlockPos)10 World (net.minecraft.world.World)9 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)9 HashMap (java.util.HashMap)8 LinkedList (java.util.LinkedList)8 PipeBlockRequestTable (logisticspipes.pipes.PipeBlockRequestTable)8 LogisticsPowerJunctionTileEntity (logisticspipes.blocks.powertile.LogisticsPowerJunctionTileEntity)7 MainProxy (logisticspipes.proxy.MainProxy)7 ExitRoute (logisticspipes.routing.ExitRoute)7 PipeLogisticsChassi (logisticspipes.pipes.PipeLogisticsChassi)6 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)6