Search in sources :

Example 1 with PacketDescriptionPacketRequest

use of me.desht.pneumaticcraft.common.network.PacketDescriptionPacketRequest in project pnc-repressurized by TeamPneumatic.

the class RenderBlockTarget method update.

public void update() {
    if (te != null && te.isInvalid())
        te = null;
    stat.update();
    List<IBlockTrackEntry> applicableTrackEntries = getApplicableEntries();
    if (CommonHUDHandler.getHandlerForPlayer().ticksExisted % 100 == 0) {
        boolean sentUpdate = false;
        for (IBlockTrackEntry entry : applicableTrackEntries) {
            if (entry.shouldBeUpdatedFromServer(te)) {
                if (!sentUpdate) {
                    NetworkHandler.sendToServer(new PacketDescriptionPacketRequest(pos));
                    sentUpdate = true;
                }
            }
        }
    }
    playerIsLooking = isPlayerLookingAtTarget();
    arrowRenderer.ticksExisted++;
    if (!getBlock().isAir(world.getBlockState(pos), world, pos)) {
        textList = new ArrayList<>();
        if (ticksExisted > 120) {
            stat.closeWindow();
            for (IBlockTrackEntry entry : applicableTrackEntries) {
                if (blockTracker.countBlockTrackersOfType(entry) <= entry.spamThreshold()) {
                    stat.openWindow();
                    break;
                }
            }
            if (playerIsLooking) {
                stat.openWindow();
                addBlockTrackInfo(textList);
            }
            stat.setText(textList);
        } else if (ticksExisted < -30) {
            stat.closeWindow();
            stat.setText(textList);
        }
    }
    if (hackTime > 0) {
        IHackableBlock hackableBlock = HackableHandler.getHackableForCoord(world, pos, player);
        if (hackableBlock != null) {
            // = Math.min(hackTime + 1, hackableBlock.getHackTime(world, blockX, blockY, blockZ, player));
            hackTime++;
        } else {
            hackTime = 0;
        }
    }
}
Also used : IHackableBlock(me.desht.pneumaticcraft.api.client.pneumaticHelmet.IHackableBlock) IBlockTrackEntry(me.desht.pneumaticcraft.api.client.pneumaticHelmet.IBlockTrackEntry) PacketDescriptionPacketRequest(me.desht.pneumaticcraft.common.network.PacketDescriptionPacketRequest)

Example 2 with PacketDescriptionPacketRequest

use of me.desht.pneumaticcraft.common.network.PacketDescriptionPacketRequest in project pnc-repressurized by TeamPneumatic.

the class BlockTrackUpgradeHandler method update.

