Search in sources :

Example 1 with TileEntityFluidTank

use of micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank in project Galacticraft by micdoodle8.

the class GCNEIHighlightHandler method handleTextData.

@Override
public List<String> handleTextData(ItemStack stack, World world, EntityPlayer player, MovingObjectPosition mop, List<String> currenttip, ItemInfo.Layout layout) {
    if (stack != null) {
        if (stack.getItem() == Item.getItemFromBlock(GCBlocks.fluidTank)) {
            if (layout == ItemInfo.Layout.BODY) {
                TileEntity tile = world.getTileEntity(mop.getBlockPos());
                if (tile instanceof TileEntityFluidTank) {
                    TileEntityFluidTank tank = (TileEntityFluidTank) tile;
                    FluidTankInfo[] infos = tank.getTankInfo(EnumFacing.DOWN);
                    if (infos.length == 1) {
                        FluidTankInfo info = infos[0];
                        currenttip.add(info.fluid != null ? info.fluid.getLocalizedName() : "Empty");
                        currenttip.add((info.fluid != null ? info.fluid.amount : 0) + " / " + info.capacity);
                    }
                }
            }
        } else if (stack.getItem() == Item.getItemFromBlock(GCBlocks.oxygenPipe) || stack.getItem() == Item.getItemFromBlock(GCBlocks.oxygenPipePull)) {
            if (layout == ItemInfo.Layout.BODY) {
                TileEntity tile = world.getTileEntity(mop.getBlockPos());
                if (tile instanceof TileEntityFluidPipe) {
                    TileEntityFluidPipe pipe = (TileEntityFluidPipe) tile;
                    currenttip.add(((BlockFluidPipe) pipe.getBlockType()).getMode().toString());
                    if (pipe.hasNetwork()) {
                        FluidNetwork network = ((FluidNetwork) pipe.getNetwork());
                        currenttip.add("Network: " + (network.buffer != null ? network.buffer.amount : 0) + " / " + network.getCapacity());
                    } else {
                        currenttip.add("Pipe: " + (pipe.getBuffer() != null ? pipe.getBuffer().amount + " / " + pipe.buffer.getCapacity() : "None"));
                    }
                }
            }
        }
    }
    return currenttip;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) FluidNetwork(micdoodle8.mods.galacticraft.core.fluid.FluidNetwork) TileEntityFluidTank(micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank) TileEntityFluidPipe(micdoodle8.mods.galacticraft.core.tile.TileEntityFluidPipe)

Example 2 with TileEntityFluidTank

use of micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank in project Galacticraft by micdoodle8.

the class BlockFluidTank method breakBlock.

@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    TileEntity tile = worldIn.getTileEntity(pos);
    if (tile instanceof TileEntityFluidTank) {
        TileEntityFluidTank tank = (TileEntityFluidTank) tile;
        tank.onBreak();
    }
    super.breakBlock(worldIn, pos, state);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFluidTank(micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank)

Example 3 with TileEntityFluidTank

use of micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank in project Galacticraft by micdoodle8.

