Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey there..

 

So I have this overlay that displays my energy, however, I have created an interface, when combined with a TE, will display the 'Void Flux' of that chunk, however for some reason it seems that the interface returns null, even though I've done the same thing for the energy, and it seems to work..

 

Here is the overlay event class:

    @SubscribeEvent
    public void onGameOverlay(RenderGameOverlayEvent.Post event){
        if(event.getType() == RenderGameOverlayEvent.ElementType.ALL && Minecraft.getMinecraft().currentScreen == null){
            Minecraft minecraft = Minecraft.getMinecraft();
            EntityPlayer player = minecraft.player;
            RayTraceResult posHit = minecraft.objectMouseOver;
            FontRenderer font = minecraft.fontRendererObj;
            ItemStack stack = player.getHeldItemMainhand();

            if(StackUtil.isValid(stack)){
                if(stack.getItem() instanceof IHudDisplay){
                    ((IHudDisplay)stack.getItem()).displayHud(minecraft, player, stack, posHit, event.getResolution());
                }
            }

            if(posHit != null && posHit.getBlockPos() != null){
                Block blockHit = minecraft.world.getBlockState(posHit.getBlockPos()).getBlock();
                TileEntity tileHit = minecraft.world.getTileEntity(posHit.getBlockPos());

                if(blockHit instanceof IHudDisplay){
                    ((IHudDisplay)blockHit).displayHud(minecraft, player, stack, posHit, event.getResolution());
                }

                if(tileHit instanceof TileEntityBase){
                    TileEntityBase base = (TileEntityBase)tileHit;
                    if(base.isRedstoneToggle()){
                        String strg = "Activation Mode: "+ TextFormatting.DARK_RED+(base.isPulseMode ? "Pulse" : "Deactivation")+TextFormatting.RESET;
                        font.drawStringWithShadow(strg, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+5, StringUtil.DECIMAL_COLOR_WHITE);

                        String expl;
                        if(StackUtil.isValid(stack) && stack.getItem() == InitItems.itemJAWrench){
                            expl = TextFormatting.GREEN+"Right-Click to adjust!";
                        }
                        else{
                            expl = TextFormatting.GRAY.toString()+TextFormatting.ITALIC+"Hold a " + TextFormatting.BLUE + "Wrench " + TextFormatting.GRAY + " to Adjust";
                        }
                        font.drawStringWithShadow(expl, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+15, StringUtil.DECIMAL_COLOR_WHITE);
                    }
                }

                if(tileHit instanceof IEnergyDisplay){
                    IEnergyDisplay display = (IEnergyDisplay)tileHit;
                    if(!display.needsHoldShift() || player.isSneaking()){
                        if(energyDisplay == null){
                            energyDisplay = new EnergyDisplay(0, 0, null);
                        }
                        energyDisplay.setData(2, event.getResolution().getScaledHeight()-96, display.getEnergyStorage(), true, true);

                        GlStateManager.pushMatrix();
                        GlStateManager.color(1F, 1F, 1F, 1F);
                        energyDisplay.draw();
                        GlStateManager.popMatrix();
                    }
                }

                if(tileHit instanceof IVoidEnergyUser) {
                    IVoidEnergyUser voidEnergy = (IVoidEnergyUser) tileHit;
                    if(!player.isSneaking()) {
                        System.out.println("displays");
                        if(voidEnergy.getVoidEnergy() != null) {
                            System.out.println("Does not displays");
                            minecraft.fontRendererObj.drawStringWithShadow("Void Flux: " + voidEnergy.getVoidEnergy().getEnergyStored(), event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+15, StringUtil.DECIMAL_COLOR_WHITE);
                        }
                    }
                }
            }
        }
    }

 

in particular:

 

   if(tileHit instanceof IVoidEnergyUser) {
                    IVoidEnergyUser voidEnergy = (IVoidEnergyUser) tileHit;
                    if(!player.isSneaking()) {
                        System.out.println("displays");
                        if(voidEnergy.getVoidEnergy() != null) {
                            System.out.println("Does not displays");
                            minecraft.fontRendererObj.drawStringWithShadow("Void Flux: " + voidEnergy.getVoidEnergy().getEnergyStored(), event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+15, StringUtil.DECIMAL_COLOR_WHITE);
                        }
                    }
                }
            }
        }

 

Also, the IVoidEnergyUser:

public interface IVoidEnergyUser {

