Added advanced drill
Added TorchHelper.class
This commit is contained in:
parent
82a760a564
commit
dbb6a9edf2
5 changed files with 183 additions and 30 deletions
|
@ -11,6 +11,7 @@ import techreborn.items.ItemDusts;
|
|||
import techreborn.items.ItemGems;
|
||||
import techreborn.items.ItemIngots;
|
||||
import techreborn.items.ItemParts;
|
||||
import techreborn.items.tools.ItemAdvancedDrill;
|
||||
import techreborn.items.tools.ItemLapotronPack;
|
||||
import techreborn.items.tools.ItemLithiumBatpack;
|
||||
import techreborn.items.tools.ItemOmniTool;
|
||||
|
@ -28,6 +29,7 @@ public class ModItems {
|
|||
public static Item lithiumBatpack;
|
||||
public static Item lapotronpack;
|
||||
public static Item omniTool;
|
||||
public static Item advancedDrill;
|
||||
|
||||
public static void init()
|
||||
{
|
||||
|
@ -47,6 +49,8 @@ public class ModItems {
|
|||
GameRegistry.registerItem(lapotronpack, "lapotronPack");
|
||||
omniTool = new ItemOmniTool(ToolMaterial.EMERALD);
|
||||
GameRegistry.registerItem(omniTool, "omniTool");
|
||||
advancedDrill = new ItemAdvancedDrill();
|
||||
GameRegistry.registerItem(advancedDrill, "advancedDrill");
|
||||
|
||||
LogHelper.info("TechReborns Items Loaded");
|
||||
|
||||
|
|
140
src/main/java/techreborn/items/tools/ItemAdvancedDrill.java
Normal file
140
src/main/java/techreborn/items/tools/ItemAdvancedDrill.java
Normal file
|
@ -0,0 +1,140 @@
|
|||
package techreborn.items.tools;
|
||||
|
||||
import ic2.api.item.ElectricItem;
|
||||
import ic2.api.item.IElectricItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import mcp.mobius.waila.api.impl.ConfigHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemPickaxe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import techreborn.client.TechRebornCreativeTab;
|
||||
import techreborn.util.TorchHelper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemAdvancedDrill extends ItemPickaxe implements IElectricItem{
|
||||
|
||||
public int maxCharge = 60000;
|
||||
public int cost = 250;;
|
||||
public int tier = 2;
|
||||
public double transferLimit = 100;
|
||||
|
||||
public ItemAdvancedDrill()
|
||||
{
|
||||
super(ToolMaterial.EMERALD);
|
||||
efficiencyOnProperMaterial = 20F;
|
||||
setCreativeTab(TechRebornCreativeTab.instance);
|
||||
setMaxStackSize(1);
|
||||
setMaxDamage(240);
|
||||
setUnlocalizedName("techreborn.advancedDrill");
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerIcons(IIconRegister iconRegister)
|
||||
{
|
||||
this.itemIcon = iconRegister.registerIcon("techreborn:" + "advancedDrill");
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList)
|
||||
{
|
||||
ItemStack itemStack = new ItemStack(this, 1);
|
||||
if (getChargedItem(itemStack) == this)
|
||||
{
|
||||
ItemStack charged = new ItemStack(this, 1);
|
||||
ElectricItem.manager.charge(charged, 2147483647, 2147483647, true, false);
|
||||
itemList.add(charged);
|
||||
}
|
||||
if (getEmptyItem(itemStack) == this)
|
||||
{
|
||||
itemList.add(new ItemStack(this, 1, getMaxDamage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int par4, int par5, int par6, EntityLivingBase entityLiving)
|
||||
{
|
||||
ElectricItem.manager.use(stack, cost, entityLiving);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHarvestBlock(Block block, ItemStack stack) {
|
||||
return Items.diamond_pickaxe.canHarvestBlock(block, stack) || Items.diamond_shovel.canHarvestBlock(block, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDigSpeed(ItemStack stack, Block block, int meta) {
|
||||
if (!ElectricItem.manager.canUse(stack, cost))
|
||||
{
|
||||
return 4.0F;
|
||||
}
|
||||
|
||||
if (Items.wooden_pickaxe.getDigSpeed(stack, block, meta) > 1.0F || Items.wooden_shovel.getDigSpeed(stack, block, meta) > 1.0F)
|
||||
{
|
||||
return efficiencyOnProperMaterial;
|
||||
} else {
|
||||
return super.getDigSpeed(stack, block, meta);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hitEntity(ItemStack itemstack, EntityLivingBase entityliving, EntityLivingBase entityliving1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset)
|
||||
{
|
||||
return TorchHelper.placeTorch(stack, player, world, x, y, z, side, xOffset, yOffset, zOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRepairable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(ItemStack itemStack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxCharge(ItemStack itemStack) {
|
||||
return maxCharge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTier(ItemStack itemStack) {
|
||||
return tier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransferLimit(ItemStack itemStack) {
|
||||
return transferLimit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getChargedItem(ItemStack itemStack) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getEmptyItem(ItemStack itemStack) {
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
import ic2.api.item.ElectricItem;
|
||||
import ic2.api.item.IElectricItem;
|
||||
import techreborn.client.TechRebornCreativeTab;
|
||||
import techreborn.util.TorchHelper;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
|
@ -103,36 +104,7 @@ public class ItemOmniTool extends ItemPickaxe implements IElectricItem{
|
|||
@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);
|
||||
return TorchHelper.placeTorch(stack, player, world, x, y, z, side, xOffset, yOffset, zOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
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;
|
||||
}
|
||||
}
|
|
@ -151,6 +151,7 @@ item.techreborn.rockcutter.name=Rockcutter
|
|||
item.techreborn.lithiumbatpack.name=lithium Batpack
|
||||
item.techreborn.lapotronpack.name=Lapotron Pack
|
||||
item.techreborn.omniTool.name=Omni tool
|
||||
item.techreborn.advancedDrill.name=Advanced Drill
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue