Cleanup jackhammer code a bit

This commit is contained in:
modmuss50 2020-07-26 16:08:19 +01:00
parent a1e3df3c4a
commit bbc9dd3b37
4 changed files with 32 additions and 39 deletions

View file

@ -185,7 +185,7 @@ public class ModRegistry {
RebornRegistry.registerItem(TRContent.BASIC_DRILL = InitUtils.setup(new DrillItem(ToolMaterials.IRON, TechRebornConfig.basicDrillCharge, EnergyTier.MEDIUM, TechRebornConfig.basicDrillCost, 6F, -.5F, MiningLevel.IRON), "basic_drill"));
RebornRegistry.registerItem(TRContent.BASIC_CHAINSAW = InitUtils.setup(new ChainsawItem(ToolMaterials.IRON, TechRebornConfig.basicChainsawCharge, EnergyTier.MEDIUM, TechRebornConfig.basicChainsawCost, 20F, 0.5F, Items.IRON_AXE), "basic_chainsaw"));
RebornRegistry.registerItem(TRContent.BASIC_JACKHAMMER = InitUtils.setup(new JackhammerItem(ToolMaterials.DIAMOND, TechRebornConfig.basicJackhammerCharge, EnergyTier.MEDIUM, TechRebornConfig.basicJackhammerCost), "basic_jackhammer"));
RebornRegistry.registerItem(TRContent.BASIC_JACKHAMMER = InitUtils.setup(new JackhammerItem(ToolMaterials.DIAMOND, TechRebornConfig.basicJackhammerCharge, EnergyTier.MEDIUM, TechRebornConfig.basicJackhammerCost, MiningLevel.IRON), "basic_jackhammer"));
RebornRegistry.registerItem(TRContent.ELECTRIC_TREE_TAP = InitUtils.setup(new ElectricTreetapItem(), "electric_treetap"));
RebornRegistry.registerItem(TRContent.ADVANCED_DRILL = InitUtils.setup(new DrillItem(ToolMaterials.DIAMOND, TechRebornConfig.advancedDrillCharge, EnergyTier.EXTREME, TechRebornConfig.advancedDrillCost, 12F, 0.2F, MiningLevel.DIAMOND), "advanced_drill"));

View file

@ -24,12 +24,15 @@
package techreborn.items.tool;
import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.*;
import net.minecraft.tag.Tag;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -45,26 +48,38 @@ import techreborn.utils.InitUtils;
import java.util.Random;
public class JackhammerItem extends PickaxeItem implements EnergyHolder, ItemDurabilityExtensions {
public class JackhammerItem extends PickaxeItem implements EnergyHolder, ItemDurabilityExtensions, DynamicAttributeTool {
public final int maxCharge;
public final int cost;
public final EnergyTier tier;
public final MiningLevel miningLevel;
public JackhammerItem(ToolMaterials material, int energyCapacity, EnergyTier tier, int cost) {
public JackhammerItem(ToolMaterials material, int energyCapacity, EnergyTier tier, int cost, MiningLevel miningLevel) {
super(material, (int) material.getAttackDamage(), 1F, new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1).maxDamage(-1));
this.maxCharge = energyCapacity;
this.cost = cost;
this.tier = tier;
this.miningLevel = miningLevel;
}
// PickaxeItem
@Override
public float getMiningSpeedMultiplier(ItemStack stack, BlockState state) {
if (state.getMaterial() == Material.STONE && Energy.of(stack).getEnergy() >= cost) {
public float getMiningSpeedMultiplier(Tag<Item> tag, BlockState state, ItemStack stack, LivingEntity user) {
if (tag.equals(FabricToolTags.PICKAXES) && stack.getItem().isEffectiveOn(state)) {
if (Energy.of(stack).getEnergy() >= cost) {
return miningSpeed;
}
return 0.5F;
}
return 0;
}
@Override
public int getMiningLevel(Tag<Item> tag, BlockState state, ItemStack stack, LivingEntity user) {
if (tag.equals(FabricToolTags.PICKAXES)) {
return miningLevel.intLevel;
}
return 0;
}
// MiningToolItem

View file

@ -46,6 +46,7 @@ import reborncore.common.util.ItemUtils;
import team.reborn.energy.EnergyTier;
import techreborn.config.TechRebornConfig;
import techreborn.items.tool.JackhammerItem;
import techreborn.items.tool.MiningLevel;
import techreborn.utils.MessageIDs;
import techreborn.utils.ToolsUtil;
@ -55,27 +56,15 @@ import java.util.List;
public class AdvancedJackhammerItem extends JackhammerItem {
public AdvancedJackhammerItem() {
super(ToolMaterials.DIAMOND, TechRebornConfig.advancedJackhammerCharge, EnergyTier.EXTREME, TechRebornConfig.advancedJackhammerCost);
super(ToolMaterials.DIAMOND, TechRebornConfig.advancedJackhammerCharge, EnergyTier.EXTREME, TechRebornConfig.advancedJackhammerCost, MiningLevel.DIAMOND);
}
private boolean shouldBreak(World worldIn, BlockPos originalPos, BlockPos pos) {
private boolean shouldBreak(World worldIn, BlockPos originalPos, BlockPos pos, ItemStack stack) {
if (originalPos.equals(pos)) {
return false;
}
BlockState blockState = worldIn.getBlockState(pos);
if (blockState.getMaterial() == Material.AIR) {
return false;
}
if (blockState.getMaterial().isLiquid()) {
return false;
}
if (blockState.getBlock() instanceof OreBlock) {
return false;
}
if (blockState.getBlock() instanceof RedstoneOreBlock) {
return false;
}
return (Items.IRON_PICKAXE.isEffectiveOn(blockState));
return (stack.getItem().isEffectiveOn(blockState));
}
// JackhammerItem
@ -85,7 +74,7 @@ public class AdvancedJackhammerItem extends JackhammerItem {
return super.postMine(stack, worldIn, stateIn, pos, entityLiving);
}
for (BlockPos additionalPos : ToolsUtil.getAOEMiningBlocks(worldIn, pos, entityLiving, 1)) {
if (shouldBreak(worldIn, pos, additionalPos)) {
if (shouldBreak(worldIn, pos, additionalPos, stack)) {
ToolsUtil.breakBlock(stack, worldIn, additionalPos, entityLiving, cost);
}
}

View file

@ -51,6 +51,7 @@ import team.reborn.energy.Energy;
import team.reborn.energy.EnergyTier;
import techreborn.config.TechRebornConfig;
import techreborn.items.tool.JackhammerItem;
import techreborn.items.tool.MiningLevel;
import techreborn.utils.MessageIDs;
import techreborn.utils.ToolsUtil;
@ -60,7 +61,7 @@ import java.util.List;
public class IndustrialJackhammerItem extends JackhammerItem {
public IndustrialJackhammerItem() {
super(ToolMaterials.DIAMOND, TechRebornConfig.industrialJackhammerCharge, EnergyTier.INSANE, TechRebornConfig.industrialJackhammerCost);
super(ToolMaterials.DIAMOND, TechRebornConfig.industrialJackhammerCharge, EnergyTier.INSANE, TechRebornConfig.industrialJackhammerCost, MiningLevel.DIAMOND);
}
// Cycle Inactive, Active 3*3 and Active 5*5
@ -85,24 +86,12 @@ public class IndustrialJackhammerItem extends JackhammerItem {
}
}
private boolean shouldBreak(World worldIn, BlockPos originalPos, BlockPos pos) {
private boolean shouldBreak(World worldIn, BlockPos originalPos, BlockPos pos, ItemStack stack) {
if (originalPos.equals(pos)) {
return false;
}
BlockState blockState = worldIn.getBlockState(pos);
if (blockState.getMaterial() == Material.AIR) {
return false;
}
if (blockState.getMaterial().isLiquid()) {
return false;
}
if (blockState.getBlock() instanceof OreBlock) {
return false;
}
if (blockState.getBlock() instanceof RedstoneOreBlock) {
return false;
}
return (Items.IRON_PICKAXE.isEffectiveOn(blockState));
return (stack.getItem().isEffectiveOn(blockState));
}
private boolean isAOE5(ItemStack stack) {
@ -117,7 +106,7 @@ public class IndustrialJackhammerItem extends JackhammerItem {
}
int radius = isAOE5(stack) ? 2 : 1;
for (BlockPos additionalPos : ToolsUtil.getAOEMiningBlocks(worldIn, pos, entityLiving, radius)) {
if (shouldBreak(worldIn, pos, additionalPos)) {
if (shouldBreak(worldIn, pos, additionalPos, stack)) {
ToolsUtil.breakBlock(stack, worldIn, additionalPos, entityLiving, cost);
}
}