Reorganized Imports/Packages

This commit is contained in:
Frank 2022-05-18 23:56:18 +02:00
parent a8beba9196
commit 770a5b4046
854 changed files with 42775 additions and 41811 deletions

View file

@ -0,0 +1,99 @@
package org.betterx.betterend.item;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.*;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.client.model.FabricModelPredicateProviderRegistry;
import org.betterx.bclib.items.BaseArmorItem;
import org.betterx.betterend.BetterEnd;
import org.betterx.betterend.interfaces.FallFlyingItem;
import org.betterx.betterend.interfaces.MultiModelItem;
import org.betterx.betterend.registry.EndItems;
public class ArmoredElytra extends BaseArmorItem implements MultiModelItem, FallFlyingItem {
private final ResourceLocation wingTexture;
private final Item repairItem;
private final double movementFactor;
private final float toughness;
private final int defense;
public ArmoredElytra(String name,
ArmorMaterial material,
Item repairItem,
int durability,
double movementFactor,
boolean fireproof) {
super(
material,
EquipmentSlot.CHEST,
fireproof ? EndItems
.makeEndItemSettings()
.durability(durability)
.rarity(Rarity.EPIC)
.fireResistant() : EndItems.makeEndItemSettings().durability(durability).rarity(Rarity.EPIC)
);
this.wingTexture = BetterEnd.makeID("textures/entity/" + name + ".png");
this.repairItem = repairItem;
this.movementFactor = movementFactor;
this.defense = (int) ((double) material.getDefenseForSlot(EquipmentSlot.CHEST) / 1.75);
this.toughness = material.getToughness() / 1.75F;
addAttributeModifier(
Attributes.ARMOR,
new AttributeModifier(ARMOR_MODIFIER_UUID_PER_SLOT[2],
"Armor modifier",
defense,
AttributeModifier.Operation.ADDITION
)
);
addAttributeModifier(
Attributes.ARMOR_TOUGHNESS,
new AttributeModifier(ARMOR_MODIFIER_UUID_PER_SLOT[2],
"Armor toughness",
toughness,
AttributeModifier.Operation.ADDITION
)
);
}
@Override
public double getMovementFactor() {
return movementFactor;
}
@Override
@Environment(EnvType.CLIENT)
public ResourceLocation getModelTexture() {
return wingTexture;
}
@Override
public boolean isValidRepairItem(ItemStack itemStack, ItemStack itemStack2) {
return super.isValidRepairItem(itemStack, itemStack2) || itemStack2.getItem() == repairItem;
}
@Override
public int getDefense() {
return defense;
}
@Override
public float getToughness() {
return toughness;
}
@Override
@Environment(EnvType.CLIENT)
public void registerModelPredicate() {
FabricModelPredicateProviderRegistry.register(
this,
new ResourceLocation("broken"),
(itemStack, clientLevel, livingEntity, id) -> ElytraItem.isFlyEnabled(itemStack) ? 0.0F : 1.0F
);
}
}

View file

@ -0,0 +1,47 @@
package org.betterx.betterend.item;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import org.betterx.bclib.items.BaseArmorItem;
import org.betterx.betterend.effects.EndStatusEffects;
import org.betterx.betterend.item.material.EndArmorMaterial;
public class CrystaliteArmor extends BaseArmorItem {
public final static MutableComponent CHEST_DESC;
public final static MutableComponent BOOTS_DESC;
public CrystaliteArmor(EquipmentSlot equipmentSlot, Properties settings) {
super(EndArmorMaterial.CRYSTALITE, equipmentSlot, settings);
}
public static boolean hasFullSet(LivingEntity owner) {
for (ItemStack armorStack : owner.getArmorSlots()) {
if (!(armorStack.getItem() instanceof CrystaliteArmor)) {
return false;
}
}
return true;
}
public static void applySetEffect(LivingEntity owner) {
if ((owner.tickCount & 63) == 0) {
owner.addEffect(new MobEffectInstance(EndStatusEffects.CRYSTALITE_HEALTH_REGEN));
}
}
static {
Style descStyle = Style.EMPTY.applyFormats(ChatFormatting.DARK_AQUA, ChatFormatting.ITALIC);
CHEST_DESC = Component.translatable("tooltip.armor.crystalite_chest");
CHEST_DESC.setStyle(descStyle);
BOOTS_DESC = Component.translatable("tooltip.armor.crystalite_boots");
BOOTS_DESC.setStyle(descStyle);
}
}

View file

@ -0,0 +1,42 @@
package org.betterx.betterend.item;
import net.minecraft.network.chat.Component;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.betterx.betterend.effects.EndStatusEffects;
import org.betterx.betterend.interfaces.MobEffectApplier;
import org.betterx.betterend.registry.EndItems;
import java.util.List;
import org.jetbrains.annotations.Nullable;
public class CrystaliteBoots extends CrystaliteArmor implements MobEffectApplier {
public CrystaliteBoots() {
super(EquipmentSlot.FEET, EndItems.makeEndItemSettings().rarity(Rarity.RARE));
}
@Override
public void applyEffect(LivingEntity owner) {
if ((owner.tickCount & 63) == 0) {
owner.addEffect(new MobEffectInstance(EndStatusEffects.CRYSTALITE_MOVE_SPEED));
}
}
@Override
@Environment(EnvType.CLIENT)
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> lines, TooltipFlag tooltip) {
super.appendHoverText(stack, level, lines, tooltip);
lines.add(1, Component.empty());
lines.add(2, BOOTS_DESC);
}
}

View file