the class TileEntityFluidPipeRenderer method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntityFluidPipe pipe, double x, double y, double z, float partialTicks, int destroyStage) {
    updateModels();
    if (pipe.getBlockType() == GCBlocks.oxygenPipePull) {
        GL11.glPushMatrix();
        GL11.glTranslatef((float) x, (float) y, (float) z);
        RenderHelper.disableStandardItemLighting();
        this.bindTexture(TextureMap.locationBlocksTexture);
        if (Minecraft.isAmbientOcclusionEnabled()) {
            GlStateManager.shadeModel(GL11.GL_SMOOTH);
        } else {
            GlStateManager.shadeModel(GL11.GL_FLAT);
        }
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        TileEntity[] adj = OxygenUtil.getAdjacentFluidConnections(pipe);
        for (EnumFacing facing : EnumFacing.VALUES) {
            TileEntity sideTile = adj[facing.ordinal()];
            if (sideTile != null && !(sideTile instanceof IBufferTransmitter)) {
                GL11.glPushMatrix();
                if (sideTile instanceof TileEntityFluidTank)
                    switch(facing) {
                        case SOUTH:
                            GL11.glTranslatef(0F, 0F, 1 / 16F);
                            break;
                        case NORTH:
                            GL11.glTranslatef(0F, 0F, -1 / 16F);
                            break;
                        case EAST:
                            GL11.glTranslatef(1 / 16F, 0F, 0F);
                            break;
                        case WEST:
                            GL11.glTranslatef(-1 / 16F, 0F, 0F);
                            break;
                    }
                ClientUtil.drawBakedModel(pullConnectorModel[facing.ordinal()]);
                GL11.glPopMatrix();
            }
        }
        GL11.glPopMatrix();
    }
    float scale;
    if (pipe.hasNetwork()) {
        FluidNetwork network = (FluidNetwork) pipe.getNetwork();
        scale = network.fluidScale;
    } else {
        scale = pipe.buffer.getFluidAmount() / (float) pipe.buffer.getCapacity();
    }
    Fluid fluid;
    if (pipe.hasNetwork()) {
        FluidNetwork network = (FluidNetwork) pipe.getNetwork();
        fluid = network.refFluid;
    } else {
        fluid = pipe.getBuffer() == null ? null : pipe.getBuffer().getFluid();
    }
    if (fluid == null) {
        return;
    }
    if (scale > 0.01) {
        this.bindTexture(TextureMap.locationBlocksTexture);
        GL11.glPushMatrix();
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F);
        GL11.glScalef(1.0F, -1.0F, -1.0F);
        GL11.glTranslatef(0.5F, 0.5F, 0.5F);
        GlStateManager.disableLighting();
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        float opacity = 1.0F;
        boolean gas = fluid.isGaseous();
        if (gas) {
            opacity = scale;
        }
        GL11.glColor4f(1.0F, 1.0F, 1.0F, opacity);
        TileEntity[] connections = OxygenUtil.getAdjacentFluidConnections(pipe);
        for (EnumFacing side : EnumFacing.VALUES) {
            TileEntity sideTile = connections[side.ordinal()];
            if (sideTile != null) {
                Integer[] displayLists = getListAndRender(side, fluid);
                if (displayLists != null) {
                    if (!gas) {
                        Integer list = displayLists[Math.max(3, (int) (scale * (stages - 1)))];
                        GL11.glCallList(list);
                    } else {
                        Integer list = displayLists[stages - 1];
                        GL11.glCallList(list);
                    }
                }
            }
        }
        Integer[] displayLists = getListAndRender(null, fluid);
        if (displayLists != null) {
            if (!gas) {
                Integer list = displayLists[Math.max(3, (int) (scale * (stages - 1)))];
                GL11.glCallList(list);
            } else {
                Integer list = displayLists[stages - 1];
                GL11.glCallList(list);
            }
        }
        GlStateManager.enableLighting();
        GlStateManager.disableBlend();
        GL11.glPopMatrix();
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidNetwork(micdoodle8.mods.galacticraft.core.fluid.FluidNetwork) EnumFacing(net.minecraft.util.EnumFacing) Fluid(net.minecraftforge.fluids.Fluid) IBufferTransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter) TileEntityFluidTank(micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank)

Example 4 with TileEntityFluidTank

use of micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank in project Galacticraft by micdoodle8.

the class FluidUtil method interactWithTank.

