Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Game crashing when the block is activated


jun2040
 Share

Recommended Posts

I'm trying to make a block that has a gui but every time I activate it, my game just crashes.

 

Code:

package com.jun2040.unixmod.blocks;

import com.jun2040.unixmod.UnixMod;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;

public class BioreactorScreen extends ContainerScreen<BioreactorContainer> {

    private ResourceLocation GUI = new ResourceLocation(UnixMod.MODID, "textures/gui/bioreactor.png");

    public BioreactorScreen(BioreactorContainer container, PlayerInventory inv, ITextComponent name) {
        super(container, inv, name);
    }

    @Override
    public void render(int mouseX, int mouseY, float partialTicks) {
        this.renderBackground();
        super.render(mouseX, mouseY, partialTicks);
        this.renderHoveredToolTip(mouseX, mouseY);
    }

    @Override
    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {

    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
        GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.minecraft.getTextureManager().bindTexture(GUI);
        int relX = (this.width - this.xSize) / 2;
        int relY = (this.height - this.ySize) / 2;
        this.blit(relX, relY, 0, 0, this.xSize, this.ySize);
    }
}

 

Error:

---- Minecraft Crash Report ----
// I bet Cylons wouldn't have this problem.

Time: 12/12/19 11:18 PM
Description: Ticking entity

java.lang.NullPointerException: Ticking entity
    at com.jun2040.unixmod.blocks.BioreactorContainer.canInteractWith(BioreactorContainer.java:38) ~[?:?] {re:classloading}
    at net.minecraft.entity.player.ServerPlayerEntity.tick(ServerPlayerEntity.java:338) ~[?:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.world.server.ServerWorld.updateEntity(ServerWorld.java:602) ~[?:?] {re:classloading}
    at net.minecraft.world.World.func_217390_a(World.java:736) ~[?:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.world.server.ServerWorld.tick(ServerWorld.java:397) ~[?:?] {re:classloading}
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:865) ~[?:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:800) ~[?:?] {re:classloading,pl:accesstransformer:B}
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:646) [?:?] {re:classloading,pl:accesstransformer:B}
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_202] {}


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Server thread
Stacktrace:
    at com.jun2040.unixmod.blocks.BioreactorContainer.canInteractWith(BioreactorContainer.java:38)
    at net.minecraft.entity.player.ServerPlayerEntity.tick(ServerPlayerEntity.java:338)
    at net.minecraft.world.server.ServerWorld.updateEntity(ServerWorld.java:602)

-- Entity being ticked --
Details:
    Entity Type: minecraft:player (net.minecraft.entity.player.ServerPlayerEntity)
    Entity ID: 126
    Entity Name: Dev
    Entity's Exact location: -149.92, 22.00, -45.12
    Entity's Block location: World: (-150,22,-46), Chunk: (at 10,1,2 in -10,-3; contains blocks -160,0,-48 to -145,255,-33), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
    Entity's Momentum: 0.00, -0.08, 0.00
    Entity's Passengers: []
    Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
    at net.minecraft.world.World.func_217390_a(World.java:736)
    at net.minecraft.world.server.ServerWorld.tick(ServerWorld.java:397)

-- Affected level --
Details:
    All players: 1 total; [ServerPlayerEntity['Dev'/126, l='mod test', x=-149.92, y=22.00, z=-45.12]]
    Chunk stats: ServerChunkCache: 2246
    Level dimension: DimensionType{minecraft:overworld}
    Level name: mod test
    Level seed: -2385347844768643725
    Level generator: ID 01 - flat, ver 0. Features enabled: true
    Level generator options: {biome:"minecraft:plains",layers:[{block:"minecraft:bedrock",height:1b},{block:"minecraft:dirt",height:20b},{block:"minecraft:grass_block",height:1b}],structures:{village:{}}}
    Level spawn location: World: (-176,22,-112), Chunk: (at 0,1,0 in -11,-7; contains blocks -176,0,-112 to -161,255,-97), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
    Level time: 54794 game time, 3461 day time
    Level storage version: 0x04ABD - Anvil
    Level weather: Rain time: 36009 (now: false), thunder time: 52923 (now: false)
    Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true
Stacktrace:
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:865)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:800)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:646)
    at java.lang.Thread.run(Thread.java:748)

