Jump to content

Problem with my mountable entity


Jammy780

Recommended Posts

Hi there, I'm having some problems and I think its forge related because when I used an older version of Forge it worked without error. This is my problem: ib9k3r.png That white block never came up before, but now every chair I sit on it comes up with this. Note: this works fine in SSP, the problem is only in SMP! Please could somebody offer some help? these are the codes I'm using:

 

Mod file code SSP/SMP:

MinecraftForge.registerEntity(EntityMountableBlock.class, mod_JammyFurniture.instance, 5, 5, 160, true);

 

BlockMountable.java in SSP/SMP

package net.minecraft.src.JAMMY780.util;

import java.util.List;

import net.minecraft.src.AxisAlignedBB;
import net.minecraft.src.Block;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.Material;
import net.minecraft.src.World;

/*ITOS: MP client version.
*This class is for your convenience. It is not necessary for your block to be a subclass of this class. 
*As long as your block has and/or calls the methods specified here it can use the EntityMountableBlock 
*class. If your class is a subclass to this class you don't have to do anything to be able to mount it, 
*just make sure that the blockActivated methods are not overridden.
*/

public class BlockMountable extends Block
{

//This constructor just pass thing on.
public BlockMountable(int x, Material material)
{
	super(x, material);
}

//This constructor just pass thing on.
public BlockMountable(int x, int y, Material material)
{
	super(x, y, material);
}

//This method use the main blockActivated with the default mounting position.
public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
    {
	return blockActivated(world, i, j, k, entityplayer, 0.5F, 1.0F, 0.5F, 0, 0, 0, 0);
    }

//This method use the main blockActivated with a custom mounting height.
public static boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, float y)
    {
	return blockActivated(world, i, j, k, entityplayer, 0.5F, y, 0.5F, 0, 0, 0, 0);
    }
    
//This is the main blockActivated method that specifies what happens when a player interact with the block.
public static boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, float x, float y, float z, int north, int south, int east, int west)
    {
	if (!world.isRemote)
	{
		//Looks for EMBs up to 1 block away from the activated block. Hopefully you didn't set the mounting position further away than this.
		List<EntityMountableBlock> list = world.getEntitiesWithinAABB(EntityMountableBlock.class, AxisAlignedBB.getBoundingBoxFromPool(i, j, k, i + 1.0D, j + 1.0D, k + 1.0D).expand(1D, 1D, 1D));
    	for (EntityMountableBlock entitytocheck : list)
    	{
    		//Looks for an EMB created by this block.
    		if (entitytocheck.orgBlockPosX == i && entitytocheck.orgBlockPosY == j && entitytocheck.orgBlockPosZ == k)
    		{
    			//Player wants to get off the block.
    			if (entitytocheck.riddenByEntity == entityplayer)
    			{
    				entitytocheck.interact(entityplayer);
    				return true;
    			}
    			//EMB is used by someone else.
    			if (entitytocheck.riddenByEntity != entityplayer && entitytocheck.riddenByEntity != null)
    			{
    				return true;
    			}
    			//EMB exist but no-one is sitting on it (bug).
    			entitytocheck.setDead();
    			break;
    		}
    	}
		//Sets coordinates for mounting a north oriented block.
		float mountingX = i + x;
		float mountingY = j + y;
		float mountingZ = k + z;
		//Changes coordinates for mounting to compensate for none-north block orientation.
		if(north != south) 
		{
			int md = world.getBlockMetadata(i, j, k);
			if (md == east) 
			{
				mountingX = i + 1 - z; 
				mountingZ = k + x; 
			}
			else if (md == south) 
			{
				mountingX = i + 1 - x; 
				mountingZ = k + 1 - z; 
			}
			else if (md == west) 
			{
				mountingX = i + z; 
				mountingZ = k + 1 - x; 
			}
		}
    	//Creates a new EMB if none had been created already or if the old one was bugged.
    	EntityMountableBlock nemb = new EntityMountableBlock(world, entityplayer, i, j, k, mountingX, mountingY, mountingZ);
    	world.spawnEntityInWorld(nemb);
    	nemb.interact(entityplayer);
    	return true;
	}
	return true;
    }

}

 

EntityMountableBlock.java - SSP

package net.minecraft.src.JAMMY780.util;

import net.minecraft.src.Entity;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.Profiler;
import net.minecraft.src.World;
import net.minecraft.src.forge.IEntityInteractHandler;

/*ITOS: MP client version.
*This class acts as a bridge between the mountable block and the player.
*This entity is what the player actually mounts instead of the block.
*An entity of this class is created by the mountable block upon activation
*and is killed when it's no longer used.
*/

