Added advanced drill
Added TorchHelper.class
This commit is contained in:
parent
82a760a564
commit
dbb6a9edf2
5 changed files with 183 additions and 30 deletions
36
src/main/java/techreborn/util/TorchHelper.java
Normal file
36
src/main/java/techreborn/util/TorchHelper.java
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue