Jump to content

Recommended Posts

Posted

So I have a problem, becuase I'm trying to save my entity reference to my Item NBT, so I can move my Entity with my Item, but I think that code says everything:

 

EntityArrow arrow = new EntityArrow(world);
world.spawnEntityInWorld(arrow);
System.out.println(world.getEntityByID(arrow.getEntityId()) == arrow);

 

It returns false

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

There is actually difference between entityId and UUID.

 

entityID is an integer assigned to entity spawned in world - this ID is shared between client and server logical sides and is used mostly in synchronization processes. entityId is generated once per one-time-world-join and is NOT persistent.

 

entityUniqueId is the UUID of entity - generated once per entity existance, saved to world and loaded on entity load. It is persistent.

Edit: Note that UUID is NOT valid on client side - only server has "real" uuid that is persistent. Client generates fakes.

 

You need to use second one if you want persistence.

1.7.10 is no longer supported by forge, you are on your own.

Posted

EntityArrow arrow = new EntityArrow(world);
world.spawnEntityInWorld(arrow);
System.out.println(world.getEntityByID(arrow.getEntityId()) == arrow);

 

you said it should work just fine, but I put this code into my update method, but it return null as I said

 

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

So I will show you anything what is necessary:

 

I want to remove that Entity entity.

 


Entity entity;

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
	if(!world.isRemote){
		if(entity == null){
			takeBlock(world, player,  pos, hitX, hitY, hitZ, 3);
		}else{
			placeBlock(world, stack);
		}
	}else{

	}
	return true;

}

public void takeBlock(World world, EntityPlayer player, BlockPos pos, float hitX, float hitY, float hitZ, int id){
	EntityNotFallingBlock nfb = new EntityNotFallingBlock(world, hitX, hitY, hitZ, world.getBlockState(pos));
	nfb.theBlock = world.getBlockState(pos);
	world.spawnEntityInWorld(nfb);
	ItemStack stack = player.getCurrentEquippedItem();
	NBTTagCompound nbt = stack.getTagCompound();
	if(world.getBlockState(pos).getBlock().hasTileEntity(world.getBlockState(pos))){
		TileEntity tile = world.getTileEntity(pos);
		NBTTagCompound tileData = new NBTTagCompound();
		tile.writeToNBT(tileData);
		nbt.setTag("NBTBlock", tileData);
		nfb.tileEntityData = tileData;
	}
	nbt.setInteger("ID", Block.getIdFromBlock(world.getBlockState(pos).getBlock()));
	nbt.setBoolean("IsBlock", true);
	nbt.setString("EntityIDClient", nfb.getUniqueID().toString());
	nbt.setInteger("EntityIDServer", nfb.getEntityId());
	Block block = nfb.fallTile != null ? nfb.fallTile.getBlock() : Blocks.air;
	ResourceLocation resourcelocation = (ResourceLocation)Block.blockRegistry.getNameForObject(block);
	nbt.setString("Block", resourcelocation == null ? "" : resourcelocation.toString());
	nbt.setByte("Data", (byte)block.getMetaFromState(nfb.fallTile));

	if (nfb.tileEntityData != null)
	{
		nbt.setTag("TileEntityData", nfb.tileEntityData);
	}
	entity = nfb;
	world.setBlockToAir(pos);
}

public void placeBlock(World world, ItemStack stack){
	if(entity instanceof EntityNotFallingBlock){
		if(world.getBlockState(new BlockPos(entity)).getBlock() == Blocks.air){
			world.setBlockState(new BlockPos(entity), ((EntityNotFallingBlock) entity).getBlock());
			if(world.getBlockState(new BlockPos(entity)).getBlock().hasTileEntity((world.getBlockState(new BlockPos(entity))))){
				world.getTileEntity(new BlockPos(entity)).readFromNBT((NBTTagCompound) stack.getTagCompound().getTag("NBTBlock"));
			}
			stack.getTagCompound().setInteger("ID", -1);
			stack.getTagCompound().setBoolean("IsBlock", false);
			entity.setDead();
			entity = null;
		}
	}
}

@Override
public void onUpdate(ItemStack stack, World world, Entity player, int itemSlot, boolean isSelected) {
	if(!stack.hasTagCompound()){
		stack.setTagCompound(new NBTTagCompound());
	}
	NBTTagCompound nbt = stack.getTagCompound();
	if(player instanceof EntityPlayer){
		if(isSelected){
			if(world.isRemote){
				IBlockState fallTile;
				int i = nbt.getByte("Data") & 255;
				if (nbt.hasKey("Block", ){
					fallTile = Block.getBlockFromName(nbt.getString("Block")).getStateFromMeta(i);
				}
				else if (nbt.hasKey("TileID", 99)){
					fallTile = Block.getBlockById(nbt.getInteger("TileID")).getStateFromMeta(i);
				}
				else{
					fallTile = Block.getBlockById(nbt.getByte("Tile") & 255).getStateFromMeta(i);
				}
				if(entity == null){
					if(nbt.getInteger("ID") != -1){
						EntityNotFallingBlock nfb = new EntityNotFallingBlock(world, player.posX, player.posY, player.posZ, fallTile);
						entity = nfb;
						world.spawnEntityInWorld(nfb);
					}
				}else{
					if(nbt.getInteger("ID") == -1){
						entity.setDead();
						entity = null;
					}else{
						if(entity instanceof EntityNotFallingBlock){
							if(!((EntityNotFallingBlock) entity).isRendered){
								entity.setDead();
								EntityNotFallingBlock nfb = new EntityNotFallingBlock(world, player.posX, player.posY, player.posZ, fallTile);
								entity = nfb;
								world.spawnEntityInWorld(nfb);
							}
						}
					}
				}
			}
			if(entity != null){
				boolean flag = true;
				if(entity instanceof EntityNotFallingBlock){
					if(((EntityNotFallingBlock) entity).theBlock == null){
						((EntityNotFallingBlock) entity).theBlock = ((EntityNotFallingBlock) entity).getBlock();
					}
				}
				if(flag){
					int far = 5;
					if(player.rayTrace(far, 1) != null){
						if(player.rayTrace(far, 1).hitVec != null){
							MovingObjectPosition mop = player.rayTrace(far, 1);
							Vec3 hit = mop.hitVec;
							int side = mop.sideHit.getIndex();	
							switch(side){
							case 0:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord - 1, (int)hit.zCoord - 0.5);
								break;
							case 1:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord, (int)hit.zCoord - 0.5);
								break;
							case 2:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord, (int)hit.zCoord - 0.5);
								break;
							case 3:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord, (int)hit.zCoord + 0.5);
								break;
							case 4:
								entity.setPositionAndUpdate((int)hit.xCoord - 0.5, (int)hit.yCoord, (int)hit.zCoord - 0.5);
								break;
							case 5:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord, (int)hit.zCoord - 0.5);
								break;
							}
						}
					}
				}
			}
		}else{
			if(nbt.getInteger("ID") != -1){
				if(nbt.getBoolean("IsBlock")){
					Entity entity;

// This is what I tried, but it doen't work
					if(!world.isRemote){
						entity = world.getEntityByID(nbt.getInteger("EntityIDServer"));
					}else{
						entity = findTheCorrectEntity(world, nbt.getString("EntityIDClient"));
					}
					if(entity != null){
						System.out.println(FMLCommonHandler.instance().getEffectiveSide());
						EntityBlock efb = new EntityBlock(world, entity.posX, entity.posY, entity.posZ, ((EntityNotFallingBlock) entity).theBlock);
						world.spawnEntityInWorld(efb);
						stack.getTagCompound().setInteger("ID", -1);
						entity.setDead();
						entity = null;
						nbt.setBoolean("IsBlock", false);
					}else{
						System.out.println("Entity is null on" + FMLCommonHandler.instance().getEffectiveSide());
					}
				}
			}
		}
	}
}

public Entity findTheCorrectEntity(World world, UUID theFinding){
	Entity entity = null;
	for(int i = 0; i < world.getLoadedEntityList().size(); i++){
		if(world.getLoadedEntityList().get(i) instanceof Entity){
			Entity entity2 = (Entity) world.getLoadedEntityList().get(i);
			if(entity2.getUniqueID() == theFinding){
				entity = entity2;
			}
		}
	}
	return entity;
}

public Entity findTheCorrectEntity(World world, String theFinding){
	Entity entity = null;
	for(int i = 0; i < world.getLoadedEntityList().size(); i++){
		if(world.getLoadedEntityList().get(i) instanceof Entity){
			Entity entity2 = (Entity) world.getLoadedEntityList().get(i);
			if(entity2.getUniqueID().toString() == theFinding){
				entity = entity2;
			}
		}
	}
	return entity;
}

 

 

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

Ok ok, I will explain you:

 

My iteem can take up Blocks, and put them back on the ground again

 

Used to check if it should place or take the block

 

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
	if(!world.isRemote){
		if(entity == null){
			takeBlock(world, player,  pos, hitX, hitY, hitZ, 3);
		}else{
			placeBlock(world, stack);
		}
	}else{

	}
	return true;

}

 

Used to take Blocks

 

public void takeBlock(World world, EntityPlayer player, BlockPos pos, float hitX, float hitY, float hitZ, int id){
	EntityNotFallingBlock nfb = new EntityNotFallingBlock(world, hitX, hitY, hitZ, world.getBlockState(pos));
	nfb.theBlock = world.getBlockState(pos);
	world.spawnEntityInWorld(nfb);
	ItemStack stack = player.getCurrentEquippedItem();
	NBTTagCompound nbt = stack.getTagCompound();

	//Check if Block is chest or something like that

	if(world.getBlockState(pos).getBlock().hasTileEntity(world.getBlockState(pos))){
		TileEntity tile = world.getTileEntity(pos);
		NBTTagCompound tileData = new NBTTagCompound();
		tile.writeToNBT(tileData);
		nbt.setTag("NBTBlock", tileData);
		nfb.tileEntityData = tileData;
	}

	//Sets some stuff to nbt item, so It knows what Id block has

	nbt.setInteger("ID", Block.getIdFromBlock(world.getBlockState(pos).getBlock()));
	nbt.setBoolean("IsBlock", true);
	nbt.setString("EntityIDClient", nfb.getUniqueID().toString());
	nbt.setInteger("EntityIDServer", nfb.getEntityId());

	//Just copy of vanilla code, to save things like diorite

	Block block = nfb.fallTile != null ? nfb.fallTile.getBlock() : Blocks.air;
	ResourceLocation resourcelocation = (ResourceLocation)Block.blockRegistry.getNameForObject(block);
	nbt.setString("Block", resourcelocation == null ? "" : resourcelocation.toString());
	nbt.setByte("Data", (byte)block.getMetaFromState(nfb.fallTile));

	if (nfb.tileEntityData != null)
	{
		nbt.setTag("TileEntityData", nfb.tileEntityData);
	}
	entity = nfb;

	//makes block disapear

	world.setBlockToAir(pos);
}

 

Used to put Blocks back in world

 

public void placeBlock(World world, ItemStack stack){

	//Checks if the entity is my enityNotFallingBlock, which is just an Copy of the EntitiyFallingBlock, without falling
	//Used because I want to add the option, to pick up Zombies or so

	if(entity instanceof EntityNotFallingBlock){

		//Checks, that it cant replace chest or not full Blocks

		if(world.getBlockState(new BlockPos(entity)).getBlock() == Blocks.air){

			//Sets the Block with every the NBT if has

			world.setBlockState(new BlockPos(entity), ((EntityNotFallingBlock) entity).getBlock());
			if(world.getBlockState(new BlockPos(entity)).getBlock().hasTileEntity((world.getBlockState(new BlockPos(entity))))){
				world.getTileEntity(new BlockPos(entity)).readFromNBT((NBTTagCompound) stack.getTagCompound().getTag("NBTBlock"));
			}
			stack.getTagCompound().setInteger("ID", -1);
			stack.getTagCompound().setBoolean("IsBlock", false);
			entity.setDead();
			entity = null;
		}
	}
}

 