public class EntityMountableBlock extends Entity
{

//These variables keep track of the block that created the entity. A bit backwards, I know.
public int orgBlockPosX;
public int orgBlockPosY;
public int orgBlockPosZ;
public int orgBlockID;

public EntityMountableBlock (World world)
{
	super(world);
}

//This constructor seems to be required by ModLoaderMp.
public EntityMountableBlock (World world, double d, double d1, double d2)
{
        super(world);
        noClip = true;
        preventEntitySpawning = true;
        width = 0.0F;
        height = 0.0F;
        setPosition(d, d1, d2);
}

//This constructor is called by the mountable block.
public EntityMountableBlock (World world, EntityPlayer entityplayer, int i, int j, int k, float mountingX, float mountingY, float mountingZ)
{
	super(world);
        noClip = true;
        preventEntitySpawning = true;
        width = 0.0F;
        height = 0.0F;
        
    	orgBlockPosX = i;
    	orgBlockPosY = j;
    	orgBlockPosZ = k;
    	orgBlockID = world.getBlockId(i, j, k);
    	
        setPosition(mountingX, mountingY, mountingZ);
}

//This method handles mounting and dismounting.
    public boolean interact(EntityPlayer entityplayer)
    {
        if (!super.interact(entityplayer))
        {
            if (!worldObj.isRemote && (riddenByEntity == null || riddenByEntity == entityplayer))
            {
                entityplayer.mountEntity(this);
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return true;
        }
    }
    
//The following methods are for most parts redundant, simplified versions of those in Entity but they also delete unused EMBs.
public void onUpdate()
{
	onEntityUpdate();
}

    public void onEntityUpdate()
    {
        Profiler.startSection("entityBaseTick");
        if(riddenByEntity == null || riddenByEntity.isDead)
        {
		setDead();
        }
        else if(worldObj.getBlockId(orgBlockPosX, orgBlockPosY, orgBlockPosZ) != orgBlockID)
	{
        	interact((EntityPlayer) riddenByEntity);
	}
        ticksExisted++;
        Profiler.endSection();
    }
    
    //The following methods are required by the Entity class but I don't know what they are for.
    public void entityInit() {}
    
    public void readEntityFromNBT(NBTTagCompound nbttagcompound) {}

    public void writeEntityToNBT(NBTTagCompound nbttagcompound) {}
}

 

EntityMountableBlock.java - SMP

package net.minecraft.src.JAMMY780.util;

import net.minecraft.src.Entity;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.EntityPlayerMP;
import net.minecraft.src.ModLoader;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.Packet39AttachEntity;
import net.minecraft.src.Profiler;
import net.minecraft.src.World;
import net.minecraft.src.forge.IEntityInteractHandler;

/*ITOS: MP server version.
*This class acts as a bridge between the mountable block and the player.
*This entity is what the player actually mounts instead of the block.
*An entity of this class is created by the mountable block upon activation
*and is killed when it's no longer used.
*/

public class EntityMountableBlock extends Entity
{

//These variables keep track of the block that created the entity. A bit backwards, I know.
public int orgBlockPosX;
public int orgBlockPosY;
public int orgBlockPosZ;
public int orgBlockID;

public EntityMountableBlock (World world)
{
	super(world);
}

//This constructor seems to be required by ModLoaderMp.
public EntityMountableBlock (World world, double d, double d1, double d2)
{
        super(world);
        noClip = true;
        preventEntitySpawning = true;
        width = 0.0F;
        height = 0.0F;
        setPosition(d, d1, d2);
}

//This constructor is called by the mountable block.
public EntityMountableBlock (World world, EntityPlayer entityplayer, int i, int j, int k, float mountingX, float mountingY, float mountingZ)
{
	super(world);
        noClip = true;
        preventEntitySpawning = true;
        width = 0.0F;
        height = 0.0F;
        
    	orgBlockPosX = i;
    	orgBlockPosY = j;
    	orgBlockPosZ = k;
    	orgBlockID = world.getBlockId(i, j, k);
    	
        setPosition(mountingX, mountingY, mountingZ);
}

//This method handles mounting and dismounting.
    public boolean interact(EntityPlayer entityplayer)
    {
        if (!super.interact(entityplayer))
        {
            if (!worldObj.isRemote && (riddenByEntity == null || riddenByEntity == entityplayer))
            {
                entityplayer.mountEntity(this);
                Packet39AttachEntity packet = new Packet39AttachEntity(entityplayer, this);
                for(Object entity : ModLoader.getMinecraftServerInstance().configManager.playerEntities)
                {
                	EntityPlayerMP player = (EntityPlayerMP)entity;
                	if(entityplayer.entityId == player.entityId)
                		continue;
                	player.playerNetServerHandler.sendPacket(packet);
                }
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return true;
        }
    }
    
//The following methods are for most parts redundant, simplified versions of those in Entity but they also delete unused EMBs.
public void onUpdate()
{
	onEntityUpdate();
}

    public void onEntityUpdate()
    {
        Profiler.startSection("entityBaseTick");
        if(riddenByEntity == null || riddenByEntity.isDead)
        {
		setDead();
        }
        else if(worldObj.getBlockId(orgBlockPosX, orgBlockPosY, orgBlockPosZ) != orgBlockID)
	{
		interact((EntityPlayer) riddenByEntity);
	}
        ticksExisted++;
        Profiler.endSection();
    }
    
    //The following methods are required by the Entity class but I don't know what they are for.
    public void entityInit() {}
    
public void readEntityFromNBT(NBTTagCompound nbttagcompound) {}

public void writeEntityToNBT(NBTTagCompound nbttagcompound) {}

}

 

BlockActivated from both of my chairs - SSP/SMP

public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
    {
    	int l = world.getBlockMetadata(i, j, k);
    	if(entityplayer.getCurrentEquippedItem() != null && entityplayer.getCurrentEquippedItem().getItem() instanceof ItemSign)
    	{
    		return false;
    	} 
    	else 
    	{
    		l %= 4;
            if(l == 0)
            {
                entityplayer.rotationYaw = 180F;
            }
            if(l == 1)
            {
                entityplayer.rotationYaw = -90F;
            }
            if(l == 2)
            {
                entityplayer.rotationYaw = 0F;
            }
            if(l == 3)
            {
                entityplayer.rotationYaw = 90F;
            }
    		float x = 0, y = 0, z = 0;
    		if(l == 0)
    		{
    			x = 0.5F;
    			y = 0.5F;
    			z = 0.5F;
    		}
    		if(l == 1)
    		{
    			x = 0.5F;
    			y = 0.5F;
    			z = 0.5F;
    		}
    		if(l == 2)
    		{
    			x = 0.5F;
    			y = 0.5F;
    			z = 0.5F;
    		}
    		if(l == 3)
    		{
    			x = 0.5F;
    			y = 0.5F;
    			z = 0.5F;
    		}
    		return BlockMountable.blockActivated(world, i, j, k, entityplayer, x, y, z, 0, 2, 1, 3);
    	}
    }

Link to comment
Share on other sites

Interesting, this seems to be similiar to this: http://imgur.com/5yS6K,GYMbq#1

Which is caused by someone using FML.

Best guess is its trying to render the player's bounding box.

Perhaps try debugging and see what is rendering that rectangle.

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

Link to comment
Share on other sites

Thank you for your help so far but I have no idea where I'd start to debug it, maybe I'm thinking about it wrong but nothing I seem to do changes the white column. It's really annoying :( Anymore ideas what might be causing it? I've tried adding a render file but it still shows up.

Link to comment
Share on other sites

So I need to make a blank render file? Like I would for a normal entity just don't include anything to actually render anything?

 

i don't think you use a blank render file, i do think there need to be a few things in there. maybe a call to do the actual render of the the entity.

 

Also may i ask is your entity an entity like a mob that just doesn't move or is it a TileEntity because if it is a tileEntity this might help

http://www.minecraftforum.net/topic/1154044-12520412-duckys-modding-tutorials-make-your-blocks-nice-now-with-cables-api/page__hl__render

 

 

Link to comment
Share on other sites

I'VE FIXED IT!! WOOHOOOOOOO! HOWEVER it does mean I have to use a modified version of Forge now :(. It seems to be the changes in this build: http://lexmanos.no-ip.org:8080/job/Forge/83/changes#detail0 I copied an older build of the code (build 72 and the two files were PacketEntitySpawn.java and PacketHandlerClient.java) all I had to do was fix a couple of problems (extend PacketHandlerBase, add unimplemented methods and change one bit of code (check below)) and it works like a charm now. Not sure why this problem happens, could a forge god explain why please? :D

 

change:

