List of usage examples for net.minecraftforge.common.util FakePlayer FakePlayer
public FakePlayer(ServerWorld world, GameProfile name)
From source file:coolalias.structuregenapi.util.StructureGeneratorBase.java
License:Open Source License
/** * Places a hanging item entity in the world at the correct location and facing. * Note that you MUST use a WALL_MOUNTED type block id (such as torch) for your custom * block id's getRealBlockID return value in order for orientation to be correct. * Coordinates x,y,z are the location of the block used to spawn the entity * NOTE: Automatically removes the dummy block at x/y/z before placing the entity, so the * metadata stored in the block will no longer be available, but will be returned by this * method so it can be stored in a local variable for later use. * @param hanging Must be an instance of ItemHangingEntity, such as Items.painting * @return Returns direction for further processing such as for ItemFrames, or -1 if no entity set *//* w w w . j a v a2 s. c o m*/ public static final int setHangingEntity(World world, ItemStack hanging, int x, int y, int z) { if (hanging.getItem() == null || !(hanging.getItem() instanceof ItemHangingEntity)) { return -1; } if (world.getBlockMetadata(x, y, z) < 1 || world.getBlockMetadata(x, y, z) > 5) { LogHelper.log(Level.WARN, "Hanging entity has invalid metadata of " + world.getBlockMetadata(x, y, z) + ". Valid values are 1,2,3,4"); return -1; } int[] metaToFacing = { 5, 4, 3, 2 }; int direction = metaToFacing[world.getBlockMetadata(x, y, z) - 1]; FakePlayer player = new FakePlayer((WorldServer) world, generatorName); world.setBlockToAir(x, y, z); switch (direction) { case 2: ++z; break; // frame facing NORTH case 3: --z; break; // frame facing SOUTH case 4: ++x; break; // frame facing WEST case 5: --x; break; // frame facing EAST } ((ItemHangingEntity) hanging.getItem()).onItemUse(hanging, player, world, x, y, z, direction, 0, 0, 0); return direction; }