Make electric tools enchantable on table. Closes #1944
This commit is contained in:
parent
0f56adbc9e
commit
1d053bb592
6 changed files with 96 additions and 75 deletions
|
@ -24,14 +24,15 @@
|
|||
|
||||
package techreborn.items.tool;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
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.item.AxeItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ToolMaterials;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -44,7 +45,6 @@ import team.reborn.energy.EnergySide;
|
|||
import team.reborn.energy.EnergyTier;
|
||||
import techreborn.TechReborn;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Random;
|
||||
|
||||
public class ChainsawItem extends AxeItem implements EnergyHolder, ItemDurabilityExtensions {
|
||||
|
@ -53,26 +53,21 @@ public class ChainsawItem extends AxeItem implements EnergyHolder, ItemDurabilit
|
|||
public int cost = 250;
|
||||
public float poweredSpeed = 20F;
|
||||
public int transferLimit = 100;
|
||||
public boolean isBreaking = false;
|
||||
|
||||
public ChainsawItem(ToolMaterials material, int energyCapacity, float unpoweredSpeed) {
|
||||
super(material, (int) material.getAttackDamage(), unpoweredSpeed, new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1));
|
||||
this.maxCharge = energyCapacity;
|
||||
|
||||
this.addPropertyGetter(new Identifier("techreborn", "animated"), new ItemPropertyGetter() {
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public float call(ItemStack stack, @Nullable World worldIn, @Nullable LivingEntity entityIn) {
|
||||
if (!stack.isEmpty() && Energy.of(stack).getEnergy() >= cost
|
||||
&& entityIn != null && entityIn.getMainHandStack().equals(stack)) {
|
||||
return 1.0F;
|
||||
}
|
||||
return 0.0F;
|
||||
this.addPropertyGetter(new Identifier("techreborn", "animated"), (stack, worldIn, entityIn) -> {
|
||||
if (!stack.isEmpty() && Energy.of(stack).getEnergy() >= cost
|
||||
&& entityIn != null && entityIn.getMainHandStack().equals(stack)) {
|
||||
return 1.0F;
|
||||
}
|
||||
return 0.0F;
|
||||
});
|
||||
}
|
||||
|
||||
// ItemAxe
|
||||
// AxeItem
|
||||
@Override
|
||||
public float getMiningSpeed(ItemStack stack, BlockState state) {
|
||||
if (Energy.of(stack).getEnergy() >= cost
|
||||
|
@ -82,7 +77,7 @@ public class ChainsawItem extends AxeItem implements EnergyHolder, ItemDurabilit
|
|||
return super.getMiningSpeed(stack, state);
|
||||
}
|
||||
|
||||
// ItemTool
|
||||
// MiningToolItem
|
||||
@Override
|
||||
public boolean postMine(ItemStack stack, World worldIn, BlockState blockIn, BlockPos pos, LivingEntity entityLiving) {
|
||||
Random rand = new Random();
|
||||
|
@ -97,6 +92,22 @@ public class ChainsawItem extends AxeItem implements EnergyHolder, ItemDurabilit
|
|||
return true;
|
||||
}
|
||||
|
||||
// ToolItem
|
||||
@Override
|
||||
public boolean canRepair(ItemStack itemStack_1, ItemStack itemStack_2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Item
|
||||
@Override
|
||||
public boolean isDamageable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnchantable(ItemStack stack) { return true; }
|
||||
|
||||
// ItemDurabilityExtensions
|
||||
@Override
|
||||
public double getDurability(ItemStack stack) {
|
||||
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
|
||||
|
@ -112,12 +123,7 @@ public class ChainsawItem extends AxeItem implements EnergyHolder, ItemDurabilit
|
|||
return PowerSystem.getDisplayPower().colour;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRepair(ItemStack itemStack_1, ItemStack itemStack_2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// IEnergyItemInfo
|
||||
// EnergyHolder
|
||||
@Override
|
||||
public double getMaxStoredPower() {
|
||||
return maxCharge;
|
||||
|
@ -137,9 +143,4 @@ public class ChainsawItem extends AxeItem implements EnergyHolder, ItemDurabilit
|
|||
public double getMaxOutput(EnergySide side) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnchantability() {
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ public class DrillItem extends PickaxeItem implements EnergyHolder, ItemDurabili
|
|||
}
|
||||
}
|
||||
|
||||
// ItemTool
|
||||
// MiningToolItem
|
||||
@Override
|
||||
public boolean postMine(ItemStack stack, World worldIn, BlockState blockIn, BlockPos pos, LivingEntity entityLiving) {
|
||||
Random rand = new Random();
|
||||
|
@ -86,17 +86,21 @@ public class DrillItem extends PickaxeItem implements EnergyHolder, ItemDurabili
|
|||
return true;
|
||||
}
|
||||
|
||||
//Item
|
||||
// ToolItem
|
||||
@Override
|
||||
public boolean canRepair(ItemStack itemStack_1, ItemStack itemStack_2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Item
|
||||
@Override
|
||||
public boolean isDamageable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnchantable(ItemStack stack) { return true; }
|
||||
|
||||
// ItemDurabilityExtensions
|
||||
@Override
|
||||
public double getDurability(ItemStack stack) {
|
||||
|
|
|
@ -88,6 +88,10 @@ public class JackhammerItem extends PickaxeItem implements EnergyHolder, ItemDur
|
|||
return false;
|
||||
}
|
||||
|
||||
// Item
|
||||
@Override
|
||||
public boolean isEnchantable(ItemStack stack) { return true; }
|
||||
|
||||
// ItemDurabilityExtensions
|
||||
@Override
|
||||
public double getDurability(ItemStack stack) {
|
||||
|
|
|
@ -62,10 +62,7 @@ public class RockCutterItem extends PickaxeItem implements EnergyHolder, ItemDur
|
|||
// PickaxeItem
|
||||
@Override
|
||||
public boolean isEffectiveOn(BlockState state) {
|
||||
if (Items.DIAMOND_PICKAXE.isEffectiveOn(state)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return Items.DIAMOND_PICKAXE.isEffectiveOn(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,6 +108,9 @@ public class RockCutterItem extends PickaxeItem implements EnergyHolder, ItemDur
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnchantable(ItemStack stack) { return true; }
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Override
|
||||
public void appendStacks(ItemGroup par2ItemGroup, DefaultedList<ItemStack> itemList) {
|
||||
|
|
|
@ -63,40 +63,33 @@ public class NanosaberItem extends SwordItem implements EnergyHolder, ItemDurabi
|
|||
// 4M FE max charge with 1k charge rate
|
||||
public NanosaberItem() {
|
||||
super(ToolMaterials.DIAMOND, 1, 1, new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1));
|
||||
this.addPropertyGetter(new Identifier("techreborn:active"), new ItemPropertyGetter() {
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public float call(ItemStack stack,
|
||||
@Nullable
|
||||
World worldIn,
|
||||
@Nullable
|
||||
LivingEntity entityIn) {
|
||||
if (ItemUtils.isActive(stack)) {
|
||||
if (Energy.of(stack).getMaxStored() - Energy.of(stack).getEnergy() >= 0.9 * Energy.of(stack).getMaxStored()) {
|
||||
return 0.5F;
|
||||
}
|
||||
return 1.0F;
|
||||
this.addPropertyGetter(new Identifier("techreborn:active"), (stack, worldIn, entityIn) -> {
|
||||
if (ItemUtils.isActive(stack)) {
|
||||
if (Energy.of(stack).getMaxStored() - Energy.of(stack).getEnergy() >= 0.9 * Energy.of(stack).getMaxStored()) {
|
||||
return 0.5F;
|
||||
}
|
||||
return 0.0F;
|
||||
return 1.0F;
|
||||
}
|
||||
return 0.0F;
|
||||
});
|
||||
}
|
||||
|
||||
// ItemSword
|
||||
// SwordItem
|
||||
@Override
|
||||
public boolean postHit(ItemStack stack, LivingEntity entityHit, LivingEntity entityHitter) {
|
||||
return Energy.of(stack).use(cost);
|
||||
}
|
||||
|
||||
// ToolItem
|
||||
@Override
|
||||
public void getAttributeModifiers(EquipmentSlot slot, ItemStack stack, Multimap<String, EntityAttributeModifier> attributes) {
|
||||
attributes.removeAll(EntityAttributes.ATTACK_DAMAGE.getId());
|
||||
attributes.removeAll(EntityAttributes.ATTACK_SPEED.getId());
|
||||
public boolean canRepair(ItemStack itemStack_1, ItemStack itemStack_2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (slot== EquipmentSlot.MAINHAND && ItemUtils.isActive(stack)) {
|
||||
attributes.put(EntityAttributes.ATTACK_DAMAGE.getId(), new EntityAttributeModifier(ATTACK_DAMAGE_MODIFIER_UUID, "Weapon modifier", 12, EntityAttributeModifier.Operation.ADDITION));
|
||||
attributes.put(EntityAttributes.ATTACK_SPEED.getId(), new EntityAttributeModifier(ATTACK_SPEED_MODIFIER_UUID, "Weapon modifier", 3, EntityAttributeModifier.Operation.ADDITION));
|
||||
}
|
||||
// Item
|
||||
@Override
|
||||
public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
|
||||
ItemUtils.checkActive(stack, cost, entityIn.world.isClient, MessageIDs.poweredToolID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -110,29 +103,12 @@ public class NanosaberItem extends SwordItem implements EnergyHolder, ItemDurabi
|
|||
}
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
|
||||
ItemUtils.checkActive(stack, cost, entityIn.world.isClient, MessageIDs.poweredToolID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRepair(ItemStack itemStack_1, ItemStack itemStack_2) {
|
||||
public boolean isDamageable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDurability(ItemStack stack) {
|
||||
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showDurability(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDurabilityColor(ItemStack stack) {
|
||||
return PowerSystem.getDisplayPower().colour;
|
||||
}
|
||||
public boolean isEnchantable(ItemStack stack) { return true; }
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Override
|
||||
|
@ -166,7 +142,7 @@ public class NanosaberItem extends SwordItem implements EnergyHolder, ItemDurabi
|
|||
ItemUtils.buildActiveTooltip(stack, tooltip);
|
||||
}
|
||||
|
||||
// IEnergyItemInfo
|
||||
// EnergyHolder
|
||||
@Override
|
||||
public double getMaxStoredPower() {
|
||||
return maxCharge;
|
||||
|
@ -186,4 +162,32 @@ public class NanosaberItem extends SwordItem implements EnergyHolder, ItemDurabi
|
|||
public double getMaxOutput(EnergySide side) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ItemDurabilityExtensions
|
||||
@Override
|
||||
public double getDurability(ItemStack stack) {
|
||||
return 1 - ItemUtils.getPowerForDurabilityBar(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showDurability(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDurabilityColor(ItemStack stack) {
|
||||
return PowerSystem.getDisplayPower().colour;
|
||||
}
|
||||
|
||||
// ItemStackModifiers
|
||||
@Override
|
||||
public void getAttributeModifiers(EquipmentSlot slot, ItemStack stack, Multimap<String, EntityAttributeModifier> attributes) {
|
||||
attributes.removeAll(EntityAttributes.ATTACK_DAMAGE.getId());
|
||||
attributes.removeAll(EntityAttributes.ATTACK_SPEED.getId());
|
||||
|
||||
if (slot== EquipmentSlot.MAINHAND && ItemUtils.isActive(stack)) {
|
||||
attributes.put(EntityAttributes.ATTACK_DAMAGE.getId(), new EntityAttributeModifier(ATTACK_DAMAGE_MODIFIER_UUID, "Weapon modifier", 12, EntityAttributeModifier.Operation.ADDITION));
|
||||
attributes.put(EntityAttributes.ATTACK_SPEED.getId(), new EntityAttributeModifier(ATTACK_SPEED_MODIFIER_UUID, "Weapon modifier", 3, EntityAttributeModifier.Operation.ADDITION));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,6 +110,14 @@ public class OmniToolItem extends PickaxeItem implements EnergyHolder, ItemDurab
|
|||
return TorchHelper.placeTorch(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnchantable(ItemStack stack) { return true; }
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Override
|
||||
public void appendStacks(ItemGroup par2ItemGroup, DefaultedList<ItemStack> itemList) {
|
||||
|
|
Loading…
Add table
Reference in a new issue