Used to moved the EntityBlock and some more stuff

 

@Override
public void onUpdate(ItemStack stack, World world, Entity player, int itemSlot, boolean isSelected) {
	if(!stack.hasTagCompound()){
		stack.setTagCompound(new NBTTagCompound());
	}
	NBTTagCompound nbt = stack.getTagCompound();
	if(player instanceof EntityPlayer){
		if(isSelected){
			if(world.isRemote){

				//Only creates an NotFallingblock for the client, because the server doesn't send the entity to client, probably worst way to do this

				//Just again a copy of vanilla code

				IBlockState fallTile;
				int i = nbt.getByte("Data") & 255;
				if (nbt.hasKey("Block", ){
					fallTile = Block.getBlockFromName(nbt.getString("Block")).getStateFromMeta(i);
				}
				else if (nbt.hasKey("TileID", 99)){
					fallTile = Block.getBlockById(nbt.getInteger("TileID")).getStateFromMeta(i);
				}
				else{
					fallTile = Block.getBlockById(nbt.getByte("Tile") & 255).getStateFromMeta(i);
				}
				if(entity == null){

					//creates the entity if not already there

					if(nbt.getInteger("ID") != -1){
						EntityNotFallingBlock nfb = new EntityNotFallingBlock(world, player.posX, player.posY, player.posZ, fallTile);
						entity = nfb;
						world.spawnEntityInWorld(nfb);
					}
				}else{
					if(nbt.getInteger("ID") == -1){

						//deletes the entity, if placed and client didn't realize

						entity.setDead();
						entity = null;
					}else{
						if(entity instanceof EntityNotFallingBlock){

							//creates the entity new if it despawned on client or client deleted it

							if(!((EntityNotFallingBlock) entity).isRendered){
								entity.setDead();
								EntityNotFallingBlock nfb = new EntityNotFallingBlock(world, player.posX, player.posY, player.posZ, fallTile);
								entity = nfb;
								world.spawnEntityInWorld(nfb);
							}
						}
					}
				}
			}
			if(entity != null){
				boolean flag = true;
				if(entity instanceof EntityNotFallingBlock){

					//sets a blockstate to the entity, if theres none

					if(((EntityNotFallingBlock) entity).theBlock == null){
						((EntityNotFallingBlock) entity).theBlock = ((EntityNotFallingBlock) entity).getBlock();
					}
				}
				if(flag){

					//the following code is used to clip the entity to the from the player looked at position

					int far = 5;
					if(player.rayTrace(far, 1) != null){
						if(player.rayTrace(far, 1).hitVec != null){
							MovingObjectPosition mop = player.rayTrace(far, 1);
							Vec3 hit = mop.hitVec;
							int side = mop.sideHit.getIndex();	
							switch(side){
							case 0:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord - 1, (int)hit.zCoord - 0.5);
								break;
							case 1:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord, (int)hit.zCoord - 0.5);
								break;
							case 2:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord, (int)hit.zCoord - 0.5);
								break;
							case 3:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord, (int)hit.zCoord + 0.5);
								break;
							case 4:
								entity.setPositionAndUpdate((int)hit.xCoord - 0.5, (int)hit.yCoord, (int)hit.zCoord - 0.5);
								break;
							case 5:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord, (int)hit.zCoord - 0.5);
								break;
							}
						}
					}
				}
			}
		}else{

			//used to drop the entity to ground if the player switched his hotbar, so the entity won't fly in the air

			if(nbt.getInteger("ID") != -1){
				if(nbt.getBoolean("IsBlock")){
					Entity entity;

					//this is used to get the entity, which should replaces the Entity entity above, but it doesn't work on both client and server

					if(!world.isRemote){
						entity = world.getEntityByID(nbt.getInteger("EntityIDServer"));
					}else{
						entity = findTheCorrectEntity(world, nbt.getString("EntityIDClient"));
					}
					if(entity != null){
						System.out.println(FMLCommonHandler.instance().getEffectiveSide());
						EntityBlock efb = new EntityBlock(world, entity.posX, entity.posY, entity.posZ, ((EntityNotFallingBlock) entity).theBlock);
						world.spawnEntityInWorld(efb);
						stack.getTagCompound().setInteger("ID", -1);
						entity.setDead();
						entity = null;
						nbt.setBoolean("IsBlock", false);
					}else{
						System.out.println("Entity is null on" + FMLCommonHandler.instance().getEffectiveSide());
					}
				}
			}
		}
	}
}

 

Should find the Entity in the world

 

public Entity findTheCorrectEntity(World world, UUID theFinding){
	Entity entity = null;
	for(int i = 0; i < world.getLoadedEntityList().size(); i++){
		if(world.getLoadedEntityList().get(i) instanceof Entity){
			Entity entity2 = (Entity) world.getLoadedEntityList().get(i);
			if(entity2.getUniqueID() == theFinding){
				entity = entity2;
			}
		}
	}
	return entity;
}

public Entity findTheCorrectEntity(World world, String theFinding){
	Entity entity = null;
	for(int i = 0; i < world.getLoadedEntityList().size(); i++){
		if(world.getLoadedEntityList().get(i) instanceof Entity){
			Entity entity2 = (Entity) world.getLoadedEntityList().get(i);
			if(entity2.getUniqueID().toString() == theFinding){
				entity = entity2;
			}
		}
	}
	return entity;
}

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

It draws a block, exactly like a falling sand, so you can see where you place your block, its necessary

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

Hm, I can find only world.getEntityByID(id), you may mix it up with world.getPlayerEntityByUUID(uuid)

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

