Search in sources :

Example 11 with Block

use of net.minecraft.world.level.block.Block in project MyPet by xXKeyleXx.

the class ConfigItem method load.

@Override
public void load(MaterialHolder material, String data) {
    ResourceLocation key = new ResourceLocation(material.getId());
    Item item = Registry.ITEM.get(key);
    // TODO AIR now?
    if (item == null) {
        Block block = Registry.BLOCK.get(key);
        item = block.asItem();
    }
    if (item == null) {
        return;
    }
    net.minecraft.world.item.ItemStack is = new net.minecraft.world.item.ItemStack(item, 1);
    if (data != null) {
        CompoundTag tag = null;
        String nbtString = data.trim();
        if (nbtString.startsWith("{") && nbtString.endsWith("}")) {
            try {
                tag = TagParser.parseTag(nbtString);
            } catch (Exception e) {
                MyPetApi.getLogger().warning("Error" + ChatColor.RESET + " in config: " + ChatColor.UNDERLINE + e.getLocalizedMessage() + ChatColor.RESET + " caused by:");
                MyPetApi.getLogger().warning(item.getDescriptionId() + " " + nbtString);
            }
            if (tag != null) {
                is.setTag(tag);
            }
        }
    }
    this.item = CraftItemStack.asCraftMirror(is);
}
Also used : Item(net.minecraft.world.item.Item) ResourceLocation(net.minecraft.resources.ResourceLocation) Block(net.minecraft.world.level.block.Block) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 12 with Block

use of net.minecraft.world.level.block.Block in project MyPet by xXKeyleXx.

the class ConfigItem method load.

@Override
public void load(MaterialHolder material, String data) {
    ResourceLocation key = new ResourceLocation(material.getId());
    Item item = Registry.ITEM.get(key);
    // TODO AIR now?
    if (item == null) {
        Block block = Registry.BLOCK.get(key);
        item = block.asItem();
    }
    if (item == null) {
        return;
    }
    net.minecraft.world.item.ItemStack is = new net.minecraft.world.item.ItemStack(item, 1);
    if (data != null) {
        CompoundTag tag = null;
        String nbtString = data.trim();
        if (nbtString.startsWith("{") && nbtString.endsWith("}")) {
            try {
                tag = TagParser.parseTag(nbtString);
            } catch (Exception e) {
                MyPetApi.getLogger().warning("Error" + ChatColor.RESET + " in config: " + ChatColor.UNDERLINE + e.getLocalizedMessage() + ChatColor.RESET + " caused by:");
                MyPetApi.getLogger().warning(item.getDescriptionId() + " " + nbtString);
            }
            if (tag != null) {
                is.setTag(tag);
            }
        }
    }
    this.item = CraftItemStack.asCraftMirror(is);
}
Also used : Item(net.minecraft.world.item.Item) ResourceLocation(net.minecraft.resources.ResourceLocation) Block(net.minecraft.world.level.block.Block) CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 13 with Block

use of net.minecraft.world.level.block.Block in project MyPet by xXKeyleXx.

the class EntityMyTraderLlama method updateVisuals.

@Override
public void updateVisuals() {
    this.getEntityData().set(CHEST_WATCHER, getMyPet().hasChest());
    this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
    if (getMyPet().hasDecor()) {
        ItemStack is = CraftItemStack.asNMSCopy(getMyPet().getDecor());
        Block block = Block.byItem(is.getItem());
        int color = block instanceof WoolCarpetBlock ? ((WoolCarpetBlock) block).getColor().getId() : 0;
        this.getEntityData().set(COLOR_WATCHER, color);
    } else {
        this.getEntityData().set(COLOR_WATCHER, -1);
    }
    this.getEntityData().set(VARIANT_WATCHER, getMyPet().getVariant());
}
Also used : WoolCarpetBlock(net.minecraft.world.level.block.WoolCarpetBlock) WoolCarpetBlock(net.minecraft.world.level.block.WoolCarpetBlock) Block(net.minecraft.world.level.block.Block) CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 14 with Block

use of net.minecraft.world.level.block.Block in project MyPet by xXKeyleXx.

the class EntityMyLlama method updateVisuals.

@Override
public void updateVisuals() {
    this.getEntityData().set(CHEST_WATCHER, getMyPet().hasChest());
    this.getEntityData().set(AGE_WATCHER, getMyPet().isBaby());
    if (getMyPet().hasDecor()) {
        ItemStack is = CraftItemStack.asNMSCopy(getMyPet().getDecor());
        Block block = Block.byItem(is.getItem());
        int color = block instanceof WoolCarpetBlock ? ((WoolCarpetBlock) block).getColor().getId() : 0;
        this.getEntityData().set(COLOR_WATCHER, color);
    } else {
        this.getEntityData().set(COLOR_WATCHER, -1);
    }
    this.getEntityData().set(VARIANT_WATCHER, getMyPet().getVariant());
}
Also used : WoolCarpetBlock(net.minecraft.world.level.block.WoolCarpetBlock) WoolCarpetBlock(net.minecraft.world.level.block.WoolCarpetBlock) Block(net.minecraft.world.level.block.Block) ItemStack(net.minecraft.world.item.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)

Aggregations

Block (net.minecraft.world.level.block.Block)14 Item (net.minecraft.world.item.Item)5 ResourceLocation (net.minecraft.resources.ResourceLocation)4 ItemStack (net.minecraft.world.item.ItemStack)3 WoolCarpetBlock (net.minecraft.world.level.block.WoolCarpetBlock)3 BlockState (net.minecraft.world.level.block.state.BlockState)3 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)3 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)2 BlockPos (net.minecraft.core.BlockPos)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 Tag (net.minecraft.tags.Tag)2 CraftItemStack (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)2 ItemStack (org.bukkit.inventory.ItemStack)2 com.google.common.collect (com.google.common.collect)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 Pair (com.mojang.datafixers.util.Pair)1 Lifecycle (com.mojang.serialization.Lifecycle)1 Field (java.lang.reflect.Field)1