diff options
| author | Draknyte1 <Draknyte1@hotmail.com> | 2016-09-07 16:36:25 +1000 |
|---|---|---|
| committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-09-07 16:36:25 +1000 |
| commit | 221c2f0fe81430e7dd4087e5f5845bd7c62ec56d (patch) | |
| tree | d6e0faaef01b9d517828557e1be82500d476f95e /src/Java/gtPlusPlus/core/item/tool | |
| parent | 5872c0947ce7bc788b03fa2fb690b8815d3d0a04 (diff) | |
| download | GT5-Unofficial-221c2f0fe81430e7dd4087e5f5845bd7c62ec56d.tar.gz GT5-Unofficial-221c2f0fe81430e7dd4087e5f5845bd7c62ec56d.tar.bz2 GT5-Unofficial-221c2f0fe81430e7dd4087e5f5845bd7c62ec56d.zip | |
% Refactored the entire project to stop using MiscUtils everywhere possible, now it's gtPlusPlus.
Diffstat (limited to 'src/Java/gtPlusPlus/core/item/tool')
4 files changed, 847 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/item/tool/misc/SandstoneHammer.java b/src/Java/gtPlusPlus/core/item/tool/misc/SandstoneHammer.java new file mode 100644 index 0000000000..108ac4b83d --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/tool/misc/SandstoneHammer.java @@ -0,0 +1,79 @@ +package gtPlusPlus.core.item.tool.misc; + +import gtPlusPlus.core.item.base.BaseItemWithDamageValue; +import gtPlusPlus.core.lib.CORE; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class SandstoneHammer extends BaseItemWithDamageValue{ + + /* (non-Javadoc) + * @see net.minecraft.item.Item#getColorFromItemStack(net.minecraft.item.ItemStack, int) + */ + @Override + public int getColorFromItemStack(ItemStack stack, int HEX_OxFFFFFF) { + //Figure Out Damage + + + return super.getColorFromItemStack(stack, HEX_OxFFFFFF); + } + + public SandstoneHammer(String unlocalizedName) { + super(unlocalizedName); + this.setTextureName(CORE.MODID + ":" + unlocalizedName); + this.setMaxStackSize(1); + this.setMaxDamage(2500); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(ItemStack stack, EntityPlayer aPlayer, List list, boolean bool) { + list.add(EnumChatFormatting.GRAY+"Allows you to craft sand from cobble, or sandstone from sand."); + super.addInformation(stack, aPlayer, list, bool); + } + + @Override + public boolean doesContainerItemLeaveCraftingGrid(ItemStack itemStack) + { + return false; + } + + @Override + public boolean getShareTag() + { + return true; + } + + @Override + public boolean hasContainerItem(ItemStack itemStack) + { + return true; + } + @Override + public ItemStack getContainerItem(ItemStack itemStack) + { + itemStack.setItemDamage(itemStack.getItemDamage() + 8); + + return itemStack; + } + + @Override + @SideOnly(Side.CLIENT) + public EnumRarity getRarity(ItemStack par1ItemStack){ + return EnumRarity.uncommon; + } + + @Override + public boolean hasEffect(ItemStack par1ItemStack){ + return false; + } + + +} diff --git a/src/Java/gtPlusPlus/core/item/tool/staballoy/MultiPickaxeBase.java b/src/Java/gtPlusPlus/core/item/tool/staballoy/MultiPickaxeBase.java new file mode 100644 index 0000000000..ea59ed2b7e --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/tool/staballoy/MultiPickaxeBase.java @@ -0,0 +1,179 @@ +package gtPlusPlus.core.item.tool.staballoy; + +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.player.UtilsMining; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class MultiPickaxeBase extends StaballoyPickaxe{ + + /* (non-Javadoc) + * @see net.minecraft.item.Item#getDurabilityForDisplay(net.minecraft.item.ItemStack) + */ + @Override + public double getDurabilityForDisplay(ItemStack stack) { + if (super.getDurabilityForDisplay(stack) > 0){ + return super.getDurabilityForDisplay(stack);} + return 0; + } + + protected Boolean FACING_HORIZONTAL = true; + protected String FACING = "north"; + protected EntityPlayer localPlayer; + protected String lookingDirection; + protected World localWorld; + protected ItemStack thisPickaxe = null; + protected final int colour; + protected final String materialName; + + public MultiPickaxeBase(String unlocalizedName, ToolMaterial material, int materialDurability, int colour) { + super(Utils.sanitizeString(unlocalizedName), material); + this.setUnlocalizedName(Utils.sanitizeString(unlocalizedName)); + this.setTextureName(CORE.MODID + ":" + "itemPickaxe"); + this.FACING_HORIZONTAL=true; + this.setMaxStackSize(1); + this.setMaxDamage(materialDurability); + this.colour = colour; + this.materialName = material.name(); + GameRegistry.registerItem(this, Utils.sanitizeString(unlocalizedName)); + this.setCreativeTab(AddToCreativeTab.tabTools); + } + + /* + * + * + * + * Methods + * + * + * + */ + + public final String getMaterialName() { + return materialName; + } + + @Override + public String getItemStackDisplayName(ItemStack iStack) { + + String name; + if (getUnlocalizedName().toLowerCase().contains("wood")){ + name = "Wooden"; + } + else if (getUnlocalizedName().toLowerCase().contains("cobblestone")){ + name = "Cobblestone"; + } + else if (getUnlocalizedName().toLowerCase().contains("iron")){ + name = "Iron"; + } + else if (getUnlocalizedName().toLowerCase().contains("gold")){ + name = "Gold"; + } + else if (getUnlocalizedName().toLowerCase().contains("diamond")){ + name = "Diamond"; + } + else { + name = materialName; + } + return name+" Multipickaxe"; + } + + @Override + public int getColorFromItemStack(ItemStack stack, int HEX_OxFFFFFF) { + if (colour == 0){ + return MathUtils.generateSingularRandomHexValue(); + } + return colour; + + } + + @SuppressWarnings("static-method") + private float calculateDurabilityLoss(World world, int X, int Y, int Z){ + float bDurabilityLoss = 0; + Boolean correctTool = false; + float bHardness = 0; + if (!world.isRemote){ + try { + Block removalist = world.getBlock(X, Y, Z); + //Utils.LOG_WARNING(removalist.toString()); + + bHardness = removalist.getBlockHardness(world, X, Y, Z); + Utils.LOG_WARNING("Hardness: "+bHardness); + + bDurabilityLoss = (bDurabilityLoss + bHardness); + //Utils.LOG_WARNING("Durability Loss: "+bDurabilityLoss); + + correctTool = canPickaxeBlock(removalist, world); + Utils.LOG_WARNING(""+correctTool); + + if (!correctTool){ + return 0; + } + + } catch (NullPointerException e){ + + } + } + return bDurabilityLoss; + } + + @Override + public int doDurabilityDamage(int x){ + return x; + } + + //Should clear up blocks quicker if I chain it. + @Override + public void removeBlockAndDropAsItem(World world, int X, int Y, int Z, ItemStack heldItem){ + localWorld = world; + try { + Block block = world.getBlock(X, Y, Z); + float dur = calculateDurabilityLoss(world, X, Y, Z); + Utils.LOG_WARNING(block.toString()); + String removalTool = ""; + removalTool = block.getHarvestTool(1); + + if (removalTool.equals("pickaxe") || UtilsMining.getBlockType(block)){ + if (canPickaxeBlock(block, world)){ + if((block != Blocks.bedrock) && (block.getBlockHardness(world, X, Y, Z) != -1) && (block.getBlockHardness(world, X, Y, Z) <= 100) && (block != Blocks.water) && (block != Blocks.lava)){ + + if (heldItem.getItemDamage() <= (heldItem.getMaxDamage()-dur)){ + + block.dropBlockAsItem(world, X, Y, Z, world.getBlockMetadata(X, Y, Z), 0); + world.setBlockToAir(X, Y, Z); + + } + + } + } + else { + Utils.LOG_WARNING("Incorrect Tool for mining this block."); + } + } + } catch (NullPointerException e){ + + } + } + + @Override + @SideOnly(Side.CLIENT) + public EnumRarity getRarity(ItemStack par1ItemStack){ + return EnumRarity.uncommon; + } + + @Override + public boolean hasEffect(ItemStack par1ItemStack){ + return false; + } + +} diff --git a/src/Java/gtPlusPlus/core/item/tool/staballoy/StaballoyAxe.java b/src/Java/gtPlusPlus/core/item/tool/staballoy/StaballoyAxe.java new file mode 100644 index 0000000000..07c5800a1f --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/tool/staballoy/StaballoyAxe.java @@ -0,0 +1,279 @@ +package gtPlusPlus.core.item.tool.staballoy; + +import gtPlusPlus.core.lib.CORE; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockAir; +import net.minecraft.block.BlockCocoa; +import net.minecraft.block.BlockDirt; +import net.minecraft.block.BlockDoublePlant; +import net.minecraft.block.BlockFlower; +import net.minecraft.block.BlockGrass; +import net.minecraft.block.BlockHugeMushroom; +import net.minecraft.block.BlockLeavesBase; +import net.minecraft.block.BlockLog; +import net.minecraft.block.BlockMushroom; +import net.minecraft.block.BlockSand; +import net.minecraft.block.BlockSnow; +import net.minecraft.block.BlockSnowBlock; +import net.minecraft.block.BlockTallGrass; +import net.minecraft.block.BlockVine; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemAxe; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class StaballoyAxe extends ItemAxe{ + public String mat; + + public StaballoyAxe(String unlocalizedName, ToolMaterial material) { + super(material); + this.setUnlocalizedName(unlocalizedName); + this.setTextureName(CORE.MODID + ":" + unlocalizedName); + } + + // EXPLODE TREE + byte[] tre= new byte[32000]; + byte unchecked=0; + byte needcheck=1; + byte ignore =2; + byte harvest =3; + + private boolean setcheck(int x, int y, int z) { + if(x<0 || x>19 || z<0 || z>19 || y<0 || y>79) return false; + int o=x+z*20+y*400; + if (tre[o]==unchecked) tre[o]=needcheck; + return true; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(ItemStack stack, EntityPlayer aPlayer, List list, boolean bool) { + list.add(EnumChatFormatting.GOLD+"Fells entire trees in a single swipe!.."); + list.add(EnumChatFormatting.GRAY+"Ask Alkalus for new trees to be supported."); + super.addInformation(stack, aPlayer, list, bool); + } + + public boolean canIgnore(Block bit){ + if (bit instanceof BlockAir)return true; + if (bit instanceof BlockGrass)return true; + if (bit instanceof BlockSand)return true; + if (bit instanceof BlockDirt)return true; + if (bit instanceof BlockCocoa)return true; + if (bit instanceof BlockVine)return true; + if (bit instanceof BlockMushroom)return true; + if (bit instanceof BlockSnow)return true; + if (bit instanceof BlockSnowBlock)return true; + if (bit instanceof BlockFlower)return true; + if (bit instanceof BlockTallGrass)return true; + if (bit instanceof BlockDoublePlant)return true; + + //LoonTools.log("Found uncuttable "+bit.getClass().getSimpleName()); + return false; + } + + private int check(World par1World, int x, int y, int z, int xo, int yo,int zo) { + int f=0; + int o=x+z*20+y*400; + if (tre[o]==needcheck){ + tre[o]=ignore; + Block bit = par1World.getBlock(x+xo, y+yo, z+zo); + if ((bit instanceof BlockLog)||(bit instanceof BlockLeavesBase)||(bit instanceof BlockHugeMushroom) || (bit.getUnlocalizedName().toLowerCase().contains("log")) || (bit.getUnlocalizedName().toLowerCase().contains("wood"))){ + f=1; + tre[o]=harvest; + //if (bit instanceof BlockLog){ + // LoonTools.log("^ Found log @ "+x+xo+" "+y+yo+" "+z+zo+" "); + //} + for(int xb=-1;xb<2;xb++) + for(int yb=-1;yb<2;yb++) + for(int zb=-1;zb<2;zb++) + if (!setcheck(x+xb,y+yb,z+zb))return 3; + }else{ + if (!canIgnore(bit)) return 2; + } + } + return f; + } + + public int checkTree(World par1World,int xo,int yo,int zo){ + boolean f; + for (f=true;f==true;){ + f=false; + for (int y=0;y<80;y++) + for(int z=0;z<20;z++) + for(int x=0;x<20;x++){ + int r=check(par1World,x,y,z,xo,yo,zo); + if (r==3) return 3; + if (r==2) return 2; + if (r==1) f=true; + } + + for (int y=79;y>=0;y--) + for(int z=19;z>=0;z--) + for(int x=19;x>=0;x--){ + int r=check(par1World,x,y,z,xo,yo,zo); + if (r==2) return 3; + if (r==2) return 2; + if (r==1) f=true; + } + } + return 1; + } + + private int check2(World par1World, int x, int y, int z, int xo, int yo,int zo) { + int f=0; + int o=x+z*20+y*400; + if (tre[o]==needcheck){ + tre[o]=ignore; + Block bit = par1World.getBlock(x+xo, y+yo, z+zo); + if (bit instanceof BlockLog){ + f=1; + tre[o]=harvest; + //if (bit instanceof BlockLog){ + // LoonTools.log("^ Found log @ "+x+xo+" "+y+yo+" "+z+zo+" "); + //} + for(int xb=-1;xb<2;xb++) + for(int yb=-1;yb<2;yb++) + for(int zb=-1;zb<2;zb++) + if (!setcheck(x+xb,y+yb,z+zb))return 3; + }else if (bit instanceof BlockLeavesBase){ + }else{ + if (!canIgnore(bit)) return 2; + } + } + return f; + } + + public int checkTree2(World par1World,int xo,int yo,int zo){ + boolean f; + for (f=true;f==true;){ + f=false; + for (int y=0;y<80;y++) + for(int z=0;z<20;z++) + for(int x=0;x<20;x++){ + int r=check2(par1World,x,y,z,xo,yo,zo); + if (r==3) return 3; + if (r==2) return 2; + if (r==1) f=true; + } + + for (int y=79;y>=0;y--) + for(int z=19;z>=0;z--) + for(int x=19;x>=0;x--){ + int r=check2(par1World,x,y,z,xo,yo,zo); + if (r==2) return 3; + if (r==2) return 2; + if (r==1) f=true; + } + } + return 1; + } + + public void exploadTree(World par1World,int xo,int yo,int zo, EntityPlayer plr){ + for (int y=0;y<80;y++) + for(int z=0;z<20;z++) + for(int x=0;x<20;x++){ + int o=x+z*20+y*400; + if (tre[o]==harvest){ + Block bit = par1World.getBlock(x+xo, y+yo, z+zo); + int met = par1World.getBlockMetadata(x+xo, y+yo, z+zo); + + if ((bit instanceof BlockLog)||(bit instanceof BlockLeavesBase) || (bit.getUnlocalizedName().toLowerCase().contains("log")) || (bit.getUnlocalizedName().toLowerCase().contains("wood"))){ + bit.harvestBlock(par1World, plr, x+xo, y+yo, z+zo,met); + par1World.setBlockToAir(x+xo, y+yo, z+zo); + } + } + } + } + + private void breakMushroom(World wld, Block bit, EntityPlayer plr, boolean silk, int x, int y, int z, int met) { + if (silk){ + ItemStack stk = null; //TODO + /*if (bit==Blocks.brown_mushroom_block) stk = new ItemStack(LoonToolItems.brown_mushroom_block,1,met); + else if (bit==Blocks.red_mushroom_block) stk = new ItemStack(LoonToolItems.red_mushroom_block,1,met); + else stk = new ItemStack(bit,1,met);*/ + EntityItem entityitem = new EntityItem(wld, x+0.5, y+0.5, z+0.5, stk); + entityitem.delayBeforeCanPickup = 10; + wld.spawnEntityInWorld(entityitem); + }else{ + bit.harvestBlock(wld, plr, x, y, z, met); + } + wld.setBlockToAir(x, y, z); + } + + public void exploadMushroom(World par1World,int xo,int yo,int zo, EntityPlayer plr, boolean silk){ + for (int y=0;y<80;y++) + for(int z=0;z<20;z++) + for(int x=0;x<20;x++){ + int o=x+z*20+y*400; + if (tre[o]==harvest){ + Block bit = par1World.getBlock(x+xo, y+yo, z+zo); + int met = par1World.getBlockMetadata(x+xo, y+yo, z+zo); + if (bit instanceof BlockHugeMushroom){ + breakMushroom(par1World, bit, plr, silk, x+xo, y+yo, z+zo,met); + }else{ + bit.harvestBlock(par1World, plr, x+xo, y+yo, z+zo,met); + par1World.setBlockToAir(x+xo, y+yo, z+zo); + } + } + } + } + + + @Override + public boolean onBlockDestroyed(ItemStack itm, World wld,Block blk, int x, int y,int z, EntityLivingBase plr) { + if (!wld.isRemote){ + Block bit = wld.getBlock(x, y, z); + boolean silk=EnchantmentHelper.getSilkTouchModifier(plr); + if ((bit instanceof BlockHugeMushroom)){ + for (int n=0;n<32000;n++) tre[n]=unchecked; + int met = wld.getBlockMetadata(x, y, z); + breakMushroom(wld, bit, (EntityPlayer) plr, silk, x, y, z,met); + wld.setBlockToAir(x,y,z); + tre[2210]=needcheck; + if (checkTree(wld,x-10,y-4,z-10)==1){ + exploadMushroom(wld,x-10,y-4,z-10,(EntityPlayer) plr,silk); + } + } + + if (bit instanceof BlockLog || (bit.getUnlocalizedName().toLowerCase().contains("log")) || (bit.getUnlocalizedName().toLowerCase().contains("wood"))){ + //LoonTools.log("cutting tree @ "+x+" "+y+" "+z+" "); + for (int n=0;n<32000;n++) tre[n]=unchecked; + int met = wld.getBlockMetadata(x, y, z); + bit.harvestBlock(wld, (EntityPlayer) plr, x, y, z,met); + wld.setBlockToAir(x,y,z); + tre[2210]=needcheck; + if (checkTree(wld,x-10,y-4,z-10)==1){ + exploadTree(wld,x-10,y-4,z-10,(EntityPlayer) plr); + }else{ + for (int n=0;n<32000;n++) tre[n]=unchecked; + tre[2210]=needcheck; + if (checkTree2(wld,x-10,y-4,z-10)==1){ + exploadTree(wld,x-10,y-4,z-10,(EntityPlayer) plr); + } + } + } + } + return super.onBlockDestroyed(itm, wld, blk, x, y, z, plr); + } + + @Override + @SideOnly(Side.CLIENT) + public EnumRarity getRarity(ItemStack par1ItemStack){ + return EnumRarity.rare; + } + + @Override + public boolean hasEffect(ItemStack par1ItemStack){ + return true; + } +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/item/tool/staballoy/StaballoyPickaxe.java b/src/Java/gtPlusPlus/core/item/tool/staballoy/StaballoyPickaxe.java new file mode 100644 index 0000000000..a21ee7e6ad --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/tool/staballoy/StaballoyPickaxe.java @@ -0,0 +1,310 @@ +package gtPlusPlus.core.item.tool.staballoy; + +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.player.UtilsMining; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemPickaxe; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.MathHelper; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class StaballoyPickaxe extends ItemPickaxe{ + + /* (non-Javadoc) + * @see net.minecraft.item.Item#getDurabilityForDisplay(net.minecraft.item.ItemStack) + */ + @Override + public double getDurabilityForDisplay(ItemStack stack) { + if (super.getDurabilityForDisplay(stack) > 0){ + return super.getDurabilityForDisplay(stack);} + return 0; + } + + protected Boolean FACING_HORIZONTAL = true; + protected String FACING = "north"; + protected EntityPlayer localPlayer; + protected String lookingDirection; + protected World localWorld; + public ItemStack thisPickaxe = null; + + /* + * + * + * + * Methods + * + * + * + */ + + @Override + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer aPlayer) { + localPlayer = aPlayer; + localWorld = world; + thisPickaxe = stack; + return super.onItemRightClick(stack, world, aPlayer); + } + + + + @Override + public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int X, int Y, int Z, EntityLivingBase entity) { + //super.onBlockDestroyed(stack, world, block, X, Y, Z, entity); + localWorld = world; + thisPickaxe = stack; + //checkFacing(world); + if (!world.isRemote){ + GetDestroyOrientation(lookingDirection, world, X, Y, Z, stack); + } + + return super.onBlockDestroyed(stack, world, block, X, Y, Z, entity); + } + + @SuppressWarnings("static-method") + private float calculateDurabilityLoss(World world, int X, int Y, int Z){ + float bDurabilityLoss = 0; + Boolean correctTool = false; + float bHardness = 0; + if (!world.isRemote){ + try { + Block removalist = world.getBlock(X, Y, Z); + //Utils.LOG_WARNING(removalist.toString()); + + bHardness = removalist.getBlockHardness(world, X, Y, Z); + Utils.LOG_WARNING("Hardness: "+bHardness); + + bDurabilityLoss = (bDurabilityLoss + bHardness); + //Utils.LOG_WARNING("Durability Loss: "+bDurabilityLoss); + + correctTool = canPickaxeBlock(removalist, world); + Utils.LOG_WARNING(""+correctTool); + + if (!correctTool){ + return 0; + } + + } catch (NullPointerException e){ + + } + } + return bDurabilityLoss; + } + + public Boolean canPickaxeBlock(Block currentBlock, World currentWorld){ + String correctTool = ""; + if (!currentWorld.isRemote){ + try { + correctTool = currentBlock.getHarvestTool(0); + //Utils.LOG_WARNING(correctTool); + if (UtilsMining.getBlockType(currentBlock) || correctTool.equals("pickaxe")){ + return true;} + } catch (NullPointerException e){ + return false;} + } + return false; + } + + private void GetDestroyOrientation(String FACING, World world, int X, int Y, int Z, ItemStack heldItem){ + localWorld = world; + float DURABILITY_LOSS = 0; + if (!world.isRemote){ + + if (FACING.equals("below") || FACING.equals("above")){ + DURABILITY_LOSS = 0; + for(int i = -1; i < 2; i++) { + for(int j = -1; j < 2; j++) { + float dur = calculateDurabilityLoss(world, X + i, Y, Z + j); + DURABILITY_LOSS = (DURABILITY_LOSS + calculateDurabilityLoss(world, X + i, Y, Z + j)); + Utils.LOG_WARNING("Added Loss: "+dur); + removeBlockAndDropAsItem(world, X + i, Y, Z + j, heldItem); + } + } + } + + else if (FACING.equals("facingEast") || FACING.equals("facingWest")){ + DURABILITY_LOSS = 0; + for(int i = -1; i < 2; i++) { + for(int j = -1; j < 2; j++) { + float dur = calculateDurabilityLoss(world, X, Y + i, Z + j); + DURABILITY_LOSS = (DURABILITY_LOSS + calculateDurabilityLoss(world, X, Y + i, Z + j)); + Utils.LOG_WARNING("Added Loss: "+dur); + removeBlockAndDropAsItem(world, X , Y + i, Z + j, heldItem); + } + } + } + + else if (FACING.equals("facingNorth") || FACING.equals("facingSouth")){ + DURABILITY_LOSS = 0; + for(int i = -1; i < 2; i++) { + for(int j = -1; j < 2; j++) { + float dur = calculateDurabilityLoss(world, X + j, Y + i, Z); + DURABILITY_LOSS = (DURABILITY_LOSS + dur); + Utils.LOG_WARNING("Added Loss: "+dur); + removeBlockAndDropAsItem(world, X + j, Y + i, Z, heldItem); + } + } + } + + //int heldItemDurability = heldItem.getDamage(1); + Utils.LOG_WARNING("Total Loss: "+(int)DURABILITY_LOSS); + //heldItem.setDamage(heldStack, DURABILITY_LOSS); + //Utils.LOG_WARNING("|GID|Durability: "+heldItem.getItemDamage()); + //Utils.LOG_WARNING("Durability: "+heldStack.getDamage(heldStack)); + if (heldItem.getItemDamage() < (heldItem.getMaxDamage()-DURABILITY_LOSS)){ + heldItem.damageItem((int) DURABILITY_LOSS, localPlayer); + } + //Utils.LOG_WARNING("|GID|Durability: "+heldItem.getItemDamage()); + DURABILITY_LOSS = 0; + + } + } + + public int doDurabilityDamage(int x){ + return x; + } + + //Should clear up blocks quicker if I chain it. + public void removeBlockAndDropAsItem(World world, int X, int Y, int Z, ItemStack heldItem){ + localWorld = world; + try { + Block block = world.getBlock(X, Y, Z); + float dur = calculateDurabilityLoss(world, X, Y, Z); + Utils.LOG_WARNING(block.toString()); + String removalTool = ""; + removalTool = block.getHarvestTool(1); + + if (removalTool.equals("pickaxe") || UtilsMining.getBlockType(block)){ + if (canPickaxeBlock(block, world)){ + if((block != Blocks.bedrock) && (block.getBlockHardness(world, X, Y, Z) != -1) && (block.getBlockHardness(world, X, Y, Z) <= 100) && (block != Blocks.water) && (block != Blocks.lava)){ + + if (heldItem.getItemDamage() <= (heldItem.getMaxDamage()-dur)){ + + block.dropBlockAsItem(world, X, Y, Z, world.getBlockMetadata(X, Y, Z), 0); + world.setBlockToAir(X, Y, Z); + + } + + } + } + else { + Utils.LOG_WARNING("Incorrect Tool for mining this block."); + } + } + } catch (NullPointerException e){ + + } + } + + public boolean checkFacing(World world){ + localWorld = world; + if (localPlayer != null){ + int direction = MathHelper.floor_double((double)((localPlayer.rotationYaw * 4F) / 360F) + 0.5D) & 3; + //Utils.LOG_WARNING("Player - F: "+direction); + //Utils.LOG_WARNING("Player - getLookVec(): "+localPlayer.getLookVec().yCoord); + + /*if (localPlayer.getLookVec().yCoord > 0){ + localPlayer.getLookVec().yCoord; + }*/ + + MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, (EntityPlayer) localPlayer, false); + if (movingobjectposition != null){ + int sideHit = movingobjectposition.sideHit; + String playerStandingPosition = ""; + if (movingobjectposition != null) { + //System.out.println("Side Hit: "+movingobjectposition.sideHit); + } + + if (sideHit == 0){ + playerStandingPosition = "above"; + FACING_HORIZONTAL = false; + } + else if (sideHit == 1){ + playerStandingPosition = "below"; + FACING_HORIZONTAL = false; + } + else if (sideHit == 2){ + playerStandingPosition = "facingSouth"; + FACING_HORIZONTAL = true; + } + else if (sideHit == 3){ + playerStandingPosition = "facingNorth"; + FACING_HORIZONTAL = true; + } + else if (sideHit == 4){ + playerStandingPosition = "facingEast"; + FACING_HORIZONTAL = true; + } + else if (sideHit == 5){ + playerStandingPosition = "facingWest"; + FACING_HORIZONTAL = true; + } + lookingDirection = playerStandingPosition; + + if (direction == 0){ + FACING = "south"; + } + else if (direction == 1){ + FACING = "west"; + } + else if (direction == 2){ + FACING = "north"; + } + else if (direction == 3){ + FACING = "east"; + } + } + + + return true; + } + return false; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(ItemStack stack, EntityPlayer aPlayer, List list, boolean bool) { + thisPickaxe = stack; + list.add(EnumChatFormatting.GOLD+"Mines a 3x3 area in the direction you are facing."); + super.addInformation(stack, aPlayer, list, bool); + } + + @Override + @SideOnly(Side.CLIENT) + public EnumRarity getRarity(ItemStack par1ItemStack){ + return EnumRarity.rare; + } + + @Override + public boolean hasEffect(ItemStack par1ItemStack){ + return true; + } + + + @Override + public boolean onBlockStartBreak(ItemStack itemstack, int X, int Y, int Z, EntityPlayer aPlayer) { + thisPickaxe = itemstack; + localPlayer = aPlayer; + checkFacing(localPlayer.worldObj); + return super.onBlockStartBreak(itemstack, X, Y, Z, aPlayer); + } + public StaballoyPickaxe(String unlocalizedName, ToolMaterial material) { + super(material); + this.setUnlocalizedName(unlocalizedName); + this.setTextureName(CORE.MODID + ":" + unlocalizedName); + this.FACING_HORIZONTAL=true; + this.setMaxStackSize(1); + this.setMaxDamage(3200); + } +} |