@Override
public void update(EntityPlayer player, int rangeUpgrades) {
    ticksExisted++;
    SearchUpgradeHandler searchHandler = HUDHandler.instance().getSpecificRenderer(SearchUpgradeHandler.class);
    if (ticksExisted % updateInterval == 0) {
        int timeTaken = (int) accTime / updateInterval;
        updateInterval = updateInterval * timeTaken / MAX_TIME;
        if (updateInterval <= 1)
            updateInterval = 2;
        accTime = 0;
        ticksExisted = 0;
    }
    accTime -= System.currentTimeMillis();
    int blockTrackRange = BLOCK_TRACKING_RANGE + Math.min(rangeUpgrades, 5) * PneumaticValues.RANGE_UPGRADE_HELMET_RANGE_INCREASE;
    int baseX = (int) Math.floor(player.posX) - blockTrackRange;
    int baseY = (int) Math.floor(player.posY) - blockTrackRange + blockTrackRange * (ticksExisted % updateInterval) / (updateInterval / 2);
    int maxY = (int) Math.floor(player.posY) - blockTrackRange + blockTrackRange * (ticksExisted % updateInterval + 1) / (updateInterval / 2);
    baseY = MathHelper.clamp(baseY, 0, 255);
    maxY = MathHelper.clamp(maxY, 0, 255);
    int baseZ = (int) Math.floor(player.posZ) - blockTrackRange;
    IBlockAccess chunkCache = new ChunkCache(player.world, new BlockPos(baseX, baseY, baseZ), new BlockPos(baseX + 2 * blockTrackRange, maxY, baseZ + 2 * blockTrackRange), 0);
    for (int i = baseX; i <= baseX + 2 * blockTrackRange; i++) {
        for (int j = baseY; j < maxY; j++) {
            for (int k = baseZ; k <= baseZ + 2 * blockTrackRange; k++) {
                if (player.getDistance(i, j, k) > blockTrackRange)
                    continue;
                BlockPos pos = new BlockPos(i, j, k);
                TileEntity te = chunkCache.getTileEntity(pos);
                if (MinecraftForge.EVENT_BUS.post(new BlockTrackEvent(player.world, pos, te)))
                    continue;
                if (searchHandler != null && te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
                    searchHandler.checkInventoryForItems(te);
                }
                List<IBlockTrackEntry> entries = BlockTrackEntryList.instance.getEntriesForCoordinate(chunkCache, pos, te);
                if (entries.isEmpty())
                    continue;
                boolean inList = false;
                for (int l = 0; l < blockTargets.size(); l++) {
                    if (blockTargets.get(l).isSameTarget(player.world, pos)) {
                        inList = true;
                        // cancel lost targets
                        blockTargets.get(l).ticksExisted = Math.abs(blockTargets.get(l).ticksExisted);
                        blockTargets.get(l).setTileEntity(te);
                        break;
                    }
                }
                if (!inList) {
                    boolean sentUpdate = false;
                    for (IBlockTrackEntry entry : entries) {
                        if (entry.shouldBeUpdatedFromServer(te)) {
                            if (!sentUpdate) {
                                NetworkHandler.sendToServer(new PacketDescriptionPacketRequest(pos));
                                sentUpdate = true;
                            }
                        }
                    }
                    addBlockTarget(new RenderBlockTarget(player.world, player, pos, te, this));
                    for (IBlockTrackEntry entry : entries) {
                        if (countBlockTrackersOfType(entry) == entry.spamThreshold() + 1) {
                            HUDHandler.instance().addMessage(new ArmorMessage(I18n.format("blockTracker.message.stopSpam", I18n.format(entry.getEntryName())), new ArrayList<String>(), 60, 0x7700AA00));
                        }
                    }
                }
            }
        }
    }
    accTime += System.currentTimeMillis();
    for (int i = 0; i < blockTargets.size(); i++) {
        RenderBlockTarget blockTarget = blockTargets.get(i);
        boolean wasNegative = blockTarget.ticksExisted < 0;
        blockTarget.ticksExisted += CommonHUDHandler.getHandlerForPlayer(player).getSpeedFromUpgrades();
        if (blockTarget.ticksExisted >= 0 && wasNegative)
            blockTarget.ticksExisted = -1;
        blockTarget.update();
        if (blockTarget.getDistanceToEntity(player) > blockTrackRange + 5 || !blockTarget.isTargetStillValid()) {
            if (blockTarget.ticksExisted > 0) {
                blockTarget.ticksExisted = -60;
            } else if (blockTarget.ticksExisted == -1) {
                removeBlockTarget(i);
                i--;
            }
        }
    }
    List<String> textList = new ArrayList<String>();
    RenderBlockTarget focusedTarget = null;
    for (RenderBlockTarget blockTarget : blockTargets) {
        if (blockTarget.isInitialized() && blockTarget.isPlayerLooking()) {
            focusedTarget = blockTarget;
            break;
        }
    }
    if (focusedTarget != null) {
        blockTrackInfo.setTitle(focusedTarget.stat.getTitle());
        textList.addAll(focusedTarget.textList);
    } else {
        blockTrackInfo.setTitle("Current tracked blocks:");
        if (blockTypeCount == null || ticksExisted % 40 == 0) {
            blockTypeCount = new int[BlockTrackEntryList.instance.trackList.size()];
            for (RenderBlockTarget target : blockTargets) {
                for (IBlockTrackEntry validEntry : target.getApplicableEntries()) {
                    blockTypeCount[BlockTrackEntryList.instance.trackList.indexOf(validEntry)]++;
                }
            }
        }
        for (int i = 0; i < blockTypeCount.length; i++) {
            if (blockTypeCount[i] > 0) {
                textList.add(blockTypeCount[i] + " " + I18n.format(BlockTrackEntryList.instance.trackList.get(i).getEntryName()));
            }
        }
        if (textList.size() == 0)
            textList.add("Tracking no blocks currently.");
    }
    blockTrackInfo.setText(textList);
}
Also used : ChunkCache(net.minecraft.world.ChunkCache) ArrayList(java.util.ArrayList) IBlockAccess(net.minecraft.world.IBlockAccess) TileEntity(net.minecraft.tileentity.TileEntity) IBlockTrackEntry(me.desht.pneumaticcraft.api.client.pneumaticHelmet.IBlockTrackEntry) PacketDescriptionPacketRequest(me.desht.pneumaticcraft.common.network.PacketDescriptionPacketRequest) BlockPos(net.minecraft.util.math.BlockPos) BlockTrackEvent(me.desht.pneumaticcraft.api.client.pneumaticHelmet.BlockTrackEvent)

