Jump to content

Recommended Posts

Posted

I have a few problems I can't seem to fix in my mod, hopefully someone else can tell me whats wrong. :P

 

Custom EntityItem Problem

 

 

I'm trying to create a custom EntityItem, so that when you throw an item on the ground it doesn't disappear in fire or when hitting a cactus. So, I created this class:

 

import net.minecraft.src.DamageSource;
import net.minecraft.src.EntityItem;
import net.minecraft.src.ItemStack;
import net.minecraft.src.World;
public class InvEntityItem extends EntityItem {

public InvEntityItem(World par1World, double par2, double par4, double par6, ItemStack par8ItemStack){

super(par1World, par2, par4, par6, par8ItemStack);
}

public InvEntityItem(World par1world){

super(par1world);
}

protected void dealFireDamage(int par1)
{
}

public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
{
         return false;
}
}

 

To replace the EntityItem, and added these functions to the item whose drop I wanted to modify:

 

public boolean hasCustomEntity(ItemStack stack)
{
         return true;
}

public Entity createEntity(World world, Entity location, ItemStack itemstack)
{
         return new InvEntityItem(world, location.posX, location.posY, location.posZ, itemstack);
}

 

Thought this would do the trick, however once ingame and pressing q to drop the item, the client crashes and I receive this error report:

 

java.lang.StackOverflowError

at sun.security.provider.ByteArrayAccess.i2bBig4(Unknown Source)

at sun.security.provider.SHA.implDigest(Unknown Source)

at sun.security.provider.DigestBase.engineDigest(Unknown Source)

at sun.security.provider.DigestBase.engineDigest(Unknown Source)

at java.security.MessageDigest$Delegate.engineDigest(Unknown Source)

at java.security.MessageDigest.digest(Unknown Source)

at sun.security.provider.SecureRandom.engineNextBytes(Unknown Source)

at java.security.SecureRandom.nextBytes(Unknown Source)

at java.util.UUID.randomUUID(Unknown Source)

at net.minecraft.src.Entity.generatePersistentID(Entity.java:2207)

at net.minecraftforge.common.ForgeInternalHandler.onEntityJoinWorld(ForgeInternalHandler.java:19)

at net.minecraftforge.event.ASMEventHandler_0_ForgeInternalHandler_onEntityJoinWorld_EntityJoinWorldEvent.invoke(.dynamic)

at net.minecraftforge.event.ASMEventHandler.invoke(ASMEventHandler.java:35)

at net.minecraftforge.event.EventBus.post(EventBus.java:103)

at net.minecraft.src.World.spawnEntityInWorld(World.java:1365)

at net.minecraftforge.common.ForgeInternalHandler.onEntityJoinWorld(ForgeInternalHandler.java:37)

at net.minecraftforge.event.ASMEventHandler_0_ForgeInternalHandler_onEntityJoinWorld_EntityJoinWorldEvent.invoke(.dynamic)

at net.minecraftforge.event.ASMEventHandler.invoke(ASMEventHandler.java:35)

at net.minecraftforge.event.EventBus.post(EventBus.java:103)

at net.minecraft.src.World.spawnEntityInWorld(World.java:1365)

at net.minecraftforge.common.ForgeInternalHandler.onEntityJoinWorld(ForgeInternalHandler.java:37)

 

It repeats that last sequence of errors over and over for a long time.

 

I know that a StackOverflow error is caused by overflowing the stack (no, really?) and is usually a result of poorly handled recursion, but I have no idea where the problem is, and it seems none of my actual code is cited in the error report. Anyone have any ideas about whats happening here?

 

 

Custom Texture Problem

 

 

Also, I'm having a problem setting a custom texture. I made the png file and put it in the minecraft.jar, then set up my code according to this guide: http://www.minecraftforge.net/wiki/How_to_use_infinite_terrain_and_sprite_indexes

 

I get no errors when I run it, but instead of the item using my custom texture which is in slot 0, its a leather helmet. So i know its not using the right texture file, but have no idea why...

 

edit: Figured out the problem. I was using renderSnowball to render an EntityItem with a custom texture, but it turns out that renderSnowball doesn't use the texture file of what you pass to it, it only uses the default texture file. So, I just made a copy of the class and had it use my custom texture file instead, and problem solved.

 

 

 

Block Movement Problem

 

 

I created an item that I want to move a block one block up when right-clicking. To that effect, I wrote this code:

 

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer){

  if(Minecraft.getMinecraft().objectMouseOver!=null)
          {
           int x=Minecraft.getMinecraft().objectMouseOver.blockX;
           int y=Minecraft.getMinecraft().objectMouseOver.blockY;
           int z=Minecraft.getMinecraft().objectMouseOver.blockZ;
          
           int id = par2World.getBlockId(x, y, z);
          
                
          
                par2World.setBlockWithNotify(x, y, z, 0);
                par2World.setBlockWithNotify(x, y+1, z, id);
          
          }

 

The problem is, when testing it in game, the behavior is pretty weird. Sometimes it functions correctly, but a lot of the time it does various other things such as not moving the block but making it flicker between air and regular texture, moving the block but not changing the position it was in to air, and moving the block as well as the block behind it. I have no idea what could be causing these things to happen.

 

 

I would appreciate any and all help.  :)

Posted

1)

This method:

public Entity createEntity(World world, Entity location, ItemStack itemstack)
{
         return new EntityItem(world, location.posX, location.posY, location.posZ, itemstack);
}

 

MUST return an instance of your new EntityItem, NOT the original EntityItem!

 

2) Make sure the path is correct. It must have a slash at the beginning. If that doesn't work, use setTextureFile(path) on an instance of your item / block, like:

Block custom = new Block(blockID, 0, Material.wood);
custom.setTextureFile("/Path/File.png");

 

3) That code doesn't work in any way on a server. I would first make sure the code is executed only client-side with the Proxy system and then use packets for this.

 

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

1)

This method:

public Entity createEntity(World world, Entity location, ItemStack itemstack)
{
         return new EntityItem(world, location.posX, location.posY, location.posZ, itemstack);
}

 

MUST return an instance of your new EntityItem, NOT the original EntityItem!

 

2) Make sure the path is correct. It must have a slash at the beginning. If that doesn't work, use setTextureFile(path) on an instance of your item / block, like:

Block custom = new Block(blockID, 0, Material.wood);
custom.setTextureFile("/Path/File.png");

 

3) That code doesn't work in any way on a server. I would first make sure the code is executed only client-side with the Proxy system and then use packets for this.

 

Ah, for the first one I forgot I left it like that. I changed it to a regular EntityItem to see if it would work after it crashed when using my custom one, and it still crashed while returning the regular EntityItem.

 

The second one I just fixed. I was using renderSnowball to render a projectile, and I figured out that it only uses the default texture file and not one from its arguments, so I copied it to a new class and changed its texture file.

 

For the third one, I'm still not too experienced and don't know what you mean by using packets. Also, could you suggest a better way of doing the code if it doesn't work on servers? I'd prefer it to work more like pistons or maybe sand/gravel, but haven't really been able to figure out how those classes work...

Posted

1) Thats caused because you use a EntityItem subclass, which you shouldn't, but i've just added support for that.

3) Check your locations, see ItemBlock, the position you get is NOT the position of the block, it's the position NEXT to it, based on the side hit.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

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



×
×
  • Create New...

Important Information

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