has some problems, I tried this

 

public void takeBlock(World world, EntityPlayer player, BlockPos pos, float hitX, float hitY, float hitZ, int id){
	ItemStack stack = player.getCurrentEquippedItem();
	stack.setTagCompound(new NBTTagCompound());
	NBTTagCompound nbt = stack.getTagCompound();
	EntityNotFallingBlock nfb = new EntityNotFallingBlock(world, hitX, hitY, hitZ, world.getBlockState(pos));
	nfb.theBlock = world.getBlockState(pos);
	nbt.setString("EntityID", nfb.getPersistentID().toString());
	world.spawnEntityInWorld(nfb);
	WorldServer server = (WorldServer) world;
	System.out.println(server.getEntityFromUuid(UUID.fromString(nbt.getString("EntityID"))) == nfb);

 

That return true, which is good, but this:

 

Entity entity;

					//this is used to get the entity, which should replaces the Entity entity above, but it doesn't work on both client and server

					if(!world.isRemote){
						WorldServer serverWorld = (WorldServer) world;
						entity = serverWorld.getEntityFromUuid(UUID.fromString(nbt.getString("EntityID")));
						System.out.println(entity);
					}else{
						entity = findTheCorrectEntity(world, UUID.fromString(nbt.getString("EntityID")));
					}

 

It says the entity is null

 

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

So I removed that field now, It works just perfect on Server, but now I have to problem, becuase how should I get the Entity, that is only on Client

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

Hm thats a good question, I wont to have the entity also on server, so that other players can see it, but the problem is the entity is only added on server, so I have to extra add it it on the client, or is there a better way to do this?

 

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
	NBTTagCompound nbt = stack.getTagCompound();
	Entity entity = null;
	if(!world.isRemote){
		WorldServer serverWorld = (WorldServer) world;
		try{
			if(nbt.getString("EntityID") != ""){
				entity = serverWorld.getEntityFromUuid(UUID.fromString(nbt.getString("EntityID")));
			}
		}catch(Exception e){

		}
		if(entity == null){
			takeBlock(world, player,  pos, hitX, hitY, hitZ, 3);
		}else{
			placeBlock(world, stack);
		}
	}else{

	}
	return true;

}

