force pick and shovel now have area mode

This commit is contained in:
LordMZTE 2021-04-16 23:51:17 +02:00
parent c1fdb96a7c
commit 7347b3f58b
2 changed files with 121 additions and 21 deletions

View file

@ -10,6 +10,7 @@ import ley.modding.dartcraft.item.DartItems;
import ley.modding.dartcraft.util.ForceConsumerUtils;
import ley.modding.dartcraft.util.ForceUpgradeManager;
import ley.modding.dartcraft.util.Util;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
@ -123,4 +124,49 @@ public class ItemForcePickaxe extends ItemPickaxe implements IBreakable, IForceC
return new int[] { ForceUpgradeManager.HEAT.getID(), ForceUpgradeManager.SPEED.getID(), ForceUpgradeManager.LUCK.getID(), ForceUpgradeManager.TOUCH.getID(), ForceUpgradeManager.STURDY.getID(), ForceUpgradeManager.GRINDING.getID(), ForceUpgradeManager.REPAIR.getID(), ForceUpgradeManager.IMPERVIOUS.getID() };
}
@Override
public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
World world = player.worldObj;
Block tempBlock = world.getBlock(x, y, z);
boolean force = false;
if(!this.canHarvestBlock(tempBlock, stack)) {
return false;
} else {
if(stack.hasTagCompound() && stack.getTagCompound().getBoolean("active")) {
force = true;
}
if(force) {
for(int i = -1; i < 2; ++i) {
for(int j = -1; j < 2; ++j) {
for(int k = -1; k < 2; ++k) {
if(i != 0 || j != 0 || k != 0) {
if(stack == null || stack.getItemDamage() >= stack.getMaxDamage()) {
return false;
}
this.tryBlock(stack, x + i, y + j, z + k, player);
}
}
}
}
}
if (stack != null && stack.getItemDamage() < stack.getMaxDamage())
this.tryBlock(stack, x, y, z, player);
return false;
}
}
public void tryBlock(ItemStack stack, int x, int y, int z, EntityPlayer player) {
World world = player.worldObj;
Block block = world.getBlock(x, y, z);
if (this.canHarvestBlock(block, stack) && block.getBlockHardness(world, x, y, z) > 0F & world.getTileEntity(x, y, z) == null) {
world.getBlock(x, y, z).harvestBlock(world, player, x, y, z, world.getBlockMetadata(x, y, z));
world.setBlockToAir(x, y, z);
stack.damageItem(1, player);
}
}
}

View file

@ -6,6 +6,8 @@ import ley.modding.dartcraft.api.IForceConsumer;
import ley.modding.dartcraft.item.DartItems;
import ley.modding.dartcraft.util.ForceConsumerUtils;
import ley.modding.dartcraft.util.Util;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemSpade;
import net.minecraft.item.ItemStack;
@ -20,10 +22,10 @@ public class ItemForceShovel extends ItemSpade implements IBreakable, IForceCons
private static int toolLevel = 10;
public static ToolMaterial material = EnumHelper.addToolMaterial("FORCE", toolLevel, 512, efficiency, (float) damage, 0);
public ItemForceShovel() {
super(material);
public ItemForceShovel() {
super(material);
Util.configureItem(this, "forceshovel");
}
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
@ -43,33 +45,85 @@ public class ItemForceShovel extends ItemSpade implements IBreakable, IForceCons
return stack;
}
@Override
public int getStored(ItemStack stack) {
@Override
public int getStored(ItemStack stack) {
return ForceConsumerUtils.getStoredForce(stack);
}
}
@Override
public int getMaxStored(ItemStack var1) {
return 10000;
}
@Override
public int getMaxStored(ItemStack var1) {
return 10000;
}
@Override
public int amountUsedBase(ItemStack var1) {
return 0;
}
@Override
public int amountUsedBase(ItemStack var1) {
return 0;
}
@Override
public boolean useForce(ItemStack var1, int var2, boolean var3) {
return false;
}
@Override
public boolean useForce(ItemStack var1, int var2, boolean var3) {
return false;
}
@Override
public boolean attemptRepair(ItemStack stack) {
@Override
public boolean attemptRepair(ItemStack stack) {
return ForceConsumerUtils.attemptRepair(stack);
}
}
@Override
public ItemStack itemReturned() {
return new ItemStack(DartItems.forceshard);
}
@Override
public boolean canHarvestBlock(Block block, ItemStack itemStack) {
return block.getMaterial() == Material.clay || block.getMaterial() == Material.craftedSnow || block.getMaterial() == Material.ground || block.getMaterial() == Material.sand || block.getMaterial() == Material.snow || block.getMaterial() == Material.grass;
}
@Override
public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
World world = player.worldObj;
Block tempBlock = world.getBlock(x, y, z);
boolean force = false;
if(!this.canHarvestBlock(tempBlock, stack)) {
return false;
} else {
if(stack.hasTagCompound() && stack.getTagCompound().getBoolean("active")) {
force = true;
}
if(force) {
for(int i = -1; i < 2; ++i) {
for(int j = -1; j < 2; ++j) {
for(int k = -1; k < 2; ++k) {
if(i != 0 || j != 0 || k != 0) {
if(stack == null || stack.getItemDamage() >= stack.getMaxDamage()) {
return false;
}
this.tryBlock(stack, x + i, y + j, z + k, player);
}
}
}
}
}
if (stack != null && stack.getItemDamage() < stack.getMaxDamage())
this.tryBlock(stack, x, y, z, player);
return false;
}
}
public void tryBlock(ItemStack stack, int x, int y, int z, EntityPlayer player) {
World world = player.worldObj;
Block block = world.getBlock(x, y, z);
if (this.canHarvestBlock(block, stack) && block.getBlockHardness(world, x, y, z) > 0F & world.getTileEntity(x, y, z) == null) {
world.getBlock(x, y, z).harvestBlock(world, player, x, y, z, world.getBlockMetadata(x, y, z));
world.setBlockToAir(x, y, z);
stack.damageItem(1, player);
}
}
}