Example 3 with PacketDescriptionPacketRequest

use of me.desht.pneumaticcraft.common.network.PacketDescriptionPacketRequest in project pnc-repressurized by TeamPneumatic.

the class ModuleRegulatorTube method renderPreview.

@SideOnly(Side.CLIENT)
private void renderPreview() {
    if (!hasTicked) {
        TileEntityPneumaticBase tile = (TileEntityPneumaticBase) getTube();
        NetworkHandler.sendToServer(new PacketDescriptionPacketRequest(tile.getPos()));
        TileEntity neighbor = tile.getWorld().getTileEntity(tile.getPos().offset(dir));
        inLine = neighbor instanceof IPneumaticMachine;
        if (inLine) {
            IAirHandler neighborHandler = ((IPneumaticMachine) neighbor).getAirHandler(dir);
            inverted = neighborHandler != null && neighborHandler.getPressure() > tile.getAirHandler(null).getPressure();
            NetworkHandler.sendToServer(new PacketDescriptionPacketRequest(neighbor.getPos()));
        }
        hasTicked = true;
    }
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    if (inLine && !inverted) {
        GL11.glColor4d(0, 1, 0, 0.3);
    } else {
        GL11.glColor4d(1, 0, 0, 0.3);
    }
    GL11.glPushMatrix();
    GL11.glTranslated(0, 1, 0.2 + ClientTickHandler.TICKS % 20 * 0.015);
    GL11.glRotated(90, 1, 0, 0);
    RenderUtils.render3DArrow();
    // 0.5 because we're rendering a preview
    GL11.glColor4d(1, 1, 1, 0.5);
    GL11.glPopMatrix();
    GL11.glDisable(GL11.GL_BLEND);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAirHandler(me.desht.pneumaticcraft.api.tileentity.IAirHandler) PacketDescriptionPacketRequest(me.desht.pneumaticcraft.common.network.PacketDescriptionPacketRequest) IPneumaticMachine(me.desht.pneumaticcraft.api.tileentity.IPneumaticMachine) TileEntityPneumaticBase(me.desht.pneumaticcraft.common.tileentity.TileEntityPneumaticBase) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

PacketDescriptionPacketRequest (me.desht.pneumaticcraft.common.network.PacketDescriptionPacketRequest)3 IBlockTrackEntry (me.desht.pneumaticcraft.api.client.pneumaticHelmet.IBlockTrackEntry)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ArrayList (java.util.ArrayList)1 BlockTrackEvent (me.desht.pneumaticcraft.api.client.pneumaticHelmet.BlockTrackEvent)1 IHackableBlock (me.desht.pneumaticcraft.api.client.pneumaticHelmet.IHackableBlock)1 IAirHandler (me.desht.pneumaticcraft.api.tileentity.IAirHandler)1 IPneumaticMachine (me.desht.pneumaticcraft.api.tileentity.IPneumaticMachine)1 TileEntityPneumaticBase (me.desht.pneumaticcraft.common.tileentity.TileEntityPneumaticBase)1 BlockPos (net.minecraft.util.math.BlockPos)1 ChunkCache (net.minecraft.world.ChunkCache)1 IBlockAccess (net.minecraft.world.IBlockAccess)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1