public static boolean interactWithTank(ItemStack container, EntityPlayer playerIn, TileEntityFluidTank tank, EnumFacing side) {
    if (container == null || playerIn.worldObj.isRemote) {
        return true;
    }
    ItemStack result;
    if (container.getItem() instanceof ItemCanisterGeneric) {
        if ((result = FluidUtil.tryEmptyCanister(container, tank, side, playerIn.capabilities.isCreativeMode)) != null || (result = FluidUtil.tryFillCanister(container, tank, side, playerIn.capabilities.isCreativeMode)) != null) {
            // send inventory updates to client
            if (playerIn.inventoryContainer != null) {
                playerIn.inventoryContainer.detectAndSendChanges();
            }
        }
        return true;
    }
    // The following code deals with a bug in 1.8.9 (filling a bucket from a tank with less than 1000mB returns an empty bucket, but clears out the tank)
    // This code may not be required in 1.10.2+
    int slot = playerIn.inventory.currentItem;
    if ((result = FluidUtil.tryFillBucket(container, tank, side)) != null || (result = net.minecraftforge.fluids.FluidUtil.tryEmptyBucket(container, tank, side)) != null) {
        if (!playerIn.capabilities.isCreativeMode) {
            playerIn.inventory.decrStackSize(slot, 1);
            ItemHandlerHelper.giveItemToPlayer(playerIn, result, slot);
        }
        if (playerIn.inventoryContainer != null) {
            playerIn.inventoryContainer.detectAndSendChanges();
        }
        return true;
    } else {
        // Code for IFluidContainerItems - unchanged from Forge
        ItemStack copy = container.copy();
        boolean changedBucket = false;
        if (ItemStack.areItemsEqual(container, FluidContainerRegistry.EMPTY_BUCKET) && FluidRegistry.isUniversalBucketEnabled()) {
            container = new ItemStack(ForgeModContainer.getInstance().universalBucket, copy.stackSize);
            changedBucket = true;
        }
        if (net.minecraftforge.fluids.FluidUtil.tryFillFluidContainerItem(container, tank, side, playerIn) || net.minecraftforge.fluids.FluidUtil.tryEmptyFluidContainerItem(container, tank, side, playerIn)) {
            if (playerIn.capabilities.isCreativeMode) {
                playerIn.inventory.setInventorySlotContents(slot, copy);
            } else {
                if (changedBucket && container.stackSize != copy.stackSize) {
                    copy.stackSize = container.stackSize;
                    playerIn.inventory.setInventorySlotContents(slot, copy);
                } else {
                    if (copy.stackSize > 1) {
                        playerIn.inventory.setInventorySlotContents(slot, container);
                    } else {
                        playerIn.inventory.setInventorySlotContents(slot, null);
                        ItemHandlerHelper.giveItemToPlayer(playerIn, container, slot);
                    }
                }
            }
            if (playerIn.inventoryContainer != null) {
                playerIn.inventoryContainer.detectAndSendChanges();
            }
            return true;
        }
    }
    return false;
}
Also used : ItemCanisterGeneric(micdoodle8.mods.galacticraft.core.items.ItemCanisterGeneric) ItemStack(net.minecraft.item.ItemStack)

Example 5 with TileEntityFluidTank

use of micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank in project Galacticraft by micdoodle8.

the class TickHandlerServer method onWorldTick.

