Added advanced drill

Added TorchHelper.class
This commit is contained in:
Gig 2015-04-13 19:08:17 +01:00
parent 82a760a564
commit dbb6a9edf2
5 changed files with 183 additions and 30 deletions

View file

@ -0,0 +1,36 @@
package techreborn.util;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeEventFactory;
public class TorchHelper {
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;
}
}