Continue migration
This commit is contained in:
parent
47ed597358
commit
33dbfbe633
263 changed files with 1450 additions and 1486 deletions
|
@ -9,18 +9,19 @@ import com.google.common.collect.Sets;
|
|||
|
||||
import io.netty.util.internal.ThreadLocalRandom;
|
||||
import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool;
|
||||
import net.minecraft.world.entity.ai.attributes.Attribute;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.DiggerItem;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.attribute.EntityAttribute;
|
||||
import net.minecraft.world.entity.attribute.EntityAttributeModifier;
|
||||
import net.minecraft.world.entity.attribute.EntityAttributes;
|
||||
import net.minecraft.world.entity.player.PlayerEntity;
|
||||
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.MiningToolItem;
|
||||
import net.minecraft.world.item.Tier;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
@ -30,72 +31,70 @@ import ru.betterend.patterns.Patterned;
|
|||
import ru.betterend.patterns.Patterns;
|
||||
import ru.betterend.registry.EndTags;
|
||||
|
||||
public class EndHammerItem extends MiningToolItem implements DynamicAttributeTool, Patterned {
|
||||
public final static UUID ATTACK_KNOCKBACK_MODIFIER_ID = Mth.randomUuid(ThreadLocalRandom.current());
|
||||
public class EndHammerItem extends DiggerItem implements DynamicAttributeTool, Patterned {
|
||||
public final static UUID ATTACK_KNOCKBACK_MODIFIER_ID = Mth.createInsecureUUID(ThreadLocalRandom.current());
|
||||
|
||||
private final Multimap<EntityAttribute, EntityAttributeModifier> attributeModifiers;
|
||||
private final Multimap<Attribute, AttributeModifier> attributeModifiers;
|
||||
|
||||
public EndHammerItem(Tier material, float attackDamage, float attackSpeed, double knockback, Properties settings) {
|
||||
super(attackDamage, attackSpeed, material, Sets.newHashSet(), settings);
|
||||
|
||||
Builder<EntityAttribute, EntityAttributeModifier> builder = ImmutableMultimap.builder();
|
||||
builder.put(EntityAttributes.GENERIC_ATTACK_DAMAGE,
|
||||
new EntityAttributeModifier(ATTACK_DAMAGE_MODIFIER_ID, "Weapon modifier",
|
||||
attackDamage + material.getAttackDamage(), EntityAttributeModifier.Operation.ADDITION));
|
||||
builder.put(EntityAttributes.GENERIC_ATTACK_SPEED, new EntityAttributeModifier(ATTACK_SPEED_MODIFIER_ID,
|
||||
"Weapon modifier", attackSpeed, EntityAttributeModifier.Operation.ADDITION));
|
||||
builder.put(EntityAttributes.GENERIC_ATTACK_KNOCKBACK, new EntityAttributeModifier(ATTACK_KNOCKBACK_MODIFIER_ID,
|
||||
"Weapon modifier", knockback, EntityAttributeModifier.Operation.ADDITION));
|
||||
Builder<Attribute, AttributeModifier> builder = ImmutableMultimap.builder();
|
||||
builder.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Weapon modifier",
|
||||
attackDamage + material.getAttackDamageBonus(), AttributeModifier.Operation.ADDITION));
|
||||
builder.put(Attributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Weapon modifier",
|
||||
attackSpeed, AttributeModifier.Operation.ADDITION));
|
||||
builder.put(Attributes.ATTACK_KNOCKBACK, new AttributeModifier(ATTACK_KNOCKBACK_MODIFIER_ID, "Weapon modifier",
|
||||
knockback, AttributeModifier.Operation.ADDITION));
|
||||
this.attributeModifiers = builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMine(BlockState state, Level world, BlockPos pos, PlayerEntity miner) {
|
||||
public boolean canAttackBlock(BlockState state, Level world, BlockPos pos, Player miner) {
|
||||
return state.getMaterial().equals(Material.STONE) || state.getMaterial().equals(Material.GLASS)
|
||||
|| state.is(Blocks.DIAMOND_BLOCK) || state.is(Blocks.EMERALD_BLOCK) || state.is(Blocks.LAPIS_BLOCK)
|
||||
|| state.is(Blocks.REDSTONE_BLOCK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) {
|
||||
stack.damage(1, attacker, ((entity) -> {
|
||||
entity.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND);
|
||||
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
|
||||
stack.hurtAndBreak(1, attacker, (entity -> {
|
||||
entity.broadcastBreakEvent(EquipmentSlot.MAINHAND);
|
||||
}));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean postMine(ItemStack stack, Level world, BlockState state, BlockPos pos, LivingEntity miner) {
|
||||
if (state.getHardness(world, pos) != 0.0F) {
|
||||
stack.damage(1, miner, ((entity) -> {
|
||||
entity.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND);
|
||||
public boolean mineBlock(ItemStack stack, Level world, BlockState state, BlockPos pos, LivingEntity miner) {
|
||||
if (state.getDestroySpeed(world, pos) != 0.0F) {
|
||||
stack.hurtAndBreak(1, miner, (entity -> {
|
||||
entity.broadcastBreakEvent(EquipmentSlot.MAINHAND);
|
||||
}));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDestroySpeed(ItemStack stack, BlockState state) {
|
||||
if (state.getMaterial().equals(Material.GLASS)) {
|
||||
return this.getMaterial().getDestroySpeed() * 2.0F;
|
||||
return getTier().getSpeed() * 2.0F;
|
||||
}
|
||||
if (isCorrectToolForDrops(state)) {
|
||||
float mult = 1.0F;
|
||||
if (state.is(Blocks.DIAMOND_BLOCK) || state.is(Blocks.EMERALD_BLOCK) || state.is(Blocks.LAPIS_BLOCK)
|
||||
|| state.is(Blocks.REDSTONE_BLOCK)) {
|
||||
mult = this.getMaterial().getDestroySpeed();
|
||||
mult = getTier().getSpeed();
|
||||
} else {
|
||||
mult = this.getMaterial().getDestroySpeed() / 2.0F;
|
||||
mult = getTier().getSpeed() / 2.0F;
|
||||
}
|
||||
return mult > 1.0F ? mult : 1.0F;
|
||||
return Math.max(mult, 1.0F);
|
||||
}
|
||||
return 1.0F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDestroySpeed(Tag<Item> tag, BlockState state, ItemStack stack, LivingEntity user) {
|
||||
public float getMiningSpeedMultiplier(Tag<Item> tag, BlockState state, ItemStack stack, LivingEntity user) {
|
||||
if (tag.equals(EndTags.HAMMERS)) {
|
||||
return this.getDestroySpeed(stack, state);
|
||||
}
|
||||
|
@ -135,8 +134,8 @@ public class EndHammerItem extends MiningToolItem implements DynamicAttributeToo
|
|||
}
|
||||
|
||||
@Override
|
||||
public Multimap<EntityAttribute, EntityAttributeModifier> getAttributeModifiers(EquipmentSlot slot) {
|
||||
return slot == EquipmentSlot.MAINHAND ? this.attributeModifiers : super.getAttributeModifiers(slot);
|
||||
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlot slot) {
|
||||
return slot == EquipmentSlot.MAINHAND ? this.attributeModifiers : super.getDefaultAttributeModifiers(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue