Java Code Examples for net.minecraft.item.ItemStack#tryPlaceItemIntoWorld()

The following examples show how to use net.minecraft.item.ItemStack#tryPlaceItemIntoWorld() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchematicMask.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void placeInWorld(IBuilderContext context, int x, int y, int z, LinkedList<ItemStack> stacks) {
	if (isConcrete) {
		if (stacks.size() == 0 || !BuildCraftAPI.isSoftBlock(context.world(), x, y, z)) {
			return;
		} else {
			ItemStack stack = stacks.getFirst();

			// force the block to be air block, in case it's just a soft
			// block which replacement is not straightforward
			context.world().setBlock(x, y, z, Blocks.air, 0, 3);

			stack.tryPlaceItemIntoWorld(
					BuildCraftAPI.proxy.getBuildCraftPlayer((WorldServer) context.world()).get(),
					context.world(), x, y, z, 1, 0.0f, 0.0f, 0.0f);
		}
	} else {
		context.world().setBlock(x, y, z, Blocks.air, 0, 3);
	}
}
 
Example 2
Source File: RandomHelper.java    From Electro-Magic-Tools with GNU General Public License v3.0 6 votes vote down vote up
public static boolean placeTorch(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) {
    for (int i = 0; i < player.inventory.mainInventory.length; i++) {
        ItemStack torchStack = player.inventory.mainInventory[i];
        if (torchStack == null || !torchStack.getUnlocalizedName().toLowerCase().contains("torch")) continue;
        Item item = torchStack.getItem();
        if (!(item instanceof ItemBlock)) continue;
        int oldMeta = torchStack.getItemDamage();
        int oldSize = torchStack.stackSize;
        boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x, y, z, side, xOffset, yOffset, zOffset);
        if (player.capabilities.isCreativeMode) {
            torchStack.setItemDamage(oldMeta);
            torchStack.stackSize = oldSize;
        } else if (torchStack.stackSize <= 0) {
            ForgeEventFactory.onPlayerDestroyItem(player, torchStack);
            player.inventory.mainInventory[i] = null;
        }
        if (result) return true;
    }
    return false;
}
 
Example 3
Source File: ItemOmnitoolIron.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) {
    for (int i = 0; i < player.inventory.mainInventory.length; i++) {
        ItemStack torchStack = player.inventory.mainInventory[i];
        if (torchStack == null || !torchStack.getUnlocalizedName().toLowerCase().contains("torch")) {
            continue;
        }
        Item item = torchStack.getItem();
        if (!(item instanceof ItemBlock)) {
            continue;
        }
        int oldMeta = torchStack.getItemDamage();
        int oldSize = torchStack.stackSize;
        boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x, y, z, side, xOffset, yOffset, zOffset);
        if (player.capabilities.isCreativeMode) {
            torchStack.setItemDamage(oldMeta);
            torchStack.stackSize = oldSize;
        } else if (torchStack.stackSize <= 0) {
            ForgeEventFactory.onPlayerDestroyItem(player, torchStack);
            player.inventory.mainInventory[i] = null;
        }
        if (result) {
            return true;
        }
    }

    return super.onItemUse(stack, player, world, x, y, z, side, xOffset, yOffset, zOffset);
}
 
Example 4
Source File: ItemDiamondChainsaw.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) {
    for (int i = 0; i < player.inventory.mainInventory.length; i++) {
        ItemStack torchStack = player.inventory.mainInventory[i];
        if (torchStack == null || !torchStack.getUnlocalizedName().toLowerCase().contains("torch")) {
            continue;
        }
        Item item = torchStack.getItem();
        if (!(item instanceof ItemBlock)) {
            continue;
        }
        int oldMeta = torchStack.getItemDamage();
        int oldSize = torchStack.stackSize;
        boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x, y, z, side, xOffset, yOffset, zOffset);
        if (player.capabilities.isCreativeMode) {
            torchStack.setItemDamage(oldMeta);
            torchStack.stackSize = oldSize;
        } else if (torchStack.stackSize <= 0) {
            ForgeEventFactory.onPlayerDestroyItem(player, torchStack);
            player.inventory.mainInventory[i] = null;
        }
        if (result) {
            return true;
        }
    }

    return super.onItemUse(stack, player, world, x, y, z, side, xOffset, yOffset, zOffset);
}
 
Example 5
Source File: ItemRockbreakerDrill.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unused")
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) {
    if (!player.isSneaking()) {
        for (int i = 0; i < player.inventory.mainInventory.length; i++) {
            ItemStack torchStack = player.inventory.mainInventory[i];
            if (torchStack == null || !torchStack.getUnlocalizedName().toLowerCase().contains("torch")) {
                continue;
            }
            Item item = torchStack.getItem();
            if (!(item instanceof ItemBlock)) {
                continue;
            }
            int oldMeta = torchStack.getItemDamage();
            int oldSize = torchStack.stackSize;
            boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x, y, z, side, xOffset, yOffset, zOffset);
            if (player.capabilities.isCreativeMode) {
                torchStack.setItemDamage(oldMeta);
                torchStack.stackSize = oldSize;
            } else if (torchStack.stackSize <= 0) {
                ForgeEventFactory.onPlayerDestroyItem(player, torchStack);
                player.inventory.mainInventory[i] = null;
            }
            if (result) {
                return true;
            }
        }
    } else {
        ElectricItem.manager.use(stack, searchCost, player);
        if (!world.isRemote) {
            world.playSoundEffect(x + 0.5D, y + 0.5D, z + 0.5D, "thaumcraft:wandfail", 0.2F, 0.2F + world.rand.nextFloat() * 0.2F);
            return super.onItemUse(stack, player, world, x, y, z, side, xOffset, xOffset, zOffset);
        }
        Minecraft mc = Minecraft.getMinecraft();
        Thaumcraft.instance.renderEventHandler.startScan(player, x, y, z, System.currentTimeMillis() + 5000L);
        player.swingItem();
        return super.onItemUse(stack, player, world, x, y, z, side, xOffset, yOffset, zOffset);
    }

    return super.onItemUse(stack, player, world, x, y, z, side, xOffset, yOffset, zOffset);
}