@SubscribeEvent
public void onWorldTick(WorldTickEvent event) {
    if (event.phase == Phase.START) {
        final WorldServer world = (WorldServer) event.world;
        CopyOnWriteArrayList<ScheduledBlockChange> changeList = TickHandlerServer.scheduledBlockChanges.get(GCCoreUtil.getDimensionID(world));
        if (changeList != null && !changeList.isEmpty()) {
            int blockCount = 0;
            int blockCountMax = Math.max(this.MAX_BLOCKS_PER_TICK, changeList.size() / 4);
            List<ScheduledBlockChange> newList = new ArrayList<ScheduledBlockChange>(Math.max(0, changeList.size() - blockCountMax));
            for (ScheduledBlockChange change : changeList) {
                if (++blockCount > blockCountMax) {
                    newList.add(change);
                } else {
                    if (change != null) {
                        BlockPos changePosition = change.getChangePosition();
                        Block block = world.getBlockState(changePosition).getBlock();
                        // Only replace blocks of type BlockAir or fire - this is to prevent accidents where other mods have moved blocks
                        if (changePosition != null && (block instanceof BlockAir || block == Blocks.fire)) {
                            world.setBlockState(changePosition, change.getChangeID().getStateFromMeta(change.getChangeMeta()), change.getChangeUpdateFlag());
                        }
                    }
                }
            }
            changeList.clear();
            TickHandlerServer.scheduledBlockChanges.remove(GCCoreUtil.getDimensionID(world));
            if (newList.size() > 0) {
                TickHandlerServer.scheduledBlockChanges.put(GCCoreUtil.getDimensionID(world), new CopyOnWriteArrayList<ScheduledBlockChange>(newList));
            }
        }
        CopyOnWriteArrayList<BlockVec3> torchList = TickHandlerServer.scheduledTorchUpdates.get(GCCoreUtil.getDimensionID(world));
        if (torchList != null && !torchList.isEmpty()) {
            for (BlockVec3 torch : torchList) {
                if (torch != null) {
                    BlockPos pos = new BlockPos(torch.x, torch.y, torch.z);
                    Block b = world.getBlockState(pos).getBlock();
                    if (b instanceof BlockUnlitTorch) {
                        world.scheduleUpdate(pos, b, 2 + world.rand.nextInt(30));
                    }
                }
            }
            torchList.clear();
            TickHandlerServer.scheduledTorchUpdates.remove(GCCoreUtil.getDimensionID(world));
        }
        if (world.provider instanceof IOrbitDimension) {
            try {
                int dim = GCCoreUtil.getDimensionID(WorldUtil.getProviderForNameServer(((IOrbitDimension) world.provider).getPlanetToOrbit()));
                int minY = ((IOrbitDimension) world.provider).getYCoordToTeleportToPlanet();
                final Entity[] entityList = world.loadedEntityList.toArray(new Entity[world.loadedEntityList.size()]);
                for (final Entity e : entityList) {
                    if (e.posY <= minY && e.worldObj == world) {
                        WorldUtil.transferEntityToDimension(e, dim, world, false, null);
                    }
                }
            } catch (Exception ex) {
            }
        }
        int dimensionID = GCCoreUtil.getDimensionID(world);
        if (worldsNeedingUpdate.contains(dimensionID)) {
            worldsNeedingUpdate.remove(dimensionID);
            for (Object obj : event.world.loadedTileEntityList) {
                TileEntity tile = (TileEntity) obj;
                if (tile instanceof TileEntityFluidTank) {
                    ((TileEntityFluidTank) tile).updateClient = true;
                }
            }
        }
    } else if (event.phase == Phase.END) {
        final WorldServer world = (WorldServer) event.world;
        for (GalacticraftPacketHandler handler : packetHandlers) {
            handler.tick(world);
        }
        int dimID = GCCoreUtil.getDimensionID(world);
        Set<BlockPos> edgesList = TickHandlerServer.edgeChecks.get(dimID);
        final HashSet<BlockPos> checkedThisTick = new HashSet<>();
        if (edgesList != null && !edgesList.isEmpty()) {
            List<BlockPos> edgesListCopy = new ArrayList<>();
            edgesListCopy.addAll(edgesList);
            for (BlockPos edgeBlock : edgesListCopy) {
                if (edgeBlock != null && !checkedThisTick.contains(edgeBlock)) {
                    if (TickHandlerServer.scheduledForChange(dimID, edgeBlock)) {
                        continue;
                    }
                    ThreadFindSeal done = new ThreadFindSeal(world, edgeBlock, 0, new ArrayList<TileEntityOxygenSealer>());
                    checkedThisTick.addAll(done.checkedAll());
                }
            }
            TickHandlerServer.edgeChecks.remove(GCCoreUtil.getDimensionID(world));
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) WorldServer(net.minecraft.world.WorldServer) GalacticraftPacketHandler(micdoodle8.mods.galacticraft.core.network.GalacticraftPacketHandler) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.BlockPos) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3) BlockAir(net.minecraft.block.BlockAir) ThreadFindSeal(micdoodle8.mods.galacticraft.core.fluid.ThreadFindSeal) ScheduledBlockChange(micdoodle8.mods.galacticraft.core.wrappers.ScheduledBlockChange) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) BlockUnlitTorch(micdoodle8.mods.galacticraft.core.blocks.BlockUnlitTorch) TileEntityFluidTank(micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank) Block(net.minecraft.block.Block) IOrbitDimension(micdoodle8.mods.galacticraft.api.world.IOrbitDimension) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

TileEntityFluidTank (micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank)6 TileEntity (net.minecraft.tileentity.TileEntity)5 FluidNetwork (micdoodle8.mods.galacticraft.core.fluid.FluidNetwork)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.BlockPos)2 EnumFacing (net.minecraft.util.EnumFacing)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 FluidTankInfo (net.minecraftforge.fluids.FluidTankInfo)2 LinkedList (java.util.LinkedList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 IBufferTransmitter (micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter)1 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)1 IOrbitDimension (micdoodle8.mods.galacticraft.api.world.IOrbitDimension)1 BlockUnlitTorch (micdoodle8.mods.galacticraft.core.blocks.BlockUnlitTorch)1 EntityHangingSchematic (micdoodle8.mods.galacticraft.core.entities.EntityHangingSchematic)1 ThreadFindSeal (micdoodle8.mods.galacticraft.core.fluid.ThreadFindSeal)1 ItemCanisterGeneric (micdoodle8.mods.galacticraft.core.items.ItemCanisterGeneric)1 GalacticraftPacketHandler (micdoodle8.mods.galacticraft.core.network.GalacticraftPacketHandler)1 IMultiBlock (micdoodle8.mods.galacticraft.core.tile.IMultiBlock)1 TileEntityCargoLoader (micdoodle8.mods.galacticraft.core.tile.TileEntityCargoLoader)1