    @SideOnly(Side.CLIENT)
    IVoidEnergy getVoidEnergy();
}

 

Lastly, the TE:

public IVoidEnergy voidStorage;

    public TileEntityVoidPump() {
        super("geothermicPump");
    }


   @Override
    public void updateEntity() {
        super.updateEntity();
        if(!world.isRemote) {
            if (player != null) {
                tick++;

                if(voidStorage == null) {
                    final Chunk chunk = world.getChunkFromBlockCoords(this.getPos());
                    final ChunkPos chunkPos = chunk.getPos();
                    this.voidStorage = CapabilityVoidEnergy.getVoidEnergyFromChunk(world, chunkPos);
                }

                if(voidStorage != null) {
                    if(tick >= 10) {
                        if(!hasDug) {
                            digDownOperation();
                        }else {
                            renderLaserToEndPoint(this.getPos().getX(), -15, this.getPos().getZ());
                            verifyScafolding();
                            if(rand.nextInt(5) == 0) {
                                voidStorage.extractEnergy(rand.nextInt(2), false);
                            }
                            storage.receiveEnergyInternal(PRODUCE, false);
                        }
                        tick=0;
                    }
                }else {
                    ModUtil.LOGGER.warn("A Player tried interacting with a null chunk! Restart your world!");
                }
            }else if(uuid != null){
                this.player = getPlayerFromUUID(uuid);
            }
            if(uuid == null & player != null) {
                setUuid(player.getUniqueID());
            }
            if(player == null && uuid == null) {
                ModUtil.LOGGER.warn("No player or UUID was saved! A player must replace the Geothermic Pump @ x: " + pos.getX() + " y: " + pos.getY() + " z: " + pos.getZ());
            }

            if(this.oldEnergy != this.storage.getEnergyStored() || this.oldVoid != this.voidStorage.getEnergyStored() && this.sendUpdateWithInterval()){
                this.oldEnergy = this.storage.getEnergyStored();
                this.oldVoid = this.voidStorage.getEnergyStored();
            }
        }
    }

    public void digDownOperation() {
        if (blockToBreak == null || (blockToBreak.getX() == 0 && blockToBreak.getY() == 0 && blockToBreak.getZ() == 0)) {
            blockToBreak = new BlockPos(this.getPos().getX(), this.getPos().getY() - 1, this.getPos().getZ());
        }else {
            IBlockState block = world.getBlockState(blockToBreak);
            if(block.getBlock() == Blocks.AIR) {
                world.setBlockState(blockToBreak, InitBlocks.blockScafolding.getDefaultState());
                blockToBreak = blockToBreak.down();
            }else if(!(block.getBlock() instanceof BlockContainer)) {
                renderStaticEffect(EnumParticleTypes.END_ROD, blockToBreak.getX(), blockToBreak.getY(), blockToBreak.getZ());
                world.destroyBlock(blockToBreak, false);
            }else {
                renderStaticEffect(EnumParticleTypes.SMOKE_NORMAL, this.getPos().getX(), this.getPos().getY()+.5, this.getPos().getZ());
            }
        }

        if(blockToBreak.getY() <= 0) {
            hasDug = true;
        }
    }

    @Override
    public IVoidEnergy getVoidEnergy() {
        if(voidStorage != null) {
            return voidStorage;
        }else {
            return null;
        }
    }

 

For github users:

IVoidEnergyUser: >interfacing

Event: >event

TE: block>tile>TileEntityVoidPump

 

 

Thanks.

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

  • Author

No, the System.outs on the overlay:

(these lines)

 

 

   if(tileHit instanceof IVoidEnergyUser) {
                    IVoidEnergyUser voidEnergy = (IVoidEnergyUser) tileHit;
                    if(!player.isSneaking()) {
                        System.out.println("displays");
                        if(voidEnergy.getVoidEnergy() != null) {
                            System.out.println("Does not displays");
                            minecraft.fontRendererObj.drawStringWithShadow("Void Flux: " + voidEnergy.getVoidEnergy().getEnergyStored(), event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+15, StringUtil.DECIMAL_COLOR_WHITE);
                        }
                    }
                }
            }
        }

 

 

the one that says displays works, however the other one doesnt run at all, which tells me the if state about is false.

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

So, presumably

voidEnergy

is null when the method is getting called. Use printlns or the debugger to check whether it is being initialised as it should be. What exactly does

CapabilityVoidEnergy.getVoidEnergyFromChunk(world, chunkPos)

do - is it returning null?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.