Registries, Base blocks with entities

This commit is contained in:
Aleksey 2021-05-27 13:55:03 +03:00
parent 5aeee09cfc
commit 8ab247f861
45 changed files with 1684 additions and 40 deletions

View file

@ -0,0 +1,49 @@
package ru.bclib.items;
import java.util.UUID;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
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 ru.bclib.client.models.ItemModelProvider;
public class BaseArmorItem 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 BaseArmorItem(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,9 @@
package ru.bclib.items;
import net.minecraft.world.entity.ai.attributes.Attribute;
public class BaseAttribute extends Attribute {
public BaseAttribute(String description, double value) {
super(description, value);
}
}

View file

@ -0,0 +1,13 @@
package ru.bclib.items;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.FishBucketItem;
import net.minecraft.world.level.material.Fluids;
import ru.bclib.client.models.ItemModelProvider;
public class BaseBucketItem extends FishBucketItem implements ItemModelProvider {
public BaseBucketItem(EntityType<?> type, FabricItemSettings settings) {
super(type, Fluids.WATER, settings.stacksTo(1));
}
}

View file

@ -0,0 +1,54 @@
package ru.bclib.items;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ItemUtils;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.level.Level;
public class BaseDrinkItem extends ModelProviderItem {
public BaseDrinkItem(Properties settings) {
super(settings);
}
@Override
public int getUseDuration(ItemStack stack) {
return 32;
}
@Override
public UseAnim getUseAnimation(ItemStack stack) {
return UseAnim.DRINK;
}
@Override
public InteractionResultHolder<ItemStack> use(Level world, Player user, InteractionHand hand) {
return ItemUtils.useDrink(world, user, hand);
}
@Override
public ItemStack finishUsingItem(ItemStack stack, Level world, LivingEntity user) {
if (user instanceof ServerPlayer) {
ServerPlayer serverPlayerEntity = (ServerPlayer) user;
CriteriaTriggers.CONSUME_ITEM.trigger(serverPlayerEntity, stack);
serverPlayerEntity.awardStat(Stats.ITEM_USED.get(this));
}
if (user instanceof Player && !((Player) user).abilities.instabuild) {
stack.shrink(1);
}
if (!world.isClientSide) {
user.removeAllEffects();
}
return stack.isEmpty() ? new ItemStack(Items.GLASS_BOTTLE) : stack;
}
}

View file

@ -0,0 +1,24 @@
package ru.bclib.items;
import java.util.Optional;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.SpawnEggItem;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
public class BaseSpawnEggItem extends SpawnEggItem implements ItemModelProvider {
public BaseSpawnEggItem(EntityType<?> type, int primaryColor, int secondaryColor, Properties settings) {
super(type, primaryColor, secondaryColor, settings);
}
@Override
public BlockModel getItemModel(ResourceLocation resourceLocation) {
Optional<String> pattern = PatternsHelper.createJson(BasePatterns.ITEM_SPAWN_EGG, resourceLocation);
return ModelsHelper.fromPattern(pattern);
}
}

View file

@ -0,0 +1,11 @@
package ru.bclib.items;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.item.RecordItem;
import ru.bclib.client.models.ItemModelProvider;
public class EndDiscItem extends RecordItem implements ItemModelProvider {
public EndDiscItem(int comparatorOutput, SoundEvent sound, Properties settings) {
super(comparatorOutput, sound, settings);
}
}

View file

@ -0,0 +1,18 @@
package ru.bclib.items;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.client.models.ModelsHelper;
public class ModelProviderItem extends Item implements ItemModelProvider {
public ModelProviderItem(Properties settings) {
super(settings);
}
@Override
public BlockModel getItemModel(ResourceLocation resourceLocation) {
return ModelsHelper.createItemModel(resourceLocation);
}
}

View file

@ -0,0 +1,34 @@
package ru.bclib.items.tool;
import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.block.state.BlockState;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.client.models.ModelsHelper;
public class BaseAxeItem extends AxeItem implements DynamicAttributeTool, ItemModelProvider {
public BaseAxeItem(Tier material, float attackDamage, float attackSpeed, Properties settings) {
super(material, attackDamage, attackSpeed, settings);
}
@Override
public int getMiningLevel(Tag<Item> tag, BlockState state, ItemStack stack, LivingEntity user) {
if (tag.equals(FabricToolTags.AXES)) {
return this.getTier().getLevel();
}
return 0;
}
@Override
public BlockModel getItemModel(ResourceLocation resourceLocation) {
return ModelsHelper.createHandheldItem(resourceLocation);
}
}

View file

@ -0,0 +1,19 @@
package ru.bclib.items.tool;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.HoeItem;
import net.minecraft.world.item.Tier;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.client.models.ModelsHelper;
public class BaseHoeItem extends HoeItem implements ItemModelProvider {
public BaseHoeItem(Tier material, int attackDamage, float attackSpeed, Properties settings) {
super(material, attackDamage, attackSpeed, settings);
}
@Override
public BlockModel getItemModel(ResourceLocation resourceLocation) {
return ModelsHelper.createHandheldItem(resourceLocation);
}
}

View file

@ -0,0 +1,42 @@
package ru.bclib.items.tool;
import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl;
import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl.Entry;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.PickaxeItem;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.block.state.BlockState;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.client.models.ModelsHelper;
public class BasePickaxeItem extends PickaxeItem implements DynamicAttributeTool, ItemModelProvider {
public BasePickaxeItem(Tier material, int attackDamage, float attackSpeed, Properties settings) {
super(material, attackDamage, attackSpeed, settings);
}
@Override
public int getMiningLevel(Tag<Item> tag, BlockState state, ItemStack stack, LivingEntity user) {
if (tag.equals(FabricToolTags.PICKAXES)) {
return getTier().getLevel();
}
return 0;
}
@Override
public float getDestroySpeed(ItemStack stack, BlockState state) {
Entry entry = ToolManagerImpl.entryNullable(state.getBlock());
return (entry != null && entry.getMiningLevel(FabricToolTags.PICKAXES) >= 0) ? speed : super.getDestroySpeed(stack, state);
}
@Override
public BlockModel getItemModel(ResourceLocation resourceLocation) {
return ModelsHelper.createHandheldItem(resourceLocation);
}
}

View file

@ -0,0 +1,42 @@
package ru.bclib.items.tool;
import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl;
import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl.Entry;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ShovelItem;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.block.state.BlockState;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.client.models.ModelsHelper;
public class BaseShovelItem extends ShovelItem implements DynamicAttributeTool, ItemModelProvider {
public BaseShovelItem(Tier material, float attackDamage, float attackSpeed, Properties settings) {
super(material, attackDamage, attackSpeed, settings);
}
@Override
public int getMiningLevel(Tag<Item> tag, BlockState state, ItemStack stack, LivingEntity user) {
if (tag.equals(FabricToolTags.SHOVELS)) {
return this.getTier().getLevel();
}
return 0;
}
@Override
public float getDestroySpeed(ItemStack stack, BlockState state) {
Entry entry = ToolManagerImpl.entryNullable(state.getBlock());
return (entry != null && entry.getMiningLevel(FabricToolTags.SHOVELS) >= 0) ? speed : super.getDestroySpeed(stack, state);
}
@Override
public BlockModel getItemModel(ResourceLocation resourceLocation) {
return ModelsHelper.createHandheldItem(resourceLocation);
}
}

View file

@ -0,0 +1,20 @@
package ru.bclib.items.tool;
import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tier;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.client.models.ModelsHelper;
public class BaseSwordItem extends SwordItem implements DynamicAttributeTool, ItemModelProvider {
public BaseSwordItem(Tier material, int attackDamage, float attackSpeed, Properties settings) {
super(material, attackDamage, attackSpeed, settings);
}
@Override
public BlockModel getItemModel(ResourceLocation resourceLocation) {
return ModelsHelper.createHandheldItem(resourceLocation);
}
}