Jump to content

Recommended Posts

Posted

I am trying to update custom crafting table from 1.7.10 to 1.8 and can't seem to get the Gui to open.  I have been able to update other blocks that have tile entities, but I cannot get the table to open.

 

Here is my GuiHandler:

 

package com.nealegaming.mod.handler;

import com.nealegaming.mod.NGGlobal;
import com.nealegaming.mod.blocks.NGBlocks;
import com.nealegaming.mod.container.ContainerAlloySmelter;
import com.nealegaming.mod.container.ContainerDraftingBoard;
import com.nealegaming.mod.container.ContainerGraniteOven;
import com.nealegaming.mod.container.ContainerIngotMasher;
import com.nealegaming.mod.gui.GuiAlloySmelter;
import com.nealegaming.mod.gui.GuiDraftingBoard;
import com.nealegaming.mod.gui.GuiGraniteOven;
import com.nealegaming.mod.gui.GuiIngotMasher;
import com.nealegaming.mod.tileentity.TileEntityAlloySmelter;
import com.nealegaming.mod.tileentity.TileEntityGraniteOven;
import com.nealegaming.mod.tileentity.TileEntityIngotMasher;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;

public class NGGuiHandler implements IGuiHandler {

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	TileEntity entity = world.getTileEntity(new BlockPos(x, y, z));
	if (entity != null) {
		switch(ID) {
		case NGGlobal.graniteOvenGUIID:
			if (entity instanceof TileEntityGraniteOven) {
				return new ContainerGraniteOven(player.inventory, (TileEntityGraniteOven) entity);
			}
			return null;

		case NGGlobal.alloySmelterGUIID:
			if (entity instanceof TileEntityAlloySmelter) {
				return new ContainerAlloySmelter(player.inventory, (TileEntityAlloySmelter) entity);
			}
			return null;


		case NGGlobal.ingotMasherGUIID:
			if (entity instanceof TileEntityIngotMasher) {
				return new ContainerIngotMasher(player.inventory, (TileEntityIngotMasher) entity);
			}
			return null;
		}
	}
	if(ID == NGGlobal.draftingBoardGUIID) {

		return ID == NGGlobal.draftingBoardGUIID && world.getBlockState(new BlockPos (x, y, z)) == NGBlocks.draftingTable ? new ContainerDraftingBoard(player.inventory, world, x, y, z) : null;
	}

    return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	TileEntity entity = world.getTileEntity(new BlockPos(x, y, z));

	if(entity != null) {
		switch(ID) {
		case NGGlobal.graniteOvenGUIID:
			if (entity instanceof TileEntityGraniteOven) {
				return new GuiGraniteOven(player.inventory, (TileEntityGraniteOven) entity);
			}
			return null;

		case NGGlobal.alloySmelterGUIID:
			if (entity instanceof TileEntityAlloySmelter) {
				return new GuiAlloySmelter(player.inventory, (TileEntityAlloySmelter) entity);
			}
			return null;

		case NGGlobal.ingotMasherGUIID:
			if (entity instanceof TileEntityIngotMasher) {
				return new GuiIngotMasher(player.inventory, (TileEntityIngotMasher) entity);
			}
			return null;
		}

	}
	if(ID == NGGlobal.draftingBoardGUIID) {
		return ID == NGGlobal.draftingBoardGUIID && world.getBlockState(new BlockPos (x, y, z)) == NGBlocks.draftingTable ? new GuiDraftingBoard(player.inventory, world, x, y, z) : null;
	}
	return null;
}
}

 

And my Block class for the crafting table:

 

package com.nealegaming.mod.blocks;

import com.nealegaming.mod.Main;
import com.nealegaming.mod.NGGlobal;
import com.nealegaming.mod.container.ContainerDraftingBoard;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.IInteractionObject;
import net.minecraft.world.World;

public class NGDraftingBoard extends Block
{
    protected NGDraftingBoard(String name)
    {
        super(Material.wood);
        this.setCreativeTab(NGGlobal.ngCreativeTab);
        this.setUnlocalizedName(name);
    }

    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
    {
    	if (!worldIn.isRemote) {
    		playerIn.openGui(Main.instance, NGGlobal.draftingBoardGUIID, worldIn, pos.getX(), pos.getY(), pos.getZ());
        }
        return true;
    }

    public static class InterfaceCraftingTable implements IInteractionObject
        {
            private final World world;
            private final BlockPos position;

            public InterfaceCraftingTable(World worldIn, BlockPos pos)
            {
                this.world = worldIn;
                this.position = pos;
            }

            /**
             * Get the name of this object. For players this returns their username
             */
            public String getName()
            {
                return null;
            }

            /**
             * Returns true if this thing is named
             */
            public boolean hasCustomName()
            {
                return false;
            }

            /**
             * Get the formatted ChatComponent that will be used for the sender's username in chat
             */
            public IChatComponent getDisplayName()
            {
                return new ChatComponentTranslation(NGBlocks.draftingTable.getUnlocalizedName() + ".name", new Object[0]);
            }

            public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
            {
                return new ContainerDraftingBoard(playerInventory, this.world, this.position);
            }

            public String getGuiID()
            {
                return "ng:draftingBoard";
            }
        }
}

 

I can post more classes, if I need to.  Just a point in the general direction would be greatly appreciated.

Posted

I guess I have been staring at it too long.  I don't even need to compare them.

 

I did this for getServerGuiElement instead and the GUI opens for a second, but only just:

 

if(ID == NGGlobal.draftingBoardGUIID) {
return new ContainerDraftingBoard(player.inventory, world, x, y, z);
}

 

It's the same with getClientGuiElement:

 

if(ID == NGGlobal.draftingBoardGUIID) {
return new GuiDraftingBoard(player.inventory, world, x, y, z);
}

Posted

I should say (shame on me) is that my console has the following when I RClick on it:

 

java.lang.NullPointerException: Ticking entity
at com.nealegaming.mod.container.ContainerDraftingBoard.canInteractWith(ContainerDraftingBoard.java:93)

 

That method is this:

 

public boolean canInteractWith(EntityPlayer playerIn)
    {
    	return this.worldObj.getBlockState(this.pos).getBlock() != NGBlocks.draftingTable ? false : playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
    }

Posted
  On 2/23/2016 at 12:14 PM, nxwhitney said:

I should say (shame on me) is that my console has the following when I RClick on it:

 

java.lang.NullPointerException: Ticking entity
at com.nealegaming.mod.container.ContainerDraftingBoard.canInteractWith(ContainerDraftingBoard.java:93)

 

That method is this:

 

public boolean canInteractWith(EntityPlayer playerIn)
    {
    	return this.worldObj.getBlockState(this.pos).getBlock() != NGBlocks.draftingTable ? false : playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
    }

Then there's something null there (it should be obvious).

Now, use your IDE's debug mode to see what actually is 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...