@ -0,0 +1,40 @@
package org.betterx.betterend.item;
import net.minecraft.network.chat.Component;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.betterx.betterend.effects.EndStatusEffects;
import org.betterx.betterend.interfaces.MobEffectApplier;
import org.betterx.betterend.registry.EndItems;
import java.util.List;
import org.jetbrains.annotations.Nullable;
public class CrystaliteChestplate extends CrystaliteArmor implements MobEffectApplier {
public CrystaliteChestplate() {
super(EquipmentSlot.CHEST, EndItems.makeEndItemSettings().rarity(Rarity.RARE));
}
@Override
public void applyEffect(LivingEntity owner) {
owner.addEffect(new MobEffectInstance(EndStatusEffects.CRYSTALITE_DIG_SPEED));
}
@Override
@Environment(EnvType.CLIENT)
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> lines, TooltipFlag tooltip) {
super.appendHoverText(stack, level, lines, tooltip);
lines.add(1, Component.empty());
lines.add(2, CHEST_DESC);
}
}

View file

@ -0,0 +1,85 @@
package org.betterx.betterend.item;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.ElytraItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Rarity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.client.model.FabricModelPredicateProviderRegistry;
import org.betterx.betterend.BetterEnd;
import org.betterx.betterend.interfaces.FallFlyingItem;
import org.betterx.betterend.interfaces.MultiModelItem;
import org.betterx.betterend.registry.EndItems;
public class CrystaliteElytra extends CrystaliteArmor implements MultiModelItem, FallFlyingItem {
private final ResourceLocation wingTexture;
private final double movementFactor;
private final int defense;
private final float toughness;
public CrystaliteElytra(int durability, double movementFactor) {
super(EquipmentSlot.CHEST, EndItems.makeEndItemSettings().durability(durability).rarity(Rarity.EPIC));
this.wingTexture = BetterEnd.makeID("textures/entity/elytra_crystalite.png");
this.movementFactor = movementFactor;
this.defense = (int) ((double) material.getDefenseForSlot(EquipmentSlot.CHEST) / 1.75);
this.toughness = material.getToughness() / 1.75F;
addAttributeModifier(
Attributes.ARMOR,
new AttributeModifier(ARMOR_MODIFIER_UUID_PER_SLOT[2],
"Armor modifier",
defense,
AttributeModifier.Operation.ADDITION
)
);
addAttributeModifier(
Attributes.ARMOR_TOUGHNESS,
new AttributeModifier(ARMOR_MODIFIER_UUID_PER_SLOT[2],
"Armor toughness",
toughness,
AttributeModifier.Operation.ADDITION
)
);
}
@Override
public boolean isValidRepairItem(ItemStack itemStack, ItemStack itemStack2) {
return super.isValidRepairItem(itemStack, itemStack2) || itemStack2.getItem() == EndItems.ENCHANTED_MEMBRANE;
}
@Override
public double getMovementFactor() {
return movementFactor;
}
@Override
@Environment(EnvType.CLIENT)
public ResourceLocation getModelTexture() {
return wingTexture;
}
@Override
public int getDefense() {
return defense;
}
@Override
public float getToughness() {
return toughness;
}
@Override
public void registerModelPredicate() {
FabricModelPredicateProviderRegistry.register(
this,
new ResourceLocation("broken"),
(itemStack, clientLevel, livingEntity, i) -> ElytraItem.isFlyEnabled(itemStack) ? 0.0F : 1.0F
);
}
}

View file

@ -0,0 +1,22 @@
package org.betterx.betterend.item;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.item.Rarity;
import org.betterx.betterend.registry.EndAttributes;
import org.betterx.betterend.registry.EndItems;
import java.util.UUID;
public class CrystaliteHelmet extends CrystaliteArmor {
public CrystaliteHelmet() {
super(EquipmentSlot.HEAD, EndItems.makeEndItemSettings().rarity(Rarity.RARE));
UUID uuid = ARMOR_MODIFIER_UUID_PER_SLOT[EquipmentSlot.HEAD.getIndex()];
addAttributeModifier(
EndAttributes.BLINDNESS_RESISTANCE,
new AttributeModifier(uuid, "Helmet blindness resistance", 1.0, AttributeModifier.Operation.ADDITION)
);
}
}

View file

@ -0,0 +1,22 @@
package org.betterx.betterend.item;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.Rarity;
import org.betterx.betterend.registry.EndItems;
import java.util.UUID;
public class CrystaliteLeggings extends CrystaliteArmor {
public CrystaliteLeggings() {
super(EquipmentSlot.LEGS, EndItems.makeEndItemSettings().rarity(Rarity.RARE));
UUID uuid = ARMOR_MODIFIER_UUID_PER_SLOT[EquipmentSlot.LEGS.getIndex()];
addAttributeModifier(
Attributes.MAX_HEALTH,
new AttributeModifier(uuid, "Armor health boost", 4.0, AttributeModifier.Operation.ADDITION)
);
}
}

View file

@ -0,0 +1,37 @@
package org.betterx.betterend.item;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Rarity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.betterx.bclib.client.models.ModelsHelper;
import org.betterx.bclib.items.ModelProviderItem;
import org.betterx.betterend.registry.EndItems;
public class EnchantedItem extends ModelProviderItem {
private final Item source;
public EnchantedItem(Item source) {
super(EndItems.makeEndItemSettings().rarity(Rarity.RARE).stacksTo(16));
this.source = source;
}
@Override
public boolean isFoil(ItemStack stack) {
return true;
}
@Override
@Environment(EnvType.CLIENT)
public BlockModel getItemModel(ResourceLocation resourceLocation) {
ResourceLocation sourceId = Registry.ITEM.getKey(source);
return ModelsHelper.createItemModel(sourceId);
}
}

