This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
RelicCraft/src/main/java/com/thebrokenrail/reliccraft/item/DragonEggHolderBlockItem.java

44 lines
1.6 KiB
Java
Raw Normal View History

package com.thebrokenrail.reliccraft.item;
import com.thebrokenrail.reliccraft.RelicCraft;
2020-06-28 16:38:49 +00:00
import com.thebrokenrail.reliccraft.mixin.ModelPredicateProviderRegistryHook;
2020-08-05 18:44:53 +00:00
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.Block;
import net.minecraft.inventory.Inventories;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity;
2020-06-28 16:38:49 +00:00
import net.minecraft.util.collection.DefaultedList;
2020-08-05 18:44:53 +00:00
import java.util.ArrayList;
import java.util.List;
public class DragonEggHolderBlockItem extends BlockItem {
2020-08-05 18:44:53 +00:00
private static final List<DragonEggHolderBlockItem> list = new ArrayList<>();
public DragonEggHolderBlockItem(Block block) {
super(block, new Settings().rarity(Rarity.UNCOMMON).group(RelicCraft.ITEM_GROUP));
2020-08-05 18:44:53 +00:00
list.add(this);
}
@Environment(EnvType.CLIENT)
public static void initClient() {
for (DragonEggHolderBlockItem item : list) {
ModelPredicateProviderRegistryHook.callRegister(item, new Identifier(RelicCraft.NAMESPACE, "active"), (stack, world, entity) -> {
CompoundTag tag = stack.getSubTag("BlockEntityTag");
if (tag != null) {
DefaultedList<ItemStack> list = DefaultedList.ofSize(1, ItemStack.EMPTY);
Inventories.fromTag(tag, list);
if (!list.get(0).isEmpty()) {
return 1;
}
}
2020-08-05 18:44:53 +00:00
return 0;
});
}
}
}