×   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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have no idea what the flip is going on, I can load the modpack just fine at forge 42.2.0 but any forge version above it insta-crashes with exit code 1. Can somebody tell me what's going on, this is minecraft 1.20.1 Latest.log: https://pastebin.com/pBUL1ZFa
    • does anyone know how to incorporate custom noise settings into a custom dimension through the use of datagen, I have created a custon json file for the noise settings that I want but I just don't know how to get it to register with the generated json file of the custom dimension.   here is the code for the dimension class package net.hurst.lustria.worldgen.dimension; import com.mojang.datafixers.util.Pair; import net.hurst.lustria.Lustria; import net.hurst.lustria.worldgen.biome.ModBiomes; import net.hurst.lustria.worldgen.registries.LustriaNoiseSettings; import net.minecraft.core.HolderGetter; import net.minecraft.core.registries.Registries; import net.minecraft.data.worldgen.BootstapContext; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; import net.minecraft.util.valueproviders.ConstantInt; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.*; import net.minecraft.world.level.dimension.BuiltinDimensionTypes; import net.minecraft.world.level.dimension.DimensionType; import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; import java.util.List; import java.util.OptionalLong; public class ModDimensions { public static final ResourceKey<LevelStem> LUSTRIA_KEY = ResourceKey.create(Registries.LEVEL_STEM, ResourceLocation.fromNamespaceAndPath(Lustria.MOD_ID, "lustriadim")); public static final ResourceKey<Level> LUSTRIA_LEVEL_KEY = ResourceKey.create(Registries.DIMENSION, ResourceLocation.fromNamespaceAndPath(Lustria.MOD_ID, "lustriadim")); public static final ResourceKey<DimensionType> LUSTRIA_DIM_TYPE = ResourceKey.create(Registries.DIMENSION_TYPE, ResourceLocation.fromNamespaceAndPath(Lustria.MOD_ID, "lustriadim_type")); public static void bootstrapType(BootstapContext<DimensionType> context) { context.register(LUSTRIA_DIM_TYPE, new DimensionType( OptionalLong.of(12000), // fixedTime false, // hasSkylight true, // hasCeiling false, // ultraWarm false, // natural 1.0, // coordinateScale true, // bedWorks false, // respawnAnchorWorks -64, // minY 256, // height 256, // logicalHeight BlockTags.INFINIBURN_OVERWORLD, // infiniburn BuiltinDimensionTypes.OVERWORLD_EFFECTS, // effectsLocation 0.0f, // ambientLight new DimensionType.MonsterSettings(false, false, ConstantInt.of(0), 0))); } public static void bootstrapStem(BootstapContext<LevelStem> context) { HolderGetter<Biome> biomeRegistry = context.lookup(Registries.BIOME); HolderGetter<DimensionType> dimTypes = context.lookup(Registries.DIMENSION_TYPE); HolderGetter<NoiseGeneratorSettings> noiseGenSettings = context.lookup(Registries.NOISE_SETTINGS); NoiseBasedChunkGenerator wrappedChunkGenerator = new NoiseBasedChunkGenerator( new FixedBiomeSource(biomeRegistry.getOrThrow(Biomes.BEACH)), noiseGenSettings.getOrThrow(NoiseGeneratorSettings.CAVES)); NoiseBasedChunkGenerator noiseBasedChunkGenerator = new NoiseBasedChunkGenerator( MultiNoiseBiomeSource.createFromList( new Climate.ParameterList<>(List.of(Pair.of( Climate.parameters(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F), biomeRegistry.getOrThrow(Biomes.BEACH)), Pair.of( Climate.parameters(0.1F, 0.2F, 0.0F, 0.2F, 0.0F, 0.0F, 0.0F), biomeRegistry.getOrThrow(Biomes.BIRCH_FOREST)), Pair.of( Climate.parameters(0.3F, 0.6F, 0.1F, 0.1F, 0.0F, 0.0F, 0.0F), biomeRegistry.getOrThrow(Biomes.OCEAN)), Pair.of( Climate.parameters(0.4F, 0.3F, 0.2F, 0.1F, 0.0F, 0.0F, 0.0F), biomeRegistry.getOrThrow(Biomes.DARK_FOREST)) ))), noiseGenSettings.getOrThrow(NoiseGeneratorSettings.CAVES)); LevelStem stem = new LevelStem(dimTypes.getOrThrow(ModDimensions.LUSTRIA_DIM_TYPE), noiseBasedChunkGenerator); context.register(LUSTRIA_KEY, stem); } } minecraft version is 1.20.1
    • Please read the FAQ (https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/) and post logs as described there using a site like https://mclo.gs and post the link to it here. It may have the information required to solve your problem.  
    • the error code comes up when i trry to run it and ive tried to fix it but i cant  
  • Topics

×
×
  • Create New...

Important Information

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