mirror of
https://github.com/GTNewHorizons/Electro-Magic-Tools.git
synced 2026-11-18 11:19:18 +00:00
Cleanup and some changes...
This commit is contained in:
1 parent
a39ac3bd74
commit
7b6ec78cd7
125 files changed
+971
-955
No files matched your search
@@ -0,0 +1,49 @@
|
||||
package emt.util;
|
||||
|
||||
import ic2.api.item.ElectricItem;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class EMTRandomHelper {
|
||||
|
||||
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(Locale.US).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;
|
||||
}
|
||||
|
||||
public static ItemStack getChargedItem(Item item, int charge) {
|
||||
ItemStack stack = new ItemStack(item);
|
||||
ElectricItem.manager.charge(stack, charge, charge, true, false);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user