2022-09-18 21:39:42 +02:00
|
|
|
package com.minelittlepony.unicopia.item;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableMultimap;
|
|
|
|
import com.google.common.collect.Multimap;
|
2022-09-23 23:25:00 +02:00
|
|
|
import com.minelittlepony.unicopia.UTags;
|
2022-09-26 21:11:28 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.Living;
|
2022-09-18 21:39:42 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.UEntityAttributes;
|
|
|
|
|
2022-09-23 15:38:48 +02:00
|
|
|
import net.minecraft.block.*;
|
2022-09-18 21:39:42 +02:00
|
|
|
import net.minecraft.entity.EquipmentSlot;
|
2022-09-23 15:38:48 +02:00
|
|
|
import net.minecraft.entity.LivingEntity;
|
2022-09-18 21:39:42 +02:00
|
|
|
import net.minecraft.entity.attribute.*;
|
|
|
|
import net.minecraft.item.*;
|
|
|
|
|
|
|
|
public class PolearmItem extends SwordItem {
|
|
|
|
protected static final UUID ATTACK_RANGE_MODIFIER_ID = UUID.fromString("A7B3659C-AA74-469C-963A-09A391DCAA0F");
|
|
|
|
|
|
|
|
private final Multimap<EntityAttribute, EntityAttributeModifier> attributeModifiers;
|
|
|
|
|
|
|
|
private final int attackRange;
|
|
|
|
|
|
|
|
public PolearmItem(ToolMaterial material, int damage, float speed, int range, Settings settings) {
|
|
|
|
super(material, damage, speed, settings);
|
|
|
|
this.attackRange = range;
|
|
|
|
ImmutableMultimap.Builder<EntityAttribute, EntityAttributeModifier> builder = ImmutableMultimap.builder();
|
|
|
|
builder.putAll(super.getAttributeModifiers(EquipmentSlot.MAINHAND));
|
|
|
|
builder.put(UEntityAttributes.EXTENDED_REACH_DISTANCE, new EntityAttributeModifier(ATTACK_RANGE_MODIFIER_ID, "Weapon modifier", attackRange, EntityAttributeModifier.Operation.ADDITION));
|
2022-12-06 23:52:24 +01:00
|
|
|
builder.put(UEntityAttributes.EXTENDED_ATTACK_DISTANCE, new EntityAttributeModifier(ATTACK_RANGE_MODIFIER_ID, "Weapon modifier", attackRange, EntityAttributeModifier.Operation.ADDITION));
|
2022-09-18 21:39:42 +02:00
|
|
|
attributeModifiers = builder.build();
|
|
|
|
}
|
|
|
|
|
2022-09-23 15:38:48 +02:00
|
|
|
@Override
|
|
|
|
public float getMiningSpeedMultiplier(ItemStack stack, BlockState state) {
|
|
|
|
if (state.isOf(Blocks.COBWEB)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return super.getMiningSpeedMultiplier(stack, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isSuitableFor(BlockState state) {
|
2022-09-23 23:25:00 +02:00
|
|
|
return state.isIn(UTags.POLEARM_MINEABLE);
|
2022-09-23 15:38:48 +02:00
|
|
|
}
|
|
|
|
|
2022-09-18 21:39:42 +02:00
|
|
|
@Override
|
|
|
|
public Multimap<EntityAttribute, EntityAttributeModifier> getAttributeModifiers(EquipmentSlot slot) {
|
|
|
|
if (slot == EquipmentSlot.MAINHAND) {
|
|
|
|
return attributeModifiers;
|
|
|
|
}
|
|
|
|
return super.getAttributeModifiers(slot);
|
|
|
|
}
|
2022-09-23 15:38:48 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) {
|
|
|
|
boolean tooNear = target.distanceTo(attacker) <= 2;
|
|
|
|
stack.damage(tooNear ? 4 : 1, attacker, e -> e.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND));
|
|
|
|
target.takeKnockback(0.15, attacker.getX() - target.getX(), attacker.getZ() - target.getZ());
|
2022-09-26 21:11:28 +02:00
|
|
|
Living.updateVelocity(target);
|
2022-09-23 15:38:48 +02:00
|
|
|
if (tooNear) {
|
|
|
|
attacker.takeKnockback(attacker.getRandom().nextTriangular(0.4, 0.2), target.getX() - attacker.getX(), target.getZ() - attacker.getZ());
|
2022-09-26 21:11:28 +02:00
|
|
|
Living.updateVelocity(attacker);
|
2022-09-23 15:38:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2022-09-18 21:39:42 +02:00
|
|
|
}
|