View file

@ -0,0 +1,62 @@
package org.betterx.betterend.item;
import net.minecraft.world.entity.EquipmentSlot;
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.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterial;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import org.betterx.bclib.interfaces.ItemModelProvider;
import java.util.UUID;
public class EndArmorItem extends ArmorItem implements ItemModelProvider {
protected static final UUID[] ARMOR_MODIFIER_UUID_PER_SLOT = new UUID[]{
UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B"),
UUID.fromString("D8499B04-0E66-4726-AB29-64469D734E0D"),
UUID.fromString("9F3D476D-C118-4544-8365-64846904B48E"),
UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150")
};
protected final Multimap<Attribute, AttributeModifier> defaultModifiers;
public EndArmorItem(ArmorMaterial material, EquipmentSlot equipmentSlot, Properties settings) {
super(material, equipmentSlot, settings);
this.defaultModifiers = HashMultimap.create();
UUID uuid = ARMOR_MODIFIER_UUID_PER_SLOT[equipmentSlot.getIndex()];
addAttributeModifier(
Attributes.ARMOR,
new AttributeModifier(uuid, "Armor modifier", getDefense(), AttributeModifier.Operation.ADDITION)
);
addAttributeModifier(
Attributes.ARMOR_TOUGHNESS,
new AttributeModifier(uuid, "Armor toughness", getToughness(), AttributeModifier.Operation.ADDITION)
);
if (knockbackResistance > 0.0F) {
addAttributeModifier(
Attributes.KNOCKBACK_RESISTANCE,
new AttributeModifier(uuid,
"Armor knockback resistance",
knockbackResistance,
AttributeModifier.Operation.ADDITION
)
);
}
}
@Override
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlot equipmentSlot) {
return equipmentSlot == slot ? defaultModifiers : super.getDefaultAttributeModifiers(equipmentSlot);
}
protected void addAttributeModifier(Attribute attribute, AttributeModifier modifier) {
if (defaultModifiers.containsKey(attribute)) {
defaultModifiers.removeAll(attribute);
}
defaultModifiers.put(attribute, modifier);
}
}

View file

@ -0,0 +1,10 @@
package org.betterx.betterend.item;
import net.minecraft.world.entity.ai.attributes.Attribute;
public class EndAttribute extends Attribute {
public EndAttribute(String description, double value) {
super(description, value);
}
}

View file

@ -0,0 +1,15 @@
package org.betterx.betterend.item;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.MobBucketItem;
import net.minecraft.world.level.material.Fluids;
import org.betterx.bclib.interfaces.ItemModelProvider;
import org.betterx.betterend.registry.EndItems;
public class EndBucketItem extends MobBucketItem implements ItemModelProvider {
public EndBucketItem(EntityType<?> type) {
super(type, Fluids.WATER, SoundEvents.BUCKET_EMPTY, EndItems.makeEndItemSettings().stacksTo(1));
}
}

View file

@ -0,0 +1,12 @@
package org.betterx.betterend.item;
import net.minecraft.world.item.Rarity;
import org.betterx.bclib.items.ModelProviderItem;
import org.betterx.betterend.registry.EndItems;
public class EternalCrystalItem extends ModelProviderItem {
public EternalCrystalItem() {
super(EndItems.makeEndItemSettings().stacksTo(16).rarity(Rarity.EPIC));
}
}

View file

@ -0,0 +1,48 @@
package org.betterx.betterend.item;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.betterx.bclib.items.ModelProviderItem;
import org.betterx.betterend.BetterEnd;
import org.betterx.betterend.registry.EndItems;
import org.betterx.betterend.util.LangUtil;
import java.util.List;
public class GuideBookItem extends ModelProviderItem {
public final static ResourceLocation BOOK_ID = BetterEnd.makeID("guidebook");
public static final Item GUIDE_BOOK = EndItems.getItemRegistry().register(BOOK_ID, new GuideBookItem());
public static void register() {
}
public GuideBookItem() {
super(EndItems.makeEndItemSettings().stacksTo(1));
}
@Override
public InteractionResultHolder<ItemStack> use(Level world, Player user, InteractionHand hand) {
if (!world.isClientSide && user instanceof ServerPlayer) {
//TODO: reanable Patchouli once it is available for 1.18
//PatchouliAPI.get().openBookGUI((ServerPlayer) user, BOOK_ID);
return InteractionResultHolder.success(user.getItemInHand(hand));
}
return InteractionResultHolder.consume(user.getItemInHand(hand));
}
@Override
public void appendHoverText(ItemStack stack, Level world, List<Component> tooltip, TooltipFlag context) {
tooltip.add(LangUtil.getText("book.betterend", "subtitle")
.withStyle(ChatFormatting.DARK_PURPLE, ChatFormatting.ITALIC));
}
}

View file

@ -0,0 +1,96 @@
package org.betterx.betterend.item.material;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.LazyLoadedValue;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.crafting.Ingredient;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndItems;
import java.util.function.Supplier;
public enum EndArmorMaterial implements ArmorMaterial {
THALLASIUM("thallasium", 17, new int[]{1, 4, 5, 2}, 12, SoundEvents.ARMOR_EQUIP_IRON, 0.0F, 0.0F, () -> {
return Ingredient.of(EndBlocks.THALLASIUM.ingot);
}), TERMINITE("terminite", 26, new int[]{3, 6, 7, 3}, 14, SoundEvents.ARMOR_EQUIP_IRON, 1.0F, 0.05F, () -> {
return Ingredient.of(EndBlocks.TERMINITE.ingot);
}), AETERNIUM("aeternium", 40, new int[]{4, 7, 9, 4}, 18, SoundEvents.ARMOR_EQUIP_NETHERITE, 3.5F, 0.2F, () -> {
return Ingredient.of(EndItems.AETERNIUM_INGOT);
}), CRYSTALITE("crystalite", 30, new int[]{3, 6, 8, 3}, 24, SoundEvents.ARMOR_EQUIP_DIAMOND, 1.2F, 0.1F, () -> {
return Ingredient.of(EndBlocks.TERMINITE.ingot);
});
private static final int[] BASE_DURABILITY = new int[]{13, 15, 16, 11};
private final String name;
private final int durabilityMultiplier;
private final int[] protectionAmounts;
private final int enchantability;
private final SoundEvent equipSound;
private final float toughness;
private final float knockbackResistance;
@SuppressWarnings("deprecation")
private final LazyLoadedValue<Ingredient> repairIngredient;
@SuppressWarnings("deprecation")
EndArmorMaterial(String name,
int durabilityMultiplier,
int[] protectionAmounts,
int enchantability,
SoundEvent equipSound,
float toughness,
float knockbackResistance,
Supplier<Ingredient> repairIngredient) {
this.name = name;
this.durabilityMultiplier = durabilityMultiplier;
this.protectionAmounts = protectionAmounts;
this.enchantability = enchantability;
this.equipSound = equipSound;
this.toughness = toughness;
this.knockbackResistance = knockbackResistance;
this.repairIngredient = new LazyLoadedValue<>(repairIngredient);
}
@Override
public int getDurabilityForSlot(EquipmentSlot slot) {
return BASE_DURABILITY[slot.getIndex()] * this.durabilityMultiplier;
}
@Override
public int getDefenseForSlot(EquipmentSlot slot) {
return this.protectionAmounts[slot.getIndex()];
}
@Override
public int getEnchantmentValue() {
return this.enchantability;
}
@Override
public SoundEvent getEquipSound() {
return this.equipSound;
}
@Override
public Ingredient getRepairIngredient() {
return this.repairIngredient.get();
}
@Override
public String getName() {
return this.name;
}
@Override
public float getToughness() {
return this.toughness;
}
@Override
public float getKnockbackResistance() {
return this.knockbackResistance;
}
}

View file

@ -0,0 +1,74 @@
package org.betterx.betterend.item.material;
import net.minecraft.util.LazyLoadedValue;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.crafting.Ingredient;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndItems;
import java.util.function.Supplier;
public enum EndToolMaterial implements Tier {
THALLASIUM(2, 320, 7.0F, 1.5F, 12, () -> {
return Ingredient.of(EndBlocks.THALLASIUM.ingot);
}), TERMINITE(3, 1230, 8.5F, 3.0F, 14, () -> {
return Ingredient.of(EndBlocks.TERMINITE.ingot);
}), AETERNIUM(5, 2196, 10.0F, 4.5F, 18, () -> {
return Ingredient.of(EndItems.AETERNIUM_INGOT);
});
private final int durability;
private final float miningSpeed;
private final float attackDamage;
private final int miningLevel;
private final int enchantability;
@SuppressWarnings("deprecation")
private final LazyLoadedValue<Ingredient> repairIngredient;
@SuppressWarnings("deprecation")
EndToolMaterial(int miningLevel,
int durability,
float miningSpeed,
float attackDamage,
int enchantability,
Supplier<Ingredient> repairIngredient) {
this.durability = durability;
this.miningSpeed = miningSpeed;
this.attackDamage = attackDamage;
this.miningLevel = miningLevel;
this.enchantability = enchantability;
this.repairIngredient = new LazyLoadedValue<>(repairIngredient);
}
@Override
public int getUses() {
return this.durability;
}
@Override
public float getSpeed() {
return this.miningSpeed;
}
@Override
public float getAttackDamageBonus() {
return this.attackDamage;
}
@Override
public int getLevel() {
return this.miningLevel;
}
@Override
public int getEnchantmentValue() {
return this.enchantability;
}
@Override
public Ingredient getRepairIngredient() {
return this.repairIngredient.get();
}
}

View file

