2020-04-08 22:22:38 +00:00
|
|
|
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;
|
2020-04-08 22:22:38 +00:00
|
|
|
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-04-08 22:22:38 +00:00
|
|
|
|
2020-08-05 18:44:53 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2020-04-08 22:22:38 +00:00
|
|
|
public class DragonEggHolderBlockItem extends BlockItem {
|
2020-08-05 18:44:53 +00:00
|
|
|
private static final List<DragonEggHolderBlockItem> list = new ArrayList<>();
|
|
|
|
|
2020-04-08 22:22:38 +00:00
|
|
|
public DragonEggHolderBlockItem(Block block) {
|
2020-04-15 22:19:40 +00:00
|
|
|
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-04-08 22:22:38 +00:00
|
|
|
}
|
2020-08-05 18:44:53 +00:00
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
}
|
2020-04-08 22:22:38 +00:00
|
|
|
}
|
|
|
|
}
|