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: 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);
}
}