@ -0,0 +1,95 @@
package org.betterx.betterend.item.model;
import net.minecraft.client.model.AgeableListModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartNames;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.CubeListBuilder;
import net.minecraft.client.model.geom.builders.LayerDefinition;
import net.minecraft.client.model.geom.builders.MeshDefinition;
import net.minecraft.client.model.geom.builders.PartDefinition;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.phys.Vec3;
import com.google.common.collect.ImmutableList;
public class ArmoredElytraModel<T extends LivingEntity> extends AgeableListModel<T> {
private final ModelPart rightWing;
private final ModelPart leftWing;
public static LayerDefinition getTexturedModelData() {
MeshDefinition modelData = new MeshDefinition();
PartDefinition modelPartData = modelData.getRoot();
modelPartData.addOrReplaceChild(
PartNames.LEFT_WING,
CubeListBuilder.create().texOffs(22, 0).addBox(-10.0f, 0.0f, 0.0f, 10.0f, 20.0f, 2.0f),
PartPose.ZERO
);
modelPartData.addOrReplaceChild(
PartNames.RIGHT_WING,
CubeListBuilder.create().mirror().texOffs(22, 0).addBox(0.0f, 0.0f, 0.0f, 10.0f, 20.0f, 2.0f),
PartPose.ZERO
);
return LayerDefinition.create(modelData, 64, 32);
}
public ArmoredElytraModel(ModelPart modelPart) {
leftWing = modelPart.getChild(PartNames.LEFT_WING);
rightWing = modelPart.getChild(PartNames.RIGHT_WING);
}
protected Iterable<ModelPart> headParts() {
return ImmutableList.of();
}
protected Iterable<ModelPart> bodyParts() {
return ImmutableList.of(leftWing, rightWing);
}
public void setupAnim(T livingEntity, float f, float g, float h, float i, float j) {
float rotX = 0.2617994F;
float rotZ = -0.2617994F;
float rotY = 0.0F;
float wingY = 0.0F;
if (livingEntity.isFallFlying()) {
float coef = 1.0F;
Vec3 vec3 = livingEntity.getDeltaMovement();
if (vec3.y < 0.0D) {
Vec3 normalized = vec3.normalize();
coef = 1.0F - (float) Math.pow(-normalized.y, 2.5D);
}
rotX = coef * 0.34906584F + (1.0F - coef) * rotX;
rotZ = coef * -1.5707964F + (1.0F - coef) * rotZ;
} else if (livingEntity.isCrouching()) {
rotX = 0.6981317F;
rotZ = -0.7853982F;
rotY = 0.08726646F;
wingY = 3.0F;
}
leftWing.x = 5.0F;
leftWing.y = wingY;
if (livingEntity instanceof AbstractClientPlayer) {
AbstractClientPlayer abstractClientPlayer = (AbstractClientPlayer) livingEntity;
abstractClientPlayer.elytraRotX = (float) ((double) abstractClientPlayer.elytraRotX + (double) (rotX - abstractClientPlayer.elytraRotX) * 0.1D);
abstractClientPlayer.elytraRotY = (float) ((double) abstractClientPlayer.elytraRotY + (double) (rotY - abstractClientPlayer.elytraRotY) * 0.1D);
abstractClientPlayer.elytraRotZ = (float) ((double) abstractClientPlayer.elytraRotZ + (double) (rotZ - abstractClientPlayer.elytraRotZ) * 0.1D);
leftWing.xRot = abstractClientPlayer.elytraRotX;
leftWing.yRot = abstractClientPlayer.elytraRotY;
leftWing.zRot = abstractClientPlayer.elytraRotZ;
} else {
leftWing.xRot = rotX;
leftWing.zRot = rotZ;
leftWing.yRot = rotY;
}
rightWing.x = -leftWing.x;
rightWing.yRot = -leftWing.yRot;
rightWing.y = leftWing.y;
rightWing.xRot = leftWing.xRot;
rightWing.zRot = -leftWing.zRot;
}
}

View file

@ -0,0 +1,92 @@
package org.betterx.betterend.item.model;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.resources.ResourceLocation;
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.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import com.google.common.collect.Lists;
import org.betterx.betterend.item.CrystaliteArmor;
import org.betterx.betterend.registry.EndItems;
import shadow.fabric.api.client.rendering.v1.ArmorRenderingRegistry;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@Environment(EnvType.CLIENT)
public class CrystaliteArmorProvider implements ArmorRenderingRegistry.ModelProvider, ArmorRenderingRegistry.TextureProvider {
//TODO: find new registry
private final static ResourceLocation FIRST_LAYER = new ResourceLocation(
"textures/models/armor/crystalite_layer_1.png");
private final static ResourceLocation SECOND_LAYER = new ResourceLocation(
"textures/models/armor/crystalite_layer_2.png");
private final static CrystaliteHelmetModel HELMET_MODEL = CrystaliteHelmetModel.createModel(null);
private final static CrystaliteChestplateModel CHEST_MODEL = CrystaliteChestplateModel.createRegularModel(null);
private final static CrystaliteChestplateModel CHEST_MODEL_SLIM = CrystaliteChestplateModel.createThinModel(null);
private final static CrystaliteLeggingsModel LEGGINGS_MODEL = CrystaliteLeggingsModel.createModel(null);
private final static CrystaliteBootsModel BOOTS_MODEL = CrystaliteBootsModel.createModel(null);
//@Override
public @NotNull ResourceLocation getArmorTexture(LivingEntity entity,
ItemStack stack,
EquipmentSlot slot,
boolean secondLayer,
@Nullable String suffix,
ResourceLocation defaultTexture) {
if (!isStackValid(stack)) return defaultTexture;
if (secondLayer) return SECOND_LAYER;
return FIRST_LAYER;
}
//@Override
public @NotNull HumanoidModel<LivingEntity> getArmorModel(LivingEntity entity,
ItemStack stack,
EquipmentSlot slot,
HumanoidModel<LivingEntity> defaultModel) {
if (!isStackValid(stack)) return defaultModel;
switch (slot) {
case HEAD: {
return HELMET_MODEL;
}
case CHEST: {
if (entity instanceof AbstractClientPlayer && ((AbstractClientPlayer) entity).getModelName()
.equals("slim")) {
CHEST_MODEL_SLIM.copyPropertiesTo(defaultModel);
return CHEST_MODEL_SLIM;
}
CHEST_MODEL.copyPropertiesTo(defaultModel);
return CHEST_MODEL;
}
case LEGS: {
return LEGGINGS_MODEL;
}
case FEET: {
BOOTS_MODEL.copyPropertiesTo(defaultModel);
return BOOTS_MODEL;
}
default: {
return defaultModel;
}
}
}
public Iterable<Item> getRenderedItems() {
return Lists.newArrayList(
EndItems.CRYSTALITE_HELMET,
EndItems.CRYSTALITE_CHESTPLATE,
EndItems.CRYSTALITE_ELYTRA,
EndItems.CRYSTALITE_LEGGINGS,
EndItems.CRYSTALITE_BOOTS
);
}
private boolean isStackValid(ItemStack stack) {
return stack.getItem() instanceof CrystaliteArmor;
}
}