-- System Details --
Details:
    Minecraft Version: 1.14.4
    Minecraft Version ID: 1.14.4
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_202, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 535933160 bytes (511 MB) / 2076704768 bytes (1980 MB) up to 3771203584 bytes (3596 MB)
    CPUs: 12
    JVM Flags: 1 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump
    ModLauncher: 4.1.0+62+5bfa59b
    ModLauncher launch target: fmluserdevclient
    ModLauncher naming: mcp
    ModLauncher services: 
        /eventbus-1.0.0-service.jar eventbus PLUGINSERVICE 
        /forge-1.14.4-28.1.87_mapped_snapshot_20191111-1.14.3-launcher.jar object_holder_definalize PLUGINSERVICE 
        /forge-1.14.4-28.1.87_mapped_snapshot_20191111-1.14.3-launcher.jar runtime_enum_extender PLUGINSERVICE 
        /accesstransformers-1.0.1-milestone.0.1+94458e7-shadowed.jar accesstransformer PLUGINSERVICE 
        /forge-1.14.4-28.1.87_mapped_snapshot_20191111-1.14.3-launcher.jar capability_inject_definalize PLUGINSERVICE 
        /forge-1.14.4-28.1.87_mapped_snapshot_20191111-1.14.3-launcher.jar runtimedistcleaner PLUGINSERVICE 
        /forge-1.14.4-28.1.87_mapped_snapshot_20191111-1.14.3-launcher.jar fml TRANSFORMATIONSERVICE 
    FML: 28.1
    Forge: net.minecraftforge:28.1.87
    FML Language Providers: 
        javafml@28.1
        minecraft@1
    Mod List: 
        client-extra.jar Minecraft {minecraft@1.14.4 DONE}
        main UnixMod {unixmod@0.1 DONE}
        forge-1.14.4-28.1.87_mapped_snapshot_20191111-1.14.3-recomp.jar Forge {forge@28.1.87 DONE}
    Player Count: 1 / 8; [ServerPlayerEntity['Dev'/126, l='mod test', x=-149.92, y=22.00, z=-45.12]]
    Data Packs: vanilla, mod:unixmod, mod:forge
    Type: Integrated Server (map_client.txt)
    Is Modded: Definitely; Client brand changed to 'forge'

Link to comment
Share on other sites

2 hours ago, jun2040 said:

(BioreactorContainer.java:38)

^^^^^^^^^^^^^^^^^^^^^^^

The class              ^^^ Line number

 

Learn to read stack traces.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Oops

Sorry. I was really sleepy last night.

Correct code:

package com.jun2040.unixmod.blocks;

import com.jun2040.unixmod.items.ModItems;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IWorldPosCallable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper;

import static com.jun2040.unixmod.blocks.ModBlocks.BIOREACTOR_CONTAINER;

public class BioreactorContainer extends Container {

    private TileEntity tileEntity;
    private PlayerEntity playerEntity;
    private IItemHandler playerInventory;

    public BioreactorContainer(int windowId, World world, BlockPos pos, PlayerInventory playerInventory, PlayerEntity player) {
        super(BIOREACTOR_CONTAINER, windowId);
        TileEntity tileEntity = world.getTileEntity(pos);
        this.playerEntity = player;
        this.playerInventory = new InvWrapper(playerInventory);

        tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(h -> {
            addSlot(new SlotItemHandler(h, 0, 64, 24));
        });
        layoutPlayerInventorySlots(10, 70);
    }

    @Override
    public boolean canInteractWith(PlayerEntity playerIn) {
        return isWithinUsableDistance(IWorldPosCallable.of(tileEntity.getWorld(), tileEntity.getPos()), playerEntity, ModBlocks.BIOREACTOR);
    }

    private int addSlotRange(IItemHandler handler, int index, int x, int y, int amount, int dx) {
        for (int i = 0 ; i < amount ; i++) {
            addSlot(new SlotItemHandler(handler, index, x, y));
            x += dx;
            index++;
        }
        return index;
    }

    private int addSlotBox(IItemHandler handler, int index, int x, int y, int horAmount, int dx, int verAmount, int dy) {
        for (int j = 0 ; j < verAmount ; j++) {
            index = addSlotRange(handler, index, x, y, horAmount, dx);
            y += dy;
        }
        return index;
    }

    private void layoutPlayerInventorySlots(int leftCol, int topRow) {
        // Player inventory
        addSlotBox(playerInventory, 9, leftCol, topRow, 9, 18, 3, 18);

        // Hotbar
        topRow += 58;
        addSlotRange(playerInventory, 0, leftCol, topRow, 9, 18);
    }
}
Link to comment
Share on other sites

You never assigned a value to the tileEntity field.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

Also, what on earth is this habit I see so many times on this forum...

"I saw an error in the console / I got an error / it didn't compile so I changed something completely unrelated and now I get a different error, please help me fix that one!"

At the same time then not mentioning they ever got that first error.

 

THIS IS A BAD IDEA.

  • Haha 2
Link to comment
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.