Fix drill speed on non-stone blocks. Closes #2225

This commit is contained in:
drcrazy 2020-10-03 21:38:15 +03:00
parent a4bceb32a8
commit 3a159d7437
2 changed files with 20 additions and 12 deletions

View file

@ -30,7 +30,6 @@ import net.minecraft.block.BlockState;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*;
import net.minecraft.tag.Tag;
import net.minecraft.util.collection.DefaultedList;
@ -69,10 +68,10 @@ public class DrillItem extends PickaxeItem implements EnergyHolder, ItemDurabili
public float getMiningSpeedMultiplier(ItemStack stack, BlockState state) {
// Going to remain to use this ol reliable function, the fabric one is funky
if(Energy.of(stack).getEnergy() >= cost ) {
if (Energy.of(stack).getEnergy() >= cost) {
if (stack.getItem().isEffectiveOn(state)) {
return poweredSpeed;
}else{
} else {
return Math.min(unpoweredSpeed * 10f, poweredSpeed); // Still be faster than unpowered when not effective
}
}
@ -80,6 +79,22 @@ public class DrillItem extends PickaxeItem implements EnergyHolder, ItemDurabili
return unpoweredSpeed;
}
// PickaxeItem
@Override
public boolean isEffectiveOn(BlockState blockIn) {
if (Items.DIAMOND_PICKAXE.isEffectiveOn(blockIn)) {
return true;
}
if (Items.DIAMOND_SHOVEL.isEffectiveOn(blockIn)) {
return true;
}
// More checks to fix #2225
if (Items.DIAMOND_SHOVEL.getMiningSpeedMultiplier(null, blockIn) > 1.0f) {
return true;
}
return Items.DIAMOND_PICKAXE.getMiningSpeedMultiplier(null, blockIn) > 1.0f;
}
// MiningToolItem
@Override
public boolean postMine(ItemStack stack, World worldIn, BlockState blockIn, BlockPos pos, LivingEntity entityLiving) {
@ -116,7 +131,7 @@ public class DrillItem extends PickaxeItem implements EnergyHolder, ItemDurabili
@Override
public int getMiningLevel(Tag<Item> tag, BlockState state, ItemStack stack, LivingEntity user) {
if (tag.equals(FabricToolTags.PICKAXES)) {
if (tag.equals(FabricToolTags.PICKAXES) || tag.equals(FabricToolTags.SHOVELS)) {
return miningLevel;
}
return 0;

View file

@ -33,7 +33,6 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.ToolMaterials;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
@ -42,6 +41,7 @@ import net.minecraft.util.TypedActionResult;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.common.util.ItemUtils;
import team.reborn.energy.EnergyTier;
import techreborn.config.TechRebornConfig;
@ -52,7 +52,6 @@ import techreborn.utils.InitUtils;
import techreborn.utils.MessageIDs;
import techreborn.utils.ToolsUtil;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class IndustrialDrillItem extends DrillItem {
@ -99,12 +98,6 @@ public class IndustrialDrillItem extends DrillItem {
return super.postMine(stack, worldIn, stateIn, pos, entityLiving);
}
// PickaxeItem
@Override
public boolean isEffectiveOn(BlockState blockIn) {
return (Items.DIAMOND_PICKAXE.isEffectiveOn(blockIn) || Items.DIAMOND_SHOVEL.isEffectiveOn(blockIn)) && !Items.DIAMOND_AXE.isEffectiveOn(blockIn);
}
// Item
@Override
public TypedActionResult<ItemStack> use(final World world, final PlayerEntity player, final Hand hand) {