                if (networkmod.toString().equals(entry.getValue()))
                {
                    ForgeHooks.networkMods.put(entry.getKey(), networkmod);
                }

 

to:

                if (networkmod.toString().equals(entry.getValue()))
                {
                    ForgeHooks.networkMods.put((Integer) entry.getKey(), networkmod);
                }

Link to comment
Share on other sites

I haven't been bothering to look at this, whats the issue and why are you using a old version?

The revisions you mentioned would have nothing to do with your rendering if you did things properly.

As for that typecast, that does nothing, as that type is already a Integer.

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

Link to comment
Share on other sites

This issue only happened in SMP. I would sit down but be in a position like in the image in the main post. It only happens after I updated from build 72. I'm not using the whole old version, I'm only using two files from build 72. I'm not actually supposed to render anything, it only happens when I sit down which is supposed to be an invisible entity for the player to sit down on.

Link to comment
Share on other sites

You ALWAYS rendering SOMETHING for every entity.

And really the only functional change in 72 was to use the (World) constructor instead of the (World, double, double, double) one.

So I dont think thats the actual issue.

Move the crap you do in the double ctr into the world ctr.

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

Link to comment
Share on other sites

You ALWAYS rendering SOMETHING for every entity.

And really the only functional change in 72 was to use the (World) constructor instead of the (World, double, double, double) one.

So I dont think thats the actual issue.

Move the crap you do in the double ctr into the world ctr.

 

I'm sure I did that already! :) it worked, thank you so much! :)

Link to comment
Share on other sites

How come you don't add this code saves you importing every class file you need :) though I would post and try and be a tiny bit helpful xD

 

import net.minecraft.src.*;

I am pretty sure it is possible

 

Most IDE's will auto bring in the specific things you need, which is indeed better as it (barely) reduces linking and JIT time for that file.

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



×
×
  • Create New...

Important Information

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