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

Evening all,

 

Trying my first mod here,  I've got some code that renders a highlight around air blocks.

 

The code works perfectly, until we come across snow covered blocks,  Then it crashes the client with little to no information as to why.  Here is the code, and the error below. (the try catch is just for debugging)

try
        {
            EntityPlayerSP player = Minecraft.getMinecraft().player;
            World world = player.getEntityWorld();

            if (player.getHeldItemMainhand().getItem() == StrapItems.BASIC_STRAP)
            {
                ItemBasicStrap myItem = (ItemBasicStrap) player.getHeldItemMainhand().getItem();
                RayTraceResult tracer = player.rayTrace(myItem.BlockRange, 1.0F);

                BlockPos pos = tracer.getBlockPos();

                GlStateManager.enableBlend();
                GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
                GlStateManager.glLineWidth(3.0F);
                GlStateManager.disableTexture2D();
                GlStateManager.depthMask(false);

                Block state = world.getBlockState(pos).getBlock();

                double x = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.getPartialTicks();
                double y = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.getPartialTicks();
                double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.getPartialTicks();

                RenderGlobal.drawSelectionBoundingBox(state.FULL_BLOCK_AABB.offset(-x, -y, -z).offset(pos).grow(0.002), 1.0F, 1.0F, 1.0F, 0.4F);

                GlStateManager.depthMask(true);
                GlStateManager.enableTexture2D();
                GlStateManager.disableBlend();
            }
        }
        catch (Exception ex)
        {
            logger.info("AIR STRAPS AIR STRAPS AIR STRAPS >> {}", ex.getMessage());
        }

 

Error

Quote

[20:50:43] [main/ERROR] [FML]: Exception caught during firing event net.minecraftforge.client.event.RenderWorldLastEvent@492f3239:
java.lang.NullPointerException: null
    at com.daten.AirStraps.world.renderHighlights.onRender(renderHighlights.java:60) ~[renderHighlights.class:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_6_renderHighlights_onRender_RenderWorldLastEvent.invoke(.dynamic) ~[?:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?]
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182) [EventBus.class:?]
    at net.minecraftforge.client.ForgeHooksClient.dispatchRenderLast(ForgeHooksClient.java:181) [ForgeHooksClient.class:?]
    at net.minecraft.client.renderer.EntityRenderer.renderWorldPass(EntityRenderer.java:1485) [EntityRenderer.class:?]
    at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1312) [EntityRenderer.class:?]
    at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1115) [EntityRenderer.class:?]
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1208) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:441) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_201]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_201]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_201]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_201]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_201]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_201]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_201]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_201]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    at GradleStart.main(GradleStart.java:25) [start/:?]
[20:50:43] [main/ERROR] [FML]: Index: 1 Listeners:
[20:50:43] [main/ERROR] [FML]: 0: NORMAL
[20:50:43] [main/ERROR] [FML]: 1: ASM: class com.daten.AirStraps.world.renderHighlights onRender(Lnet/minecraftforge/client/event/RenderWorldLastEvent;)V
[20:50:43] [Client Shutdown Thread/INFO] [minecraft/MinecraftServer]: Stopping server
[20:50:43] [Client Shutdown Thread/INFO] [minecraft/MinecraftServer]: Saving players
AL lib: (EE) alc_cleanup: 1 device not closed

 

Any help would be greatly appreciated!!

 

Edited by DatenThielt
Update Title

  • Author
12 hours ago, diesieben07 said:

Little to no information? It tells you exactly what's wrong and on what line. Use the debugger to figure out which value is null and then fix your bug.

That's what I get for programming after a few beers.    Thanks for the reality slap.  The try-catch was hiding the original error line, turned out the raytrace could return null over certain blocks.  Fixed and thank you!

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.