Continue mapping migration

This commit is contained in:
Aleksey 2021-04-12 21:38:22 +03:00
parent 99ade39404
commit f03fd03bd0
499 changed files with 12567 additions and 12723 deletions

View file

@ -9,90 +9,89 @@ import com.google.common.collect.Sets;
import io.netty.util.internal.ThreadLocalRandom;
import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool;
import net.minecraft.core.BlockPos;
import net.minecraft.tags.Tag;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
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.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.tags.Tag;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import ru.betterend.patterns.Patterned;
import ru.betterend.patterns.Patterns;
import ru.betterend.registry.EndTags;
public class EndHammerItem extends DiggerItem implements DynamicAttributeTool, Patterned {
public final static UUID ATTACK_KNOCKBACK_MODIFIER_ID = Mth.createInsecureUUID(ThreadLocalRandom.current());
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<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));
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 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);
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 hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
stack.hurtAndBreak(1, attacker, (entity -> {
stack.hurtAndBreak(1, attacker, ((entity) -> {
entity.broadcastBreakEvent(EquipmentSlot.MAINHAND);
}));
return true;
}
@Override
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 -> {
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 getTier().getSpeed() * 2.0F;
return this.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 = getTier().getSpeed();
if (state.is(Blocks.DIAMOND_BLOCK) || state.is(Blocks.EMERALD_BLOCK) || state.is(Blocks.LAPIS_BLOCK) || state.is(Blocks.REDSTONE_BLOCK)) {
mult = this.getTier().getSpeed();
} else {
mult = getTier().getSpeed() / 2.0F;
mult = this.getTier().getSpeed() / 2.0F;
}
return Math.max(mult, 1.0F);
return mult > 1.0F ? mult : 1.0F;
}
return 1.0F;
}
@Override
public float getMiningSpeedMultiplier(Tag<Item> tag, BlockState state, ItemStack stack, LivingEntity user) {
if (tag.equals(EndTags.HAMMERS)) {
@ -100,7 +99,7 @@ public class EndHammerItem extends DiggerItem implements DynamicAttributeTool, P
}
return 1.0F;
}
@Override
public int getMiningLevel(Tag<Item> tag, BlockState state, ItemStack stack, LivingEntity user) {
if (tag.equals(EndTags.HAMMERS)) {
@ -114,20 +113,17 @@ public class EndHammerItem extends DiggerItem implements DynamicAttributeTool, P
if (state.getMaterial().equals(Material.GLASS)) {
return true;
}
if (!state.is(Blocks.REDSTONE_BLOCK) && !state.is(Blocks.DIAMOND_BLOCK) && !state.is(Blocks.EMERALD_BLOCK)
&& !state.is(Blocks.LAPIS_BLOCK) && !state.getMaterial().equals(Material.STONE)) {
if (!state.is(Blocks.REDSTONE_BLOCK) && !state.is(Blocks.DIAMOND_BLOCK) && !state.is(Blocks.EMERALD_BLOCK) && !state.is(Blocks.LAPIS_BLOCK) && !state.getMaterial().equals(Material.STONE)) {
return false;
}
int level = this.getTier().getLevel();
if (state.is(Blocks.IRON_ORE) || state.is(Blocks.LAPIS_BLOCK) || state.is(Blocks.LAPIS_ORE)) {
return level >= 1;
}
if (state.is(Blocks.DIAMOND_BLOCK) && !state.is(Blocks.DIAMOND_ORE) || state.is(Blocks.EMERALD_ORE)
|| state.is(Blocks.EMERALD_BLOCK) || state.is(Blocks.GOLD_ORE) || state.is(Blocks.REDSTONE_ORE)) {
if (state.is(Blocks.DIAMOND_BLOCK) && !state.is(Blocks.DIAMOND_ORE) || state.is(Blocks.EMERALD_ORE) || state.is(Blocks.EMERALD_BLOCK) || state.is(Blocks.GOLD_ORE) || state.is(Blocks.REDSTONE_ORE)) {
return level >= 2;
}
if (state.is(Blocks.OBSIDIAN) || state.is(Blocks.CRYING_OBSIDIAN) || state.is(Blocks.RESPAWN_ANCHOR)
|| state.is(Blocks.ANCIENT_DEBRIS)) {
if (state.is(Blocks.OBSIDIAN) || state.is(Blocks.CRYING_OBSIDIAN) || state.is(Blocks.RESPAWN_ANCHOR) || state.is(Blocks.ANCIENT_DEBRIS)) {
return level >= 3;
}
return true;
@ -137,7 +133,7 @@ public class EndHammerItem extends DiggerItem implements DynamicAttributeTool, P
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlot slot) {
return slot == EquipmentSlot.MAINHAND ? this.attributeModifiers : super.getDefaultAttributeModifiers(slot);
}
@Override
public String getModelPattern(String name) {
return Patterns.createJson(Patterns.ITEM_HANDHELD, name);