Jump to content

Recommended Posts

Posted

I've made a block which has many versions of itself using metadata.

 

I used a for loop in my main mod class to add metadata-specific names to each block version, but I'm getting a null pointer error, for no apparent reason (There's obviously a reason :P)

 

Adding names (the first for loop works but isn't for the relevant block, the second for loop is the one that doesn't work):

 

for (int k = 0; k < Variables.getLastInt(ItemAnt.antMeta) + Variables.getLastInt(ItemAnt.typeMeta); k++){

		ItemStack ant = new ItemStack(itemAnt, 1, k);

		String name = ItemAnt.names[k];

		LanguageRegistry.addName(ant, name);

	}

	for (int i = 0; i < Variables.getLastInt(BlockAntHill.hillMeta); i++){

		ItemStack hill = new ItemStack(blockAntHill, 1, i);

		String name2 = BlockAntHill.hillNames[i];

		/* Line 168 --->*/ LanguageRegistry.addName(hill, BlockAntHill.hillNames[i]);

	}

 

The getLastInt method:

public static int getLastInt(int[] array){

	int a;

	a = array[array.length - 1];

	return a;

}

 

The hillMeta variable in BlockAntHill:

 

public static final int[] hillMeta = {0, 1, 2, 3, 4, 5, 6};

 

The hillNames variable in BlockAntHill:

private static final String NAME = "Ant Hill";

public static final String[] hillNames = {"Forest "+NAME, "Hillside "+NAME, "Desert "+NAME, "Swamp "+NAME, 
	"Plains "+NAME, "Jungle "+NAME, "Snowy "+NAME};

 

The blockAntHill object:

public static Block blockAntHill;
blockAntHill = new BlockAntHill(blockAntHillID);

 

The error:

---- Minecraft Crash Report ----
// Daisy, daisy...

Time: 6/10/13 10:09 PM
Description: Failed to start game

java.lang.NullPointerException
at cpw.mods.fml.common.registry.LanguageRegistry.addNameForObject(LanguageRegistry.java:110)
at cpw.mods.fml.common.registry.LanguageRegistry.addName(LanguageRegistry.java:120)
at vivadaylight3.myrmecology.common.Myrmecology.mainInit(Myrmecology.java:168)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:494)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)
at com.google.common.eventbus.EventBus.post(EventBus.java:267)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:165)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)
at com.google.common.eventbus.EventBus.post(EventBus.java:267)
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:98)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:696)
at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:213)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:448)
at net.minecraft.client.MinecraftAppletImpl.startGame(MinecraftAppletImpl.java:44)
at net.minecraft.client.Minecraft.run(Minecraft.java:733)
at java.lang.Thread.run(Thread.java:680)


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

