Changed getDigSpeed and canHarvestBlock in AIOTs and Drill to be better

This commit is contained in:
Ellpeck 2015-07-15 05:33:02 +02:00
parent 9f20575875
commit a13892708d
2 changed files with 25 additions and 43 deletions

View file

@ -1,14 +1,12 @@
package ellpeck.actuallyadditions.items; package ellpeck.actuallyadditions.items;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import ellpeck.actuallyadditions.ActuallyAdditions; import ellpeck.actuallyadditions.ActuallyAdditions;
import ellpeck.actuallyadditions.config.values.ConfigFloatValues; import ellpeck.actuallyadditions.config.values.ConfigFloatValues;
import ellpeck.actuallyadditions.config.values.ConfigIntValues; import ellpeck.actuallyadditions.config.values.ConfigIntValues;
import ellpeck.actuallyadditions.inventory.GuiHandler; import ellpeck.actuallyadditions.inventory.GuiHandler;
import ellpeck.actuallyadditions.items.tools.ItemAllToolAA;
import ellpeck.actuallyadditions.util.INameableItem; import ellpeck.actuallyadditions.util.INameableItem;
import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.WorldUtil; import ellpeck.actuallyadditions.util.WorldUtil;
@ -22,6 +20,7 @@ import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -38,12 +37,6 @@ import java.util.Set;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class ItemDrill extends ItemEnergy implements INameableItem{ public class ItemDrill extends ItemEnergy implements INameableItem{
private static final Set allSet = Sets.newHashSet();
static{
allSet.addAll(ItemAllToolAA.pickSet);
allSet.addAll(ItemAllToolAA.shovelSet);
}
public ItemDrill(){ public ItemDrill(){
super(500000, 5000, 3); super(500000, 5000, 3);
} }
@ -211,6 +204,8 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
zRange = radius; zRange = radius;
} }
float mainHardness = world.getBlock(x, y, z).getBlockHardness(world, x, y, z);
//Break Middle Block first //Break Middle Block first
int use = this.getEnergyUsePerBlock(stack); int use = this.getEnergyUsePerBlock(stack);
if(this.getEnergyStored(stack) >= use){ if(this.getEnergyStored(stack) >= use){
@ -225,8 +220,11 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
for(int zPos = z-zRange; zPos <= z+zRange; zPos++){ for(int zPos = z-zRange; zPos <= z+zRange; zPos++){
if(!(x == xPos && y == yPos && z == zPos)){ if(!(x == xPos && y == yPos && z == zPos)){
if(this.getEnergyStored(stack) >= use){ if(this.getEnergyStored(stack) >= use){
//Only break Blocks that are (about) as hard or softer
if(world.getBlock(xPos, yPos, zPos).getBlockHardness(world, xPos, yPos, zPos) <= mainHardness+5.0F){
this.tryHarvestBlock(world, xPos, yPos, zPos, true, stack, player, use); this.tryHarvestBlock(world, xPos, yPos, zPos, true, stack, player, use);
} }
}
else return; else return;
} }
} }
@ -246,12 +244,14 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
block.onBlockHarvested(world, xPos, yPos, zPos, meta, player); block.onBlockHarvested(world, xPos, yPos, zPos, meta, player);
if(block.removedByPlayer(world, player, xPos, yPos, zPos, true)){ if(block.removedByPlayer(world, player, xPos, yPos, zPos, true)){
block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, meta); block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, meta);
block.harvestBlock(world, player, xPos, yPos, zPos, meta);
if(!player.capabilities.isCreativeMode){
block.harvestBlock(world, player, xPos, yPos, zPos, meta);
if(!EnchantmentHelper.getSilkTouchModifier(player)){ if(!EnchantmentHelper.getSilkTouchModifier(player)){
block.dropXpOnBlockBreak(world, xPos, yPos, zPos, block.getExpDrop(world, meta, EnchantmentHelper.getFortuneModifier(player))); block.dropXpOnBlockBreak(world, xPos, yPos, zPos, block.getExpDrop(world, meta, EnchantmentHelper.getFortuneModifier(player)));
} }
} }
}
if(isExtra){ if(isExtra){
world.playAuxSFX(2001, xPos, yPos, zPos, Block.getIdFromBlock(block)+(meta << 12)); world.playAuxSFX(2001, xPos, yPos, zPos, Block.getIdFromBlock(block)+(meta << 12));
@ -300,13 +300,6 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
else return true; else return true;
} }
@Override
public float func_150893_a(ItemStack stack, Block block){
if(this.getEnergyStored(stack) < this.getEnergyUsePerBlock(stack)) return 0.0F;
if(block.getMaterial() == Material.iron || block.getMaterial() == Material.anvil || block.getMaterial() == Material.rock || allSet.contains(block)) return this.getEfficiencyFromUpgrade(stack);
else return super.func_150893_a(stack, block);
}
@Override @Override
public boolean hitEntity(ItemStack stack, EntityLivingBase entity1, EntityLivingBase entity2){ public boolean hitEntity(ItemStack stack, EntityLivingBase entity1, EntityLivingBase entity2){
int use = this.getEnergyUsePerBlock(stack); int use = this.getEnergyUsePerBlock(stack);
@ -316,9 +309,14 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
return true; return true;
} }
@Override
public float getDigSpeed(ItemStack stack, Block block, int meta){
return this.getEnergyStored(stack) >= this.getEnergyUsePerBlock(stack) ? (this.getToolClasses(stack).contains(block.getHarvestTool(meta)) ? this.getEfficiencyFromUpgrade(stack) : 1.0F) : 0.0F;
}
@Override @Override
public boolean canHarvestBlock(Block block, ItemStack stack){ public boolean canHarvestBlock(Block block, ItemStack stack){
return this.func_150893_a(stack, block) > super.func_150893_a(stack, block); return this.getEnergyStored(stack) >= this.getEnergyUsePerBlock(stack) && (block.getMaterial().isToolNotRequired() || (block == Blocks.snow_layer || block == Blocks.snow || (block == Blocks.obsidian ? ToolMaterial.EMERALD.getHarvestLevel() == 3 : (block != Blocks.diamond_block && block != Blocks.diamond_ore ? (block != Blocks.emerald_ore && block != Blocks.emerald_block ? (block != Blocks.gold_block && block != Blocks.gold_ore ? (block != Blocks.iron_block && block != Blocks.iron_ore ? (block != Blocks.lapis_block && block != Blocks.lapis_ore ? (block != Blocks.redstone_ore && block != Blocks.lit_redstone_ore ? (block.getMaterial() == Material.rock || (block.getMaterial() == Material.iron || block.getMaterial() == Material.anvil)) : ToolMaterial.EMERALD.getHarvestLevel() >= 2) : ToolMaterial.EMERALD.getHarvestLevel() >= 1) : ToolMaterial.EMERALD.getHarvestLevel() >= 1) : ToolMaterial.EMERALD.getHarvestLevel() >= 2) : ToolMaterial.EMERALD.getHarvestLevel() >= 2) : ToolMaterial.EMERALD.getHarvestLevel() >= 2))));
} }
@Override @Override
@ -336,17 +334,12 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
@Override @Override
public Set<String> getToolClasses(ItemStack stack){ public Set<String> getToolClasses(ItemStack stack){
HashSet<String> hashSet = new HashSet<String>(); HashSet<String> hashSet = new HashSet<>();
hashSet.add("pickaxe"); hashSet.add("pickaxe");
hashSet.add("shovel"); hashSet.add("shovel");
return hashSet; return hashSet;
} }
@Override
public float getDigSpeed(ItemStack stack, Block block, int meta){
return this.func_150893_a(stack, block);
}
@Override @Override
public Multimap getAttributeModifiers(ItemStack stack){ public Multimap getAttributeModifiers(ItemStack stack){
Multimap map = super.getAttributeModifiers(stack); Multimap map = super.getAttributeModifiers(stack);

View file

@ -30,23 +30,12 @@ import java.util.Set;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class ItemAllToolAA extends ItemTool implements INameableItem{ public class ItemAllToolAA extends ItemTool implements INameableItem{
public static final Set axeSet = Sets.newHashSet(Blocks.planks, Blocks.bookshelf, Blocks.log, Blocks.log2, Blocks.chest, Blocks.pumpkin, Blocks.lit_pumpkin);
public static final Set pickSet = Sets.newHashSet(Blocks.cobblestone, Blocks.double_stone_slab, Blocks.stone_slab, Blocks.stone, Blocks.sandstone, Blocks.mossy_cobblestone, Blocks.iron_ore, Blocks.iron_block, Blocks.coal_ore, Blocks.gold_block, Blocks.gold_ore, Blocks.diamond_ore, Blocks.diamond_block, Blocks.ice, Blocks.netherrack, Blocks.lapis_ore, Blocks.lapis_block, Blocks.redstone_ore, Blocks.lit_redstone_ore, Blocks.rail, Blocks.detector_rail, Blocks.golden_rail, Blocks.activator_rail);
public static final Set shovelSet = Sets.newHashSet(Blocks.grass, Blocks.dirt, Blocks.sand, Blocks.gravel, Blocks.snow_layer, Blocks.snow, Blocks.clay, Blocks.farmland, Blocks.soul_sand, Blocks.mycelium);
private static final Set allSet = Sets.newHashSet();
static{
allSet.addAll(axeSet);
allSet.addAll(pickSet);
allSet.addAll(shovelSet);
}
private String name; private String name;
private EnumRarity rarity; private EnumRarity rarity;
private String repairItem; private String repairItem;
public ItemAllToolAA(ToolMaterial toolMat, String repairItem, String unlocalizedName, EnumRarity rarity){ public ItemAllToolAA(ToolMaterial toolMat, String repairItem, String unlocalizedName, EnumRarity rarity){
super(4.0F, toolMat, allSet); super(4.0F, toolMat, Sets.newHashSet());
this.repairItem = repairItem; this.repairItem = repairItem;
this.name = unlocalizedName; this.name = unlocalizedName;
@ -56,13 +45,13 @@ public class ItemAllToolAA extends ItemTool implements INameableItem{
} }
@Override @Override
public float func_150893_a(ItemStack stack, Block block){ public float getDigSpeed(ItemStack stack, Block block, int meta){
return block.getMaterial() != Material.iron && block.getMaterial() != Material.anvil && block.getMaterial() != Material.rock && block.getMaterial() != Material.wood && block.getMaterial() != Material.plants && block.getMaterial() != Material.vine ? super.func_150893_a(stack, block) : this.efficiencyOnProperMaterial; return this.getToolClasses(stack).contains(block.getHarvestTool(meta)) ? this.efficiencyOnProperMaterial : 1.0F;
} }
@Override @Override
public boolean func_150897_b(Block block){ public boolean canHarvestBlock(Block block, ItemStack stack){
return block == Blocks.snow_layer || block == Blocks.snow || (block == Blocks.obsidian ? this.toolMaterial.getHarvestLevel() == 3 : (block != Blocks.diamond_block && block != Blocks.diamond_ore ? (block != Blocks.emerald_ore && block != Blocks.emerald_block ? (block != Blocks.gold_block && block != Blocks.gold_ore ? (block != Blocks.iron_block && block != Blocks.iron_ore ? (block != Blocks.lapis_block && block != Blocks.lapis_ore ? (block != Blocks.redstone_ore && block != Blocks.lit_redstone_ore ? (block.getMaterial() == Material.rock || (block.getMaterial() == Material.iron || block.getMaterial() == Material.anvil)) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2)); return block.getMaterial().isToolNotRequired() || (block == Blocks.snow_layer || block == Blocks.snow || (block == Blocks.obsidian ? this.toolMaterial.getHarvestLevel() == 3 : (block != Blocks.diamond_block && block != Blocks.diamond_ore ? (block != Blocks.emerald_ore && block != Blocks.emerald_block ? (block != Blocks.gold_block && block != Blocks.gold_ore ? (block != Blocks.iron_block && block != Blocks.iron_ore ? (block != Blocks.lapis_block && block != Blocks.lapis_ore ? (block != Blocks.redstone_ore && block != Blocks.lit_redstone_ore ? (block.getMaterial() == Material.rock || (block.getMaterial() == Material.iron || block.getMaterial() == Material.anvil)) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2)));
} }
@Override @Override
@ -134,7 +123,7 @@ public class ItemAllToolAA extends ItemTool implements INameableItem{
@Override @Override
public Set<String> getToolClasses(ItemStack stack){ public Set<String> getToolClasses(ItemStack stack){
HashSet<String> hashSet = new HashSet<String>(); HashSet<String> hashSet = new HashSet<>();
hashSet.add("pickaxe"); hashSet.add("pickaxe");
hashSet.add("axe"); hashSet.add("axe");
hashSet.add("shovel"); hashSet.add("shovel");