View file

@ -0,0 +1,83 @@
package org.betterx.betterend.item.model;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.entity.LivingEntity;
import com.google.common.collect.Lists;
import org.betterx.betterend.registry.EndEntitiesRenders;
import java.util.Collections;
public class CrystaliteBootsModel extends HumanoidModel<LivingEntity> {
public ModelPart leftBoot;
public ModelPart rightBoot;
public static LayerDefinition getTexturedModelData() {
final float scale = 1.0f;
MeshDefinition modelData = new MeshDefinition();
PartDefinition modelPartData = modelData.getRoot();
// TODO: see if we need to subclass HumanoidModel
// Humanoid model tries to retrieve all parts in it's constructor,
// so we need to add empty Nodes
modelPartData.addOrReplaceChild("head", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("hat", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("body", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("right_arm", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("left_arm", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("right_leg", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("left_leg", CubeListBuilder.create(), PartPose.ZERO);
CubeDeformation deformation = new CubeDeformation(scale + 0.25f);
modelPartData.addOrReplaceChild(
"leftBoot",
CubeListBuilder.create().texOffs(0, 32).addBox(-2.0f, 0.0f, -2.0f, 4.0f, 12.0f, 4.0f, deformation),
PartPose.offset(1.9f, 12.0f, 0.0f)
);
modelPartData.addOrReplaceChild(
"rightBoot",
CubeListBuilder.create().texOffs(0, 16).addBox(-2.0f, 0.0f, -2.0f, 4.0f, 12.0f, 4.0f, deformation),
PartPose.offset(-1.9f, 12.0f, 0.0f)
);
return LayerDefinition.create(modelData, 64, 48);
}
public static CrystaliteBootsModel createModel(EntityModelSet entityModelSet) {
return new CrystaliteBootsModel(entityModelSet == null
? getTexturedModelData().bakeRoot()
: entityModelSet.bakeLayer(
EndEntitiesRenders.CRYSTALITE_BOOTS));
}
public CrystaliteBootsModel(ModelPart modelPart) {
super(modelPart, RenderType::entityTranslucent);
leftBoot = modelPart.getChild("leftBoot");
rightBoot = modelPart.getChild("rightBoot");
}
@Override
public void copyPropertiesTo(HumanoidModel<LivingEntity> bipedEntityModel) {
super.copyPropertiesTo(bipedEntityModel);
this.leftBoot.copyFrom(leftLeg);
this.rightBoot.copyFrom(rightLeg);
}
@Override
protected Iterable<ModelPart> headParts() {
return Collections::emptyIterator;
}
@Override
protected Iterable<ModelPart> bodyParts() {
return Lists.newArrayList(leftBoot, rightBoot);
}
}

View file

@ -0,0 +1,150 @@
package org.betterx.betterend.item.model;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartNames;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.entity.LivingEntity;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.vertex.PoseStack;
import org.betterx.betterend.registry.EndEntitiesRenders;
import java.util.Collections;
public class CrystaliteChestplateModel extends HumanoidModel<LivingEntity> {
public ModelPart leftShoulder;
public ModelPart rightShoulder;
private final boolean thinArms;
public static LayerDefinition getRegularTexturedModelData() {
return getTexturedModelData(1.0f, false);
}
public static LayerDefinition getThinTexturedModelData() {
return getTexturedModelData(1.0f, true);
}
private static LayerDefinition getTexturedModelData(float scale, boolean thinArms) {
MeshDefinition modelData = new MeshDefinition();
PartDefinition modelPartData = modelData.getRoot();
// TODO: see if we need to subclass HumanoidModel
// Humanoid model tries to retrieve all parts in it's constructor,
// so we need to add empty Nodes
modelPartData.addOrReplaceChild("head", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("hat", CubeListBuilder.create(), PartPose.ZERO);
// modelPartData.addOrReplaceChild("body", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("right_arm", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("left_arm", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("right_leg", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("left_leg", CubeListBuilder.create(), PartPose.ZERO);
CubeDeformation deformation = new CubeDeformation(scale + 0.25F);
PartDefinition body = modelPartData.addOrReplaceChild(
PartNames.BODY,
CubeListBuilder.create().texOffs(16, 16).addBox(-4.0f, 0.0f, -2.0f, 8.0f, 12.0f, 4.0f, deformation),
PartPose.ZERO
);
if (thinArms) {
deformation = new CubeDeformation(scale + 0.45F);
PartDefinition leftShoulder = modelPartData.addOrReplaceChild(
"leftShoulder",
CubeListBuilder.create()
.mirror()
.texOffs(40, 32)
.addBox(-1.0f, -2.5f, -2.0f, 4.0f, 12.0f, 4.0f, deformation),
PartPose.offset(5.0f, 2.0f, 0.0f)
);
PartDefinition rightShoulder = modelPartData.addOrReplaceChild(
"rightShoulder",
CubeListBuilder.create()
.texOffs(40, 16)
.addBox(-3.0f, -2.5f, -2.0f, 4.0f, 12.0f, 4.0f, deformation),
PartPose.offset(-5.0f, 2.0f, 10.0f)
);
} else {
deformation = new CubeDeformation(scale + 0.45F);
PartDefinition leftShoulder = modelPartData.addOrReplaceChild(
"leftShoulder",
CubeListBuilder.create()
.mirror()
.texOffs(40, 32)
.addBox(-1.0f, -2.5f, -2.0f, 4.0f, 12.0f, 4.0f, deformation),
PartPose.offset(5.0f, 2.0f, 0.0f)
);
PartDefinition rightShoulder = modelPartData.addOrReplaceChild(
"rightShoulder",
CubeListBuilder.create()
.texOffs(40, 16)
.addBox(-3.0f, -2.5f, -2.0f, 4.0f, 12.0f, 4.0f, deformation),
PartPose.offset(-5.0f, 2.0f, 10.0f)
);
}
return LayerDefinition.create(modelData, 64, 48);
}
final ModelPart localBody;
public static CrystaliteChestplateModel createRegularModel(EntityModelSet entityModelSet) {
return new CrystaliteChestplateModel(entityModelSet == null
? getRegularTexturedModelData().bakeRoot()
: entityModelSet
.bakeLayer(EndEntitiesRenders.CRYSTALITE_CHESTPLATE),
false);
}
public static CrystaliteChestplateModel createThinModel(EntityModelSet entityModelSet) {
return new CrystaliteChestplateModel(entityModelSet == null
? getThinTexturedModelData().bakeRoot()
: entityModelSet
.bakeLayer(EndEntitiesRenders.CRYSTALITE_CHESTPLATE_THIN),
true);
}
protected CrystaliteChestplateModel(ModelPart modelPart, boolean thinArms) {
super(modelPart, RenderType::entityTranslucent);
this.thinArms = thinArms;
localBody = modelPart.getChild(PartNames.BODY);
leftShoulder = modelPart.getChild("leftShoulder");
rightShoulder = modelPart.getChild("rightShoulder");
}
@Override
public void copyPropertiesTo(HumanoidModel<LivingEntity> bipedEntityModel) {
super.copyPropertiesTo(bipedEntityModel);
this.leftShoulder.copyFrom(leftArm);
this.rightShoulder.copyFrom(rightArm);
}
@Override
protected Iterable<ModelPart> headParts() {
return Collections::emptyIterator;
}
@Override
protected Iterable<ModelPart> bodyParts() {
return Lists.newArrayList(localBody, leftShoulder, rightShoulder);
}
@Override
public void translateToHand(HumanoidArm arm, PoseStack matrices) {
ModelPart modelPart = this.getArm(arm);
if (this.thinArms) {
float f = 0.5F * (float) (arm == HumanoidArm.RIGHT ? 1 : -1);
modelPart.x += f;
modelPart.translateAndRotate(matrices);
modelPart.x -= f;
} else {
modelPart.translateAndRotate(matrices);
}
}
}

View file

@ -0,0 +1,73 @@
package org.betterx.betterend.item.model;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartNames;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.entity.LivingEntity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import com.google.common.collect.Lists;
import org.betterx.betterend.registry.EndEntitiesRenders;
import java.util.Collections;
@Environment(EnvType.CLIENT)
public class CrystaliteHelmetModel extends HumanoidModel<LivingEntity> {
final ModelPart myHat;
public static LayerDefinition getTexturedModelData() {
final float scale = 1.0f;
MeshDefinition modelData = new MeshDefinition();
PartDefinition modelPartData = modelData.getRoot();
// TODO: see if we need to subclass HumanoidModel
// Humanoid model tries to retrieve all parts in it's constructor,
// so we need to add empty Nodes
modelPartData.addOrReplaceChild("head", CubeListBuilder.create(), PartPose.ZERO);
//modelPartData.addOrReplaceChild("hat", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("body", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("right_arm", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("left_arm", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("right_leg", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("left_leg", CubeListBuilder.create(), PartPose.ZERO);
CubeDeformation deformation_hat = new CubeDeformation(scale + 0.5f);
PartDefinition hat = modelPartData.addOrReplaceChild(
PartNames.HAT,
CubeListBuilder.create().texOffs(0, 0).addBox(-4.0f, -8.0f, -4.0f, 8.0f, 8.0f, 8.0f, deformation_hat),
PartPose.ZERO
);
return LayerDefinition.create(modelData, 64, 48);
}
public static CrystaliteHelmetModel createModel(EntityModelSet entityModelSet) {
return new CrystaliteHelmetModel(entityModelSet == null
? getTexturedModelData().bakeRoot()
: entityModelSet.bakeLayer(
EndEntitiesRenders.CRYSTALITE_HELMET));
}
public CrystaliteHelmetModel(ModelPart modelPart) {
super(modelPart, RenderType::entityTranslucent);
myHat = modelPart.getChild(PartNames.HAT);
}
@Override
protected Iterable<ModelPart> headParts() {
return Collections::emptyIterator;
}
@Override
protected Iterable<ModelPart> bodyParts() {
return Lists.newArrayList(myHat);
}
}

View file

@ -0,0 +1,84 @@
package org.betterx.betterend.item.model;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartNames;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.entity.LivingEntity;
import com.google.common.collect.Lists;
import org.betterx.betterend.registry.EndEntitiesRenders;
import java.util.Collections;
public class CrystaliteLeggingsModel extends HumanoidModel<LivingEntity> {
public static LayerDefinition getTexturedModelData() {
float scale = 1.0f;
MeshDefinition modelData = new MeshDefinition();
PartDefinition modelPartData = modelData.getRoot();
// TODO: see if we need to subclass HumanoidModel
// Humanoid model tries to retrieve all parts in it's constructor,
// so we need to add empty Nodes
modelPartData.addOrReplaceChild("head", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("hat", CubeListBuilder.create(), PartPose.ZERO);
// modelPartData.addOrReplaceChild("body", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("right_arm", CubeListBuilder.create(), PartPose.ZERO);
modelPartData.addOrReplaceChild("left_arm", CubeListBuilder.create(), PartPose.ZERO);
// modelPartData.addOrReplaceChild("right_leg", CubeListBuilder.create(), PartPose.ZERO);
// modelPartData.addOrReplaceChild("left_leg", CubeListBuilder.create(), PartPose.ZERO);
CubeDeformation deformation = new CubeDeformation(scale);
modelPartData.addOrReplaceChild(
PartNames.BODY,
CubeListBuilder.create().texOffs(16, 16).addBox(-4.0f, 0.0f, -2.0f, 8.0f, 12.0f, 4.0f, deformation),
PartPose.ZERO
);
modelPartData.addOrReplaceChild(
PartNames.LEFT_LEG,
CubeListBuilder.create().texOffs(0, 32).addBox(-2.0f, 0.0f, -2.0f, 4.0f, 12.0f, 4.0f, deformation),
PartPose.offset(1.9f, 12.0f, 0.0f)
);
modelPartData.addOrReplaceChild(
PartNames.RIGHT_LEG,
CubeListBuilder.create().texOffs(0, 16).addBox(-2.0f, 0.0f, -2.0f, 4.0f, 12.0f, 4.0f, deformation),
PartPose.offset(-1.9f, 12.0f, 0.0f)
);
return LayerDefinition.create(modelData, 64, 48);
}
final ModelPart myBody;
final ModelPart myLeftLeg;
final ModelPart myRightLeg;
public static CrystaliteLeggingsModel createModel(EntityModelSet entityModelSet) {
return new CrystaliteLeggingsModel(entityModelSet == null
? getTexturedModelData().bakeRoot()
: entityModelSet.bakeLayer(
EndEntitiesRenders.CRYSTALITE_LEGGINGS));
}
public CrystaliteLeggingsModel(ModelPart modelPart) {
super(modelPart, RenderType::entityTranslucent);
myBody = modelPart.getChild(PartNames.BODY);
myLeftLeg = modelPart.getChild(PartNames.LEFT_LEG);
myRightLeg = modelPart.getChild(PartNames.RIGHT_LEG);
}
@Override
protected Iterable<ModelPart> headParts() {
return Collections::emptyIterator;
}
@Override
protected Iterable<ModelPart> bodyParts() {
return Lists.newArrayList(myBody, myRightLeg, myLeftLeg);
}
}

View file

@ -0,0 +1,156 @@
package org.betterx.betterend.item.tool;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
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.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableMultimap.Builder;
import com.google.common.collect.Multimap;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.api.tag.CommonItemTags;
import org.betterx.bclib.client.models.ModelsHelper;
import org.betterx.bclib.interfaces.ItemModelProvider;
import org.betterx.bclib.interfaces.TagProvider;
import org.betterx.bclib.util.MHelper;
import java.util.List;
import java.util.UUID;
public class EndHammerItem extends DiggerItem implements ItemModelProvider, TagProvider {
public final static UUID ATTACK_KNOCKBACK_MODIFIER_ID = Mth.createInsecureUUID(MHelper.RANDOM_SOURCE);
private final Multimap<Attribute, AttributeModifier> attributeModifiers;
public EndHammerItem(Tier material, float attackDamage, float attackSpeed, double knockback, Properties settings) {
super(attackDamage, attackSpeed, material, CommonBlockTags.MINABLE_WITH_HAMMER, 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
)
);
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);
}
@Override
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
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) -> entity.broadcastBreakEvent(EquipmentSlot.MAINHAND)));
}
return true;
}
@Override
public float getDestroySpeed(ItemStack stack, BlockState state) {
if (state.getMaterial().equals(Material.GLASS)) {
return this.getTier().getSpeed() * 2.0F;
}
if (isCorrectToolForDrops(state)) {
float mult;
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 = this.getTier().getSpeed() / 2.0F;
}
return Math.max(mult, 1.0F);
}
return 1.0F;
}
@Override
public boolean isCorrectToolForDrops(BlockState state) {
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)) {
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)) {
return level >= 2;
}
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;
}
@Override
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlot slot) {
return slot == EquipmentSlot.MAINHAND ? this.attributeModifiers : super.getDefaultAttributeModifiers(slot);
}
@Override
@Environment(EnvType.CLIENT)
public BlockModel getItemModel(ResourceLocation resourceLocation) {
return ModelsHelper.createHandheldItem(resourceLocation);
}
@Override
public void addTags(List<TagKey<Block>> blockTags, List<TagKey<Item>> itemTags) {
itemTags.add(CommonItemTags.HAMMERS);
}
}

View file

@ -0,0 +1,22 @@
package org.betterx.betterend.item.tool;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.items.tool.BasePickaxeItem;
public class EndPickaxe extends BasePickaxeItem {
public EndPickaxe(Tier material, int attackDamage, float attackSpeed, Properties settings) {
super(material, attackDamage, attackSpeed, settings);
}
@Override
public float getDestroySpeed(ItemStack stack, BlockState state) {
if (state.is(Blocks.END_STONE) && this.getTier().getLevel() > 2) {
return this.speed * 3;
}
return super.getDestroySpeed(stack, state);
}
}