public void takeBlock(World world, EntityPlayer player, BlockPos pos, float hitX, float hitY, float hitZ, int id){
	ItemStack stack = player.getCurrentEquippedItem();
	stack.setTagCompound(new NBTTagCompound());
	NBTTagCompound nbt = stack.getTagCompound();
	EntityNotFallingBlock nfb = new EntityNotFallingBlock(world, hitX, hitY, hitZ, world.getBlockState(pos));
	nfb.theBlock = world.getBlockState(pos);
	nbt.setString("EntityID", nfb.getPersistentID().toString());
	world.spawnEntityInWorld(nfb);
	WorldServer server = (WorldServer) world;

	//Check if Block is chest or something like that

	if(world.getBlockState(pos).getBlock().hasTileEntity(world.getBlockState(pos))){
		TileEntity tile = world.getTileEntity(pos);
		NBTTagCompound tileData = new NBTTagCompound();
		tile.writeToNBT(tileData);
		nbt.setTag("NBTBlock", tileData);
		nfb.tileEntityData = tileData;
	}

	//Sets some stuff to nbt item, so It knows what Id block has

	nbt.setInteger("ID", Block.getIdFromBlock(world.getBlockState(pos).getBlock()));
	nbt.setBoolean("IsBlock", true);

	nbt.setInteger("EntityIDC", nfb.getEntityId());

	//Just copy of vanilla code, to save things like diorite

	Block block = nfb.fallTile != null ? nfb.fallTile.getBlock() : Blocks.air;
	ResourceLocation resourcelocation = (ResourceLocation)Block.blockRegistry.getNameForObject(block);
	nbt.setString("Block", resourcelocation == null ? "" : resourcelocation.toString());
	nbt.setByte("Data", (byte)block.getMetaFromState(nfb.fallTile));

	if (nfb.tileEntityData != null)
	{
		nbt.setTag("TileEntityData", nfb.tileEntityData);
	}
	//		entity = nfb;

	//makes block disapear

	world.setBlockToAir(pos);

 

Thats the code to add the entity and take the block, but it gets only called on the server, any better way to do this?

 

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

	EntityRegistry.registerModEntity(EntityNotFallingBlock.class, modid + "EntityNOTFallingBlock", 0, this, 64, 20, true);

 

No properly?

 

The rest of the problem is in my Entity then, because it nearly never shows, and when for like 0.1 second, so it could be a problem in the class itself, or in the render, but the rendere is an exact copy of the vanilla renderer, exactly as the entity...

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

Also:

 

ItemStack stack = player.getCurrentEquippedItem();
	stack.setTagCompound(new NBTTagCompound());
	NBTTagCompound nbt = stack.getTagCompound();
	EntityNotFallingBlock nfb = new EntityNotFallingBlock(world, hitX, hitY, hitZ, world.getBlockState(pos));
	nfb.theBlock = world.getBlockState(pos);
	System.out.println(nfb.getUniqueID());
	world.spawnEntityInWorld(nfb);
	nbt.setString("EntityID", nfb.getUniqueID().toString());
	WorldServer server = (WorldServer) world;
	System.out.println(server.getEntityFromUuid(UUID.fromString(nbt.getString("EntityID"))) == nfb);

 

This return false

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

package de.intektor.moreminecraft.items;

import java.util.List;
import java.util.UUID;

import de.intektor.moreminecraft.MoreMinecraft;
import de.intektor.moreminecraft.entity.EntityBlock;
import de.intektor.moreminecraft.entity.EntityNotFallingBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockHalfStoneSlab;
import net.minecraft.block.BlockHalfStoneSlabNew;
import net.minecraft.block.BlockHalfWoodSlab;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.passive.EntityChicken;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.FMLCommonHandler;

public class BlockMover extends BasicItem{

public BlockMover() {
	super(1, "Block Mover", MoreMinecraft.moreMinecraftTab);
}

@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
	return stack;
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
	NBTTagCompound nbt = stack.getTagCompound();
	if(!world.isRemote){

		Entity entity = null;

		if(nbt.getString("EntityID") != ""){
			WorldServer server = (WorldServer) world;
			entity = server.getEntityFromUuid(UUID.fromString(nbt.getString("EntityID")));
		}
		if(!nbt.getBoolean("SomethingTaken")){
			takeBlock(world, player,  pos, hitX, hitY, hitZ, 3);
		}else{
			placeBlock(world, stack);
		}
	}
	return true;

}

public void takeBlock(World world, EntityPlayer player, BlockPos pos, float hitX, float hitY, float hitZ, int id){
	ItemStack stack = player.getCurrentEquippedItem();
	stack.setTagCompound(new NBTTagCompound());
	NBTTagCompound nbt = stack.getTagCompound();
	EntityNotFallingBlock nfb = new EntityNotFallingBlock(world, hitX, hitY, hitZ, world.getBlockState(pos));
	nfb.theBlock = world.getBlockState(pos);
	System.out.println(nfb.getUniqueID());
	world.spawnEntityInWorld(nfb);
	nbt.setString("EntityID", nfb.getUniqueID().toString());
	WorldServer server = (WorldServer) world;
	System.out.println(server.getEntityFromUuid(UUID.fromString(nbt.getString("EntityID"))) == nfb);
	//Check if Block is chest or something like that

	if(world.getBlockState(pos).getBlock().hasTileEntity(world.getBlockState(pos))){
		TileEntity tile = world.getTileEntity(pos);
		NBTTagCompound tileData = new NBTTagCompound();
		tile.writeToNBT(tileData);
		nbt.setTag("NBTBlock", tileData);
		nfb.tileEntityData = tileData;
	}

	//Sets some stuff to nbt item, so It knows what Id block has

	nbt.setInteger("ID", Block.getIdFromBlock(world.getBlockState(pos).getBlock()));
	nbt.setBoolean("IsBlock", true);
	nbt.setBoolean("SomethingTaken", true);
	nbt.setInteger("EntityIDC", nfb.getEntityId());

	//Just copy of vanilla code, to save things like diorite

	Block block = nfb.fallTile != null ? nfb.fallTile.getBlock() : Blocks.air;
	ResourceLocation resourcelocation = (ResourceLocation)Block.blockRegistry.getNameForObject(block);
	nbt.setString("Block", resourcelocation == null ? "" : resourcelocation.toString());
	nbt.setByte("Data", (byte)block.getMetaFromState(nfb.fallTile));

	if (nfb.tileEntityData != null)
	{
		nbt.setTag("TileEntityData", nfb.tileEntityData);
	}
	//		entity = nfb;

	//makes block disapear

	world.setBlockToAir(pos);
}

public void placeBlock(World world, ItemStack stack){

	//Checks if the entity is my enityNotFallingBlock, which is just an Copy of the EntitiyFallingBlock, without falling
	//Used because I want to add the option, to pick up Zombies or so
	if(!world.isRemote){
		Entity entity;
		WorldServer serverWorld = (WorldServer) world;
		entity = serverWorld.getEntityFromUuid(UUID.fromString(stack.getTagCompound().getString("EntityID")));
		if(entity instanceof EntityNotFallingBlock){

			//Checks, that it cant replace chest or not full Blocks

			//Sets the Block with every the NBT if has

			if(((EntityNotFallingBlock) entity).theBlock.getBlock() instanceof BlockHalfStoneSlab || ((EntityNotFallingBlock) entity).theBlock.getBlock() instanceof BlockHalfWoodSlab || ((EntityNotFallingBlock) entity).theBlock.getBlock() instanceof BlockSlab){
				BlockSlab slap = (BlockHalfStoneSlabNew) ((EntityNotFallingBlock) entity).theBlock.getBlock();
				if(stack.getTagCompound().getInteger("Half") != -1){
					if(stack.getTagCompound().getInteger("Half") == 1){
						world.setBlockState(new BlockPos(entity), ((EntityNotFallingBlock) entity).getBlock().withProperty(BlockSlab.HALF, BlockSlab.EnumBlockHalf.TOP));
						stack.getTagCompound().setInteger("ID", -1);
						stack.getTagCompound().setBoolean("IsBlock", false);
						entity.setDead();
						entity = null;
					}else{
						if(stack.getTagCompound().getBoolean("RootUp")){
							if(!stack.getTagCompound().getBoolean("OneUp")){
								world.setBlockState(new BlockPos(entity.posX, entity.posY + 1, entity.posZ), ((EntityNotFallingBlock) entity).getBlock().withProperty(BlockSlab.HALF, BlockSlab.EnumBlockHalf.BOTTOM));
							}else{
								world.setBlockState(new BlockPos(entity.posX, entity.posY, entity.posZ), ((EntityNotFallingBlock) entity).getBlock().withProperty(BlockSlab.HALF, BlockSlab.EnumBlockHalf.TOP));
							}
							stack.getTagCompound().setInteger("ID", -1);
							stack.getTagCompound().setBoolean("IsBlock", false);
							entity.setDead();
							entity = null;
						}else{
							if(!stack.getTagCompound().getBoolean("OneUp")){
								world.setBlockState(new BlockPos(entity), ((EntityNotFallingBlock) entity).getBlock().withProperty(BlockSlab.HALF, BlockSlab.EnumBlockHalf.BOTTOM));
							}else{
								world.setBlockState(new BlockPos(entity.posX, entity.posY, entity.posZ), ((EntityNotFallingBlock) entity).getBlock().withProperty(BlockSlab.HALF, BlockSlab.EnumBlockHalf.TOP));
							}
							stack.getTagCompound().setInteger("ID", -1);
							stack.getTagCompound().setBoolean("IsBlock", false);
							entity.setDead();
							entity = null;
						}
					}
				}
			}else{
				if(world.getBlockState(new BlockPos(entity.posX, entity.posY, entity.posZ)).getBlock() == Blocks.air){
					world.setBlockState(new BlockPos(entity), ((EntityNotFallingBlock) entity).getBlock());
					if(world.getBlockState(new BlockPos(entity)).getBlock().hasTileEntity((world.getBlockState(new BlockPos(entity))))){
						NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound().getTag("NBTBlock");
						nbt.setInteger("x", new BlockPos(entity).getX());
						nbt.setInteger("y", new BlockPos(entity).getY());
						nbt.setInteger("z", new BlockPos(entity).getZ());
						world.getTileEntity(new BlockPos(entity)).readFromNBT((NBTTagCompound) stack.getTagCompound().getTag("NBTBlock"));
					}
					stack.getTagCompound().setInteger("ID", -1);
					stack.getTagCompound().setBoolean("IsBlock", false);
					entity.setDead();
					entity = null;
				}
			}
		}
		stack.setTagCompound(new NBTTagCompound());
	}
}



@Override
public void onUpdate(ItemStack stack, World world, Entity player, int itemSlot, boolean isSelected) {
	if(!stack.hasTagCompound()){
		stack.setTagCompound(new NBTTagCompound());
	}
	NBTTagCompound nbt = stack.getTagCompound();
	if(player instanceof EntityPlayer){
		if(isSelected){
			Entity entity = findTheCorrectEntity(world, nbt.getString("EntityID"));
			if(world.isRemote){
				//
				//					//Only} creates an NotFallingblock for the client, because the server doesn't send the entity to client, probably worst way to do this
				//
				//					//Just again a copy of vanilla code
				//
				//					IBlockState fallTile;
				//					int i = nbt.getByte("Data") & 255;
				//					if (nbt.hasKey("Block", ){
				//						fallTile = Block.getBlockFromName(nbt.getString("Block")).getStateFromMeta(i);
				//					}
				//					else if (nbt.hasKey("TileID", 99)){
				//						fallTile = Block.getBlockById(nbt.getInteger("TileID")).getStateFromMeta(i);
				//					}
				//					else{
				//						fallTile = Block.getBlockById(nbt.getByte("Tile") & 255).getStateFromMeta(i);
				//					}
				//					if(entity == null){
				//
				//						//creates the entity if not already there
				//						
				//						if(nbt.getInteger("ID") != -1){
				//							EntityNotFallingBlock nfb = new EntityNotFallingBlock(world, player.posX, player.posY, player.posZ, fallTile);
				//							entity = nfb;
				//							world.loadedEntityList.set(nbt.getInteger("EntityIDC"), nfb);
				//							nbt.setInteger("EntityIDC", nfb.getEntityId());
				//						}
				//					}else{
				//						if(nbt.getInteger("ID") == -1){
				//
				//							//deletes the entity, if placed and client didn't realize
				//
				//							entity.setDead();
				//							entity = null;
				//						}else{
				//							if(entity instanceof EntityNotFallingBlock){
				//
				//								//creates the entity new if it despawned on client or client deleted it
				//
				//								if(!((EntityNotFallingBlock) entity).isRendered){
				//									entity.setDead();
				//									EntityNotFallingBlock nfb = new EntityNotFallingBlock(world, player.posX, player.posY, player.posZ, fallTile);
				//									entity = nfb;
				//									world.spawnEntityInWorld(nfb);
				//								}
				//							}
				//						}
				//					}
			}else{
				if(nbt.getString("EntityID") != ""){
					WorldServer server = (WorldServer) world;
					entity = server.getEntityFromUuid(UUID.fromString(nbt.getString("EntityID")));
				}
			}
			if(entity != null){
				boolean flag = true;
				boolean halfStep = false;
				boolean rootUp = false;
				if(entity instanceof EntityNotFallingBlock){

					//sets a blockstate to the entity, if theres none

					if(((EntityNotFallingBlock) entity).theBlock == null){
						((EntityNotFallingBlock) entity).theBlock = ((EntityNotFallingBlock) entity).getBlock();
					}
					if(((EntityNotFallingBlock) entity).theBlock.getBlock() instanceof BlockHalfStoneSlab || ((EntityNotFallingBlock) entity).theBlock.getBlock() instanceof BlockHalfWoodSlab || ((EntityNotFallingBlock) entity).theBlock.getBlock() instanceof BlockSlab){
						halfStep = true;
						if(((EntityNotFallingBlock) entity).theBlock.getProperties().containsValue(BlockSlab.EnumBlockHalf.TOP)){
							nbt.setBoolean("RootUp", true);
							rootUp = true;
						}
					}else{
						nbt.setInteger("Half", -1);
					}
				}
				if(flag){

					//the following code is used to clip the entity to the from the player looked at position

					int far = 5;
					if(player.rayTrace(far, 1) != null){
						if(player.rayTrace(far, 1).hitVec != null){
							MovingObjectPosition mop = player.rayTrace(far, 1);
							Vec3 hit = mop.hitVec;
							int side = mop.sideHit.getIndex();	
							double yplus = 0;
							if(halfStep){
								if(mop.hitVec.yCoord - Math.floor(mop.hitVec.yCoord) > 0.5){
									if(!rootUp){
										yplus = 0.5;
									}else{

									}
									nbt.setInteger("Half", 1);
								}else{
									if(rootUp){
										yplus = -0.5;
									}
									nbt.setInteger("Half", 0);
								}
							}
							switch(side){
							case 0:
								if(!rootUp){
									nbt.setBoolean("OneUp", true);;
									nbt.setDouble("Up", 0.5);
									yplus = 0.5;
								}else{
									nbt.setBoolean("OneUp", true);;
									nbt.setDouble("Up", -0.5);
									yplus = 0;
								}
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord - 1 + yplus, (int)hit.zCoord - 0.5);
								break;
							case 1:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord + yplus, (int)hit.zCoord - 0.5);
								break;
							case 2:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord + yplus, (int)hit.zCoord - 0.5);
								break;
							case 3:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord + yplus, (int)hit.zCoord + 0.5);
								break;
							case 4:
								entity.setPositionAndUpdate((int)hit.xCoord - 0.5, (int)hit.yCoord + yplus, (int)hit.zCoord - 0.5);
								break;
							case 5:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord + yplus, (int)hit.zCoord - 0.5);
								break;
							}
						}
					}
				}
			}
		}else{

			//used to drop the entity to ground if the player switched his hotbar, so the entity won't fly in the air

			if(nbt.getInteger("ID") != -1){
				if(nbt.getBoolean("IsBlock")){
					Entity entity;

					//this is used to get the entity, which should replaces the Entity entity above, but it doesn't work on both client and server
					if(nbt.getString("EntityID") != ""){
						if(!world.isRemote){
							WorldServer serverWorld = (WorldServer) world;
							entity = serverWorld.getEntityFromUuid(UUID.fromString(nbt.getString("EntityID")));
						}else{
							WorldClient clientWorld = (WorldClient) world;
							entity = findTheCorrectEntity(world, UUID.fromString(nbt.getString("EntityID")));
						}
						if(entity != null){
							System.out.println(FMLCommonHandler.instance().getEffectiveSide());
							EntityBlock efb = new EntityBlock(world, entity.posX, entity.posY, entity.posZ, ((EntityNotFallingBlock) entity).theBlock);
							world.spawnEntityInWorld(efb);
							stack.getTagCompound().setInteger("ID", -1);
							entity.setDead();
							entity = null;
							nbt.setBoolean("IsBlock", false);
						}
					}
				}
			}
		}
	}
}