-- System Details --
Details:
Minecraft Version: 1.5.2
Operating System: Mac OS X (x86_64) version 10.8.3
Java Version: 1.6.0_45, Apple Inc.
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Apple Inc.
Memory: 36162168 bytes (34 MB) / 85000192 bytes (81 MB) up to 2138767360 bytes (2039 MB)
JVM Flags: 1 total; -Xmx2g
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Suspicious classes: FML and Forge are installed
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v7.51 FML v5.2.17.716 Minecraft Forge 7.8.0.716 4 mods loaded, 4 mods active
mcp{7.44} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized
FML{5.2.17.716} [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized->Initialized
Forge{7.8.0.716} [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized->Initialized
Myrmecology{0.0.1} [Myrmecology] (bin) Unloaded->Constructed->Pre-initialized->Errored
LWJGL: 2.4.2
OpenGL: Intel HD Graphics 3000 OpenGL Engine GL version 2.1 INTEL-8.10.44, Intel Inc.
Is Modded: Definitely; Client brand changed to 'fml,forge'
Type: Client (map_client.txt)
Texture Pack: Default
Profiler Position: N/A (disabled)
Vec3 Pool Size: ~~ERROR~~ NullPointerException: null

 

I appreciate any help, thanks in advance!

"Thinking that coding is the nerdy IT guy at work rebooting your computer is like thinking that music is what happens when the piano tuner comes round." - Ed Rex

Posted

Why... do you... never mind, I don't even want to ask.

 

You probably want to use i/k < myList.length if you want to register the name for all of the items. As it is you're leaving out the last one.

Your problem could be caused by a failure to register your block. Are you registering your block?

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Posted

What is it you don't want to ask me about? I would like to optimise my code if that's the thing.

 

I solved it by registering the block prior to adding then name, that was the very obvious problem :P (noob moment)

 

Thanks for the help!

"Thinking that coding is the nerdy IT guy at work rebooting your computer is like thinking that music is what happens when the piano tuner comes round." - Ed Rex

Posted

The reason why I have the getLastInt() method is because I often forget how to do several things in Java, so I make methods so that I don't forget :)

 

If you mean native 'speaking' language, I was born in England and it's English.

 

If you mean native programming language, I come from a PHP, Css and HTML background.

"Thinking that coding is the nerdy IT guy at work rebooting your computer is like thinking that music is what happens when the piano tuner comes round." - Ed Rex

Posted

The reason why I have the getLastInt() method is because I often forget how to do several things in Java, so I make methods so that I don't forget :)

 

If you mean native 'speaking' language, I was born in England and it's English.

 

If you mean native programming language, I come from a PHP, Css and HTML background.

I did mean programming... I'm a Python person myself, and I hate Java with all my heart. But I mod MC anyway, because I like modding and there's little I can do about the language.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Posted

I like Java, but prefer PHP for its simplicity.

 

For some reason I can't register names for each metadata variant for my antHill block.

 

Each metadata variant appears in the creative menu but has the name "Snow Ant Hill" which is the last value of the hillNames array. I haven't been able to figure out why  :-\  ???

 

I event tried adding the names manually with several LanguageRegistry.addName(block variable, metadata name) but I got the same result.

 

Adding names in main class:

blockAntHill = new BlockAntHill(blockAntHillID);

for (int k = 0; k < Variables.getLastInt(BlockAntHill.hillMeta); k++){

		ItemStack ant = new ItemStack(blockAntHill, 1, k);

		LanguageRegistry.addName(ant, BlockAntHill.hillNames[k]);

	}

 

The BlockAntHill class:

package vivadaylight3.myrmecology.common.block;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import vivadaylight3.myrmecology.common.Myrmecology;
import vivadaylight3.myrmecology.common.item.ItemAnt;
import vivadaylight3.myrmecology.common.item.ItemExtractor;
import vivadaylight3.myrmecology.common.lib.Variables;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.world.World;

public class BlockAntHill extends Block
{

public static final int[] hillMeta = {0, 1, 2, 3, 4, 5, 6};

private static final String NAME = "Ant Hill";

public static final String[] hillNames = {"Forest "+NAME, "Hillside "+NAME, "Desert "+NAME, "Swamp "+NAME, 
	"Plains "+NAME, "Jungle "+NAME, "Snowy "+NAME};

private static Icon[] icons;

private final String[] iconNames = {Myrmecology.TEXTURE_PREFIX+Myrmecology.ITEM_ANT_NAME, 
		Myrmecology.TEXTURE_PREFIX+Myrmecology.ITEM_ANT_NAME+"_Forest", 
		Myrmecology.TEXTURE_PREFIX+Myrmecology.ITEM_ANT_NAME+"_Hills", 
		Myrmecology.TEXTURE_PREFIX+Myrmecology.ITEM_ANT_NAME+"_Desert",
		Myrmecology.TEXTURE_PREFIX+Myrmecology.ITEM_ANT_NAME+"_Swamp", 
		Myrmecology.TEXTURE_PREFIX+Myrmecology.ITEM_ANT_NAME+"_Plains", 
		Myrmecology.TEXTURE_PREFIX+Myrmecology.ITEM_ANT_NAME+"_Jungle", 
		Myrmecology.TEXTURE_PREFIX+Myrmecology.ITEM_ANT_NAME+"_Snow"};

public BlockAntHill(int par1)
{
	super(par1, Material.ground);
	setUnlocalizedName("antHill");
	setCreativeTab(Myrmecology.tabMyrmecology);
	setStepSound(Block.soundGrassFootstep);
	setHardness(1.0F);
	setResistance(1.0F);
}

@Override
public void registerIcons(IconRegister iconRegister){

	icons = Variables.iconsToArray(iconRegister, iconNames);

}

@Override
public Icon getIcon(int side, int metadata){

	return icons[metadata];

}

public String getUnlocalizedName(ItemStack itemStack)
    {

    	return this.getUnlocalizedName() + hillNames[itemStack.getItemDamage()];
    
    }

@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
    {

	for (int k = 0; k < hillMeta.length + 1; k++){

		par3List.add(new ItemStack(this, 1, k));

	}
    }

@Override
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9){

	return true;

}

public void harvestBlock(World world, EntityPlayer entity, int x, int y, int z){

	if(!world.isRemote){

		ItemStack tool = entity.getCurrentEquippedItem();
		ItemStack extractor = new ItemStack(Myrmecology.itemExtractor);

		if(tool != null && tool == extractor){

			int meta = world.getBlockMetadata(x, y, z);

			for(int k = 0; k < hillMeta.length * 5 + 1; k++){

				if(meta == k){

					ItemStack drone = new ItemStack(Myrmecology.itemAnt, k + ItemAnt.typeMeta[1], 1);
					ItemStack queen = new ItemStack(Myrmecology.itemAnt, k + ItemAnt.typeMeta[0], 1);
					entity.dropPlayerItem(drone);
					entity.dropPlayerItem(queen);

				}

			}

		}
	}

}

}

 

Does anyone have any idea why? :/

"Thinking that coding is the nerdy IT guy at work rebooting your computer is like thinking that music is what happens when the piano tuner comes round." - Ed Rex

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

    • You would have better results asking a more specific question. What have you done? What exactly do you need help with? Please also read the FAQ regarding posting logs.
    • Hi, this is my second post with the same content as no one answered this and it's been a long time since I made the last post, I want to make a client-only mod, everything is ok, but when I use shaders, none of the textures rendered in RenderLevelStageEvent nor the crow entity model are rendered, I want them to be visible, because it's a horror themed mod I've already tried it with different shaders, but it didn't work with any of them and I really want to add support for shaders Here is how i render the crow model in the CrowEntityRenderer<CrowEntity>, by the time i use this method, i know is not the right method but i don't think this is the cause of the problem, the renderType i'm using is entityCutout @Override public void render(CrowEntity p_entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { super.render(p_entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientEventHandler.getClient().crow.renderToBuffer(poseStack, bufferSource.getBuffer(ClientEventHandler.getClient().crow .renderType(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY, Utils.rgb(255, 255, 255)); } Here renderLevelStage @Override public void renderWorld(RenderLevelStageEvent e) { horrorEvents.draw(e); } Here is how i render every event public void draw(RenderLevelStageEvent e) { for (HorrorEvent event : currentHorrorEvents) { event.tick(e.getPartialTick()); event.draw(e); } } Here is how i render the crow model on the event @Override public void draw(RenderLevelStageEvent e) { if(e.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) { float arcProgress = getArcProgress(0.25f); int alpha = (int) Mth.lerp(arcProgress, 0, 255); int packedLight = LevelRenderer.getLightColor(Minecraft.getInstance().level, blockPos); VertexConsumer builder = ClientEventHandler.bufferSource.getBuffer(crow); Crow<CreepyBirdHorrorEvent> model = ClientEventHandler .getClient().crow; model.setupAnim(this); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, packedLight, OverlayTexture.NO_OVERLAY, alpha); builder = ClientEventHandler.bufferSource.getBuffer(eyes); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, 15728880, OverlayTexture.NO_OVERLAY, alpha); } } How i render the model public static void renderModelInWorld(Model model, Vector3f pos, Vector3f offset, Camera camera, PoseStack matrix, VertexConsumer builder, int light, int overlay, int alpha) { matrix.pushPose(); Vec3 cameraPos = camera.getPosition(); double finalX = pos.x - cameraPos.x + offset.x; double finalY = pos.y - cameraPos.y + offset.y; double finalZ = pos.z - cameraPos.z + offset.z; matrix.pushPose(); matrix.translate(finalX, finalY, finalZ); matrix.mulPose(Axis.XP.rotationDegrees(180f)); model.renderToBuffer(matrix, builder, light, overlay, Utils .rgba(255, 255, 255, alpha)); matrix.popPose(); matrix.popPose(); } Thanks in advance
    • Same issue - I have no idea
    • I am trying to develop a modpack for me and my friends to use on our server. Does anyone know how to develop a modpack for a server or could they help take a look at my modpack to potentially help at all?
    • un server de armas realista.  
  • Topics

×
×
  • Create New...

Important Information

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