public Entity findTheCorrectEntity(World world, UUID uuid){
	Entity entity = null;
	for (int i = 0; i < world.loadedEntityList.size(); ++i)
	{
		Entity entityplayer = (Entity)world.loadedEntityList.get(i);

		if (uuid.equals(entityplayer.getUniqueID()))
		{
			return entityplayer;
		}
	}

	return null;
}

public Entity findTheCorrectEntity(World world, String theFinding){
	Entity entity = null;
	for(int i = 0; i < world.getLoadedEntityList().size(); i++){
		if(world.getLoadedEntityList().get(i) instanceof Entity){
			Entity entity2 = (Entity) world.getLoadedEntityList().get(i);
			if(entity2.getUniqueID().toString().equals(theFinding)){
				entity = entity2;
			}
		}
	}
	return entity;
}

@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List tooltip, boolean advanced) {
	if(stack.hasTagCompound()){
		tooltip.add("Block ID: " + stack.getTagCompound().getInteger("ID") + "");
		tooltip.add("EntityUUID: " + stack.getTagCompound().getString("EntityID"));
		tooltip.add("Client Entity ID: " + stack.getTagCompound().getInteger("EntityIDC"));
	}
}
}

 

Some things chanced from last time, but the main things are the same, so some things are no langer correctly described, but it should still be readable

 

Entity Code

 

package de.intektor.moreminecraft.entity;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class EntityNotFallingBlock extends Entity{

public IBlockState fallTile;
public IBlockState theBlock;
public static IBlockState lastState;
private boolean allowFall = false;
public boolean isRendered;
public NBTTagCompound tileEntityData;

public EntityNotFallingBlock(World worldIn) {
	super(worldIn);
	fallTile = lastState;
	kill();
}

public EntityNotFallingBlock(World world, double posX, double posY, double posZ, IBlockState fallingBlockState) {
	super(world);
	this.posX = posX;
	this.posY = posY;
	this.posZ = posZ;
	this.fallTile = fallingBlockState;
	lastState = fallingBlockState;

}

@Override
protected void entityInit() {

}

@Override
public void onUpdate() {
	isRendered = false;

	if(allowFall){
		this.motionY = -0.001;
	}

	super.onUpdate();
}

protected void writeEntityToNBT(NBTTagCompound tagCompound)
    {
        Block block = this.fallTile != null ? this.fallTile.getBlock() : Blocks.air;
        ResourceLocation resourcelocation = (ResourceLocation)Block.blockRegistry.getNameForObject(block);
        tagCompound.setString("Block", resourcelocation == null ? "" : resourcelocation.toString());
        tagCompound.setByte("Data", (byte)block.getMetaFromState(this.fallTile));

        if (this.tileEntityData != null)
        {
            tagCompound.setTag("TileEntityData", this.tileEntityData);
        }
    }

    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     */
    protected void readEntityFromNBT(NBTTagCompound tagCompund)
    {
        int i = tagCompund.getByte("Data") & 255;

        if (tagCompund.hasKey("Block", )
        {
            this.fallTile = Block.getBlockFromName(tagCompund.getString("Block")).getStateFromMeta(i);
        }
        else if (tagCompund.hasKey("TileID", 99))
        {
            this.fallTile = Block.getBlockById(tagCompund.getInteger("TileID")).getStateFromMeta(i);
        }
        else
        {
            this.fallTile = Block.getBlockById(tagCompund.getByte("Tile") & 255).getStateFromMeta(i);
        }

        Block block = this.fallTile.getBlock();

        if (tagCompund.hasKey("TileEntityData", 10))
        {
            this.tileEntityData = tagCompund.getCompoundTag("TileEntityData");
        }

        if (block == null || block.getMaterial() == Material.air)
        {
            this.fallTile = Blocks.sand.getDefaultState();
        }
    }

public IBlockState getBlock()
{
	return this.fallTile;
}

@SideOnly(Side.CLIENT)
public World getWorldObj()
{
	return this.worldObj;
}

public void setAllowFall(boolean flag){
	allowFall = flag;
}

public boolean getAllowFall(){
	return allowFall;
}
}

 

Render Code

 

package de.intektor.moreminecraft.render;

import de.intektor.moreminecraft.entity.EntityNotFallingBlock;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.entity.RenderFallingBlock;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.resources.model.IBakedModel;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityFallingBlock;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

public class RenderNotFallingBlock extends RenderFallingBlock{

public RenderNotFallingBlock(RenderManager p_i46177_1_) {
	super(p_i46177_1_);
	  this.shadowSize = 0.5F;
    }

    public void doRender(EntityNotFallingBlock p_180557_1_, double p_180557_2_, double p_180557_4_, double p_180557_6_, float p_180557_8_, float p_180557_9_)
    {
        if (p_180557_1_.getBlock() != null)
        {
        	p_180557_1_.isRendered = true;
            this.bindTexture(TextureMap.locationBlocksTexture);
            IBlockState iblockstate = p_180557_1_.getBlock();
            Block block = iblockstate.getBlock();
            BlockPos blockpos = new BlockPos(p_180557_1_);
            World world = p_180557_1_.getWorldObj();

            if (iblockstate != world.getBlockState(blockpos) && block.getRenderType() != -1)
            {
                if (block.getRenderType() == 3)
                {
                    GlStateManager.pushMatrix();
                    GlStateManager.translate((float)p_180557_2_, (float)p_180557_4_, (float)p_180557_6_);
                    GlStateManager.disableLighting();
                    Tessellator tessellator = Tessellator.getInstance();
                    WorldRenderer worldrenderer = tessellator.getWorldRenderer();
                    worldrenderer.startDrawingQuads();
                    worldrenderer.setVertexFormat(DefaultVertexFormats.BLOCK);
                    int i = blockpos.getX();
                    int j = blockpos.getY();
                    int k = blockpos.getZ();
                    worldrenderer.setTranslation((double)((float)(-i) - 0.5F), (double)(-j), (double)((float)(-k) - 0.5F));
                    BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
                    IBakedModel ibakedmodel = blockrendererdispatcher.getModelFromBlockState(iblockstate, world, (BlockPos)null);
                    blockrendererdispatcher.getBlockModelRenderer().renderModel(world, ibakedmodel, iblockstate, blockpos, worldrenderer, false);
                    worldrenderer.setTranslation(0.0D, 0.0D, 0.0D);
                    tessellator.draw();
                    GlStateManager.enableLighting();
                    GlStateManager.popMatrix();
//                  super.doRender(p_180557_1_, p_180557_2_, p_180557_4_, p_180557_6_, p_180557_8_, p_180557_9_);
                }
            }
        }
    }

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(EntityFallingBlock entity)
    {
        return TextureMap.locationBlocksTexture;
    }

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(Entity entity)
    {
        return this.getEntityTexture((EntityFallingBlock)entity);
    }

    /**
     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
     * (Render<T extends Entity>) and this method has signature public void func_76986_a(T entity, double d, double d1,
     * double d2, float f, float f1). But JAD is pre 1.5 so doe
     */
    public void doRender(Entity entity, double x, double y, double z, float p_76986_8_, float partialTicks)
    {
        this.doRender((EntityNotFallingBlock)entity, x, y, z, p_76986_8_, partialTicks);
    }
}

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

It's the vanilla code dude, the not Falling Block is just not really hard to read, and the renderer is a complete copy of vanilla code, so...

 

and if you mean my Item code, look a bit closer, it is explained

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

I just hope for you to help me, because I'm stuck:

 

Sometimes this code works, sometimes not:

 

public void takeBlock(World world, EntityPlayer player, BlockPos pos, float hitX, float hitY, float hitZ, int id){
	ItemStack stack = player.getCurrentEquippedItem();
	stack.setTagCompound(new NBTTagCompound());
	NBTTagCompound nbt = stack.getTagCompound();
	EntityNotFallingBlock nfb = new EntityNotFallingBlock(world, hitX, hitY, hitZ, world.getBlockState(pos));
	nfb.theBlock = world.getBlockState(pos);
	world.spawnEntityInWorld(nfb);
	nbt.setString("EntityID", nfb.getPersistentID().toString());
	WorldServer server = (WorldServer) world;
	System.out.println(server.getEntityFromUuid(UUID.fromString(nbt.getString("EntityID"))) == nfb);

 

Thats the main problem right now

 

 

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

But here is the most weird thing:

 

@Override
public void onUpdate(ItemStack stack, World world, Entity player, int itemSlot, boolean isSelected) {

	EntityArrow arrow = new EntityArrow(world, player.posX, player.posY, player.posZ);
	world.spawnEntityInWorld(arrow);
	if(!world.isRemote){
		WorldServer server = (WorldServer) world;
		System.out.println(server.getEntityFromUuid(arrow.getPersistentID()) == arrow);
	}

	arrow.setDead();

 

Works perfectly

 

public void takeBlock(World world, EntityPlayer player, BlockPos pos, float hitX, float hitY, float hitZ, int id){
	ItemStack stack = player.getCurrentEquippedItem();
	stack.setTagCompound(new NBTTagCompound());
	NBTTagCompound nbt = stack.getTagCompound();
	EntityNotFallingBlock nfb = new EntityNotFallingBlock(world, hitX, hitY, hitZ, world.getBlockState(pos));
//		nfb.theBlock = world.getBlockState(pos);
	world.spawnEntityInWorld(nfb);
//		nbt.setString("EntityID", nfb.getPersistentID().toString());
	WorldServer server = (WorldServer) world;
	System.out.println(server.getEntityFromUuid(nfb.getPersistentID()) == nfb);

 

Doesn't work

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

Because it doen't matter where I spawn the entity, it will teleported to the position where the player is looking anyway, I can change the values to, player.posX, player.posY, player.posZ

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

Ok, it returns true now, well thats good, thanks, but that doesn't fix that my entity wont get rendered

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Posted

Well I have really no idea, either you explain me, what I don't expect, or I use onEntityjoindWorld Event, what I will do right now

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

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.