Search in sources :

Example 1 with NBTTagByte

use of net.minecraft.nbt.NBTTagByte in project SpongeCommon by SpongePowered.

the class NbtTranslator method containerToCompound.

private static void containerToCompound(final DataView container, final NBTTagCompound compound) {
    // We don't need to get deep values since all nested DataViews will be found
    // from the instance of checks.
    checkNotNull(container);
    checkNotNull(compound);
    for (Map.Entry<DataQuery, Object> entry : container.getValues(false).entrySet()) {
        Object value = entry.getValue();
        String key = entry.getKey().asString('.');
        if (value instanceof DataView) {
            NBTTagCompound inner = new NBTTagCompound();
            containerToCompound(container.getView(entry.getKey()).get(), inner);
            compound.setTag(key, inner);
        } else if (value instanceof Boolean) {
            compound.setTag(key + BOOLEAN_IDENTIFER, new NBTTagByte(((Boolean) value) ? (byte) 1 : 0));
        } else {
            compound.setTag(key, getBaseFromObject(value));
        }
    }
}
Also used : DataView(org.spongepowered.api.data.DataView) NBTTagByte(net.minecraft.nbt.NBTTagByte) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) DataQuery(org.spongepowered.api.data.DataQuery) NBTTagString(net.minecraft.nbt.NBTTagString) Map(java.util.Map)

Example 2 with NBTTagByte

use of net.minecraft.nbt.NBTTagByte in project Random-Things by lumien231.

the class ModRecipes method register.

public static void register() {
    for (int i = 0; i < oreDictDyes.length; i++) {
        oreDictDyes[i] = "dye" + dyes[i];
    }
    ArrayUtils.reverse(oreDictDyes);
    RecipeSorter.register("randomthings:customWorkbenchRecipe", RecipeWorkbench.class, Category.SHAPED, "");
    final ItemStack rottenFlesh = new ItemStack(Items.ROTTEN_FLESH);
    final ItemStack boneMeal = new ItemStack(Items.DYE, 1, 15);
    final ItemStack lapis = new ItemStack(Items.DYE, 1, 4);
    final ItemStack cobblestone = new ItemStack(Blocks.COBBLESTONE);
    final ItemStack ghastTear = new ItemStack(Items.GHAST_TEAR);
    final ItemStack vine = new ItemStack(Blocks.VINE);
    final ItemStack waterBottle = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.WATER);
    final ItemStack mossyCobblestone = new ItemStack(Blocks.MOSSY_COBBLESTONE);
    final ItemStack netherBrick = new ItemStack(Blocks.NETHER_BRICK);
    final ItemStack coal = new ItemStack(Items.COAL);
    final ItemStack blazePowder = new ItemStack(Items.BLAZE_POWDER);
    final ItemStack flint = new ItemStack(Items.FLINT);
    final ItemStack spiderEye = new ItemStack(Items.SPIDER_EYE);
    final ItemStack redMushroom = new ItemStack(Blocks.RED_MUSHROOM);
    final ItemStack glowStone = new ItemStack(Items.GLOWSTONE_DUST);
    final ItemStack glisteringMelon = new ItemStack(Items.SPECKLED_MELON);
    final ItemStack witherSkull = new ItemStack(Items.SKULL, 1, 1);
    ForgeRegistries.RECIPES.register(new RecipeWorkbench());
    // Imbuing Station
    ImbuingRecipeHandler.addRecipe(waterBottle, vine, boneMeal, cobblestone, mossyCobblestone);
    ImbuingRecipeHandler.addRecipe(coal, flint, blazePowder, waterBottle, new ItemStack(ModItems.imbue, 1, 0));
    ImbuingRecipeHandler.addRecipe(spiderEye, rottenFlesh, redMushroom, waterBottle, new ItemStack(ModItems.imbue, 1, 1));
    ImbuingRecipeHandler.addRecipe(new ItemStack(ModItems.beans, 1, 1), lapis, glowStone, waterBottle, new ItemStack(ModItems.imbue, 1, 2));
    ImbuingRecipeHandler.addRecipe(witherSkull, netherBrick, ghastTear, waterBottle, new ItemStack(ModItems.imbue, 1, 3));
    // Anvil
    if (Loader.isModLoaded("baubles")) {
        AnvilRecipeHandler.addAnvilRecipe(new ItemStack(ModItems.obsidianSkull), new ItemStack(Items.FIRE_CHARGE), new ItemStack(ModItems.obsidianSkullRing), 3);
    }
    AnvilRecipeHandler.addAnvilRecipe(new ItemStack(ModItems.waterWalkingBoots), new ItemStack(ModItems.obsidianSkull), new ItemStack(ModItems.obsidianWaterWalkingBoots), 10);
    AnvilRecipeHandler.addAnvilRecipe(new ItemStack(ModItems.waterWalkingBoots), new ItemStack(ModItems.obsidianSkullRing), new ItemStack(ModItems.obsidianWaterWalkingBoots), 10);
    AnvilRecipeHandler.addAnvilRecipe(new ItemStack(ModItems.obsidianWaterWalkingBoots), new ItemStack(ModItems.lavaCharm), new ItemStack(ModItems.lavaWader), 15);
    // Spectre Anchor
    IRecipe anchorRecipe = new SimpleRecipe(new ResourceLocation("randomthings", "spectreAnchorCombine")) {

        @Override
        public boolean matches(InventoryCrafting inv, World worldIn) {
            ItemStack anchor = null;
            ItemStack target = null;
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                ItemStack is = inv.getStackInSlot(i);
                if (!is.isEmpty()) {
                    if (is.getItem() == ModItems.spectreAnchor) {
                        if (anchor == null) {
                            anchor = is;
                        } else {
                            return false;
                        }
                    } else {
                        if (target == null) {
                            if (is.getMaxStackSize() != 1) {
                                return false;
                            } else {
                                target = is;
                            }
                        } else {
                            return false;
                        }
                    }
                }
            }
            return anchor != null && target != null && (!target.hasTagCompound() || !target.getTagCompound().hasKey("spectreAnchor"));
        }

        @Override
        public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
            return NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
        }

        @Override
        public ItemStack getRecipeOutput() {
            return new ItemStack(ModItems.spectreAnchor);
        }

        @Override
        public ItemStack getCraftingResult(InventoryCrafting inv) {
            ItemStack anchor = null;
            ItemStack target = null;
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                ItemStack is = inv.getStackInSlot(i);
                if (!is.isEmpty()) {
                    if (is.getItem() == ModItems.spectreAnchor) {
                        anchor = is;
                    } else {
                        target = is;
                    }
                }
            }
            ItemStack result = target.copy();
            result.setTagInfo("spectreAnchor", new NBTTagByte((byte) 0));
            return result;
        }

        @Override
        public boolean canFit(int width, int height) {
            return true;
        }
    };
    RecipeSorter.register("spectreAnchorCombine", anchorRecipe.getClass(), Category.SHAPELESS, "");
    ForgeRegistries.RECIPES.register(anchorRecipe);
    // Golden Compass
    IRecipe goldenCompassRecipe = new SimpleRecipe(new ResourceLocation("randomthings", "goldenCompassSetPosition")) {

        @Override
        public boolean matches(InventoryCrafting inv, World worldIn) {
            ItemStack compass = null;
            ItemStack target = null;
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                ItemStack is = inv.getStackInSlot(i);
                if (!is.isEmpty()) {
                    if (is.getItem() == ModItems.goldenCompass) {
                        if (compass == null) {
                            compass = is;
                        } else {
                            return false;
                        }
                    } else {
                        if (target == null) {
                            if (is.getItem() == ModItems.positionFilter) {
                                target = is;
                            } else {
                                return false;
                            }
                        } else {
                            return false;
                        }
                    }
                }
            }
            return compass != null && target != null && (!target.hasTagCompound() || !target.getTagCompound().hasKey("spectreAnchor"));
        }

        @Override
        public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
            NonNullList aitemstack = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                ItemStack is = inv.getStackInSlot(i);
                if (!is.isEmpty()) {
                    if (is.getItem() == ModItems.positionFilter) {
                        aitemstack.set(i, is.copy());
                    }
                }
            }
            return aitemstack;
        }

        @Override
        public ItemStack getRecipeOutput() {
            return new ItemStack(ModItems.goldenCompass);
        }

        @Override
        public ItemStack getCraftingResult(InventoryCrafting inv) {
            ItemStack compass = null;
            ItemStack target = null;
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                ItemStack is = inv.getStackInSlot(i);
                if (!is.isEmpty()) {
                    if (is.getItem() == ModItems.goldenCompass) {
                        compass = is;
                    } else {
                        target = is;
                    }
                }
            }
            ItemStack result = compass.copy();
            BlockPos pos = ItemPositionFilter.getPosition(target);
            if (pos != null) {
                if (result.getTagCompound() == null) {
                    result.setTagCompound(new NBTTagCompound());
                }
                NBTTagCompound compound = result.getTagCompound();
                compound.setInteger("targetX", pos.getX());
                compound.setInteger("targetZ", pos.getZ());
            }
            return result;
        }

        @Override
        public boolean canFit(int width, int height) {
            return true;
        }
    };
    RecipeSorter.register("goldenCompass", goldenCompassRecipe.getClass(), Category.SHAPELESS, "");
    ForgeRegistries.RECIPES.register(goldenCompassRecipe);
    // Luminous Powder
    IRecipe luminousPowderRecipe = new SimpleRecipe(new ResourceLocation("randomthings", "luminousPowder")) {

        @Override
        public boolean matches(InventoryCrafting inv, World worldIn) {
            ItemStack powder = null;
            ItemStack target = null;
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                ItemStack is = inv.getStackInSlot(i);
                if (!is.isEmpty()) {
                    if (is.getItem() == ModItems.ingredients && is.getItemDamage() == ItemIngredient.INGREDIENT.LUMINOUS_POWDER.id) {
                        if (powder == null) {
                            powder = is;
                        } else {
                            return false;
                        }
                    } else {
                        if (target == null) {
                            if (!is.isItemEnchanted()) {
                                return false;
                            } else {
                                target = is;
                            }
                        } else {
                            return false;
                        }
                    }
                }
            }
            return powder != null && target != null && (!target.hasTagCompound() || !target.getTagCompound().hasKey("luminousEnchantment"));
        }

        @Override
        public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
            return NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
        }

        @Override
        public ItemStack getRecipeOutput() {
            return new ItemStack(ModItems.spectreAnchor);
        }

        @Override
        public ItemStack getCraftingResult(InventoryCrafting inv) {
            ItemStack powder = null;
            ItemStack target = null;
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                ItemStack is = inv.getStackInSlot(i);
                if (!is.isEmpty()) {
                    if (is.getItem() == ModItems.ingredients) {
                        powder = is;
                    } else {
                        target = is;
                    }
                }
            }
            ItemStack result = target.copy();
            result.setTagInfo("luminousEnchantment", new NBTTagByte((byte) 0));
            return result;
        }

        @Override
        public boolean canFit(int width, int height) {
            return true;
        }
    };
    RecipeSorter.register("luminousPowder", luminousPowderRecipe.getClass(), Category.SHAPELESS, "");
    ForgeRegistries.RECIPES.register(luminousPowderRecipe);
    // Emerald Compass
    IRecipe emeraldCompassRecipe = new SimpleRecipe(new ResourceLocation("randomthings", "emeraldcompass_settarget")) {

        @Override
        public boolean matches(InventoryCrafting inv, World worldIn) {
            ItemStack compass = null;
            ItemStack target = null;
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                ItemStack is = inv.getStackInSlot(i);
                if (!is.isEmpty()) {
                    if (is.getItem() == ModItems.emeraldCompass) {
                        if (compass == null) {
                            compass = is;
                        } else {
                            return false;
                        }
                    } else {
                        if (target == null) {
                            if (is.getItem() == ModItems.idCard) {
                                target = is;
                            } else {
                                return false;
                            }
                        } else {
                            return false;
                        }
                    }
                }
            }
            return compass != null && target != null && (!target.hasTagCompound() || !target.getTagCompound().hasKey("spectreAnchor"));
        }

        @Override
        public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
            NonNullList aitemstack = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                ItemStack is = inv.getStackInSlot(i);
                if (!is.isEmpty()) {
                    if (is.getItem() == ModItems.idCard) {
                        aitemstack.set(i, is.copy());
                    }
                }
            }
            return aitemstack;
        }

        @Override
        public ItemStack getRecipeOutput() {
            return new ItemStack(ModItems.emeraldCompass);
        }

        @Override
        public ItemStack getCraftingResult(InventoryCrafting inv) {
            ItemStack compass = null;
            ItemStack target = null;
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                ItemStack is = inv.getStackInSlot(i);
                if (!is.isEmpty()) {
                    if (is.getItem() == ModItems.emeraldCompass) {
                        compass = is;
                    } else {
                        target = is;
                    }
                }
            }
            ItemStack result = compass.copy();
            UUID uuid = ItemIDCard.getUUID(target);
            if (uuid != null) {
                if (result.getTagCompound() == null) {
                    result.setTagCompound(new NBTTagCompound());
                }
                NBTTagCompound compound = result.getTagCompound();
                compound.setString("uuid", uuid.toString());
            }
            return result;
        }

        @Override
        public boolean canFit(int width, int height) {
            return true;
        }
    };
    // Emerald Compass
    IRecipe portKeyCamoRecipe = new SimpleRecipe(new ResourceLocation("randomthings", "portkey_camo")) {

        @Override
        public boolean matches(InventoryCrafting inv, World worldIn) {
            ItemStack portkey = null;
            ItemStack camo = null;
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                ItemStack is = inv.getStackInSlot(i);
                if (!is.isEmpty()) {
                    if (is.getItem() == ModItems.portKey) {
                        if (portkey == null) {
                            portkey = is;
                        } else {
                            return false;
                        }
                    } else if (is.getItem() != ModItems.portKey) {
                        if (camo == null) {
                            camo = is;
                        } else {
                            return false;
                        }
                    }
                }
            }
            return portkey != null && camo != null;
        }

        @Override
        public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
            NonNullList aitemstack = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                ItemStack is = inv.getStackInSlot(i);
                if (!is.isEmpty()) {
                    if (is.getItem() != ModItems.portKey) {
                        aitemstack.set(i, is.copy());
                    }
                }
            }
            return aitemstack;
        }

        @Override
        public ItemStack getRecipeOutput() {
            return new ItemStack(ModItems.portKey);
        }

        @Override
        public ItemStack getCraftingResult(InventoryCrafting inv) {
            ItemStack portKey = null;
            ItemStack camo = null;
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                ItemStack is = inv.getStackInSlot(i);
                if (!is.isEmpty()) {
                    if (is.getItem() == ModItems.portKey) {
                        portKey = is;
                    } else {
                        camo = is;
                    }
                }
            }
            ItemStack result = portKey.copy();
            UUID uuid = ItemIDCard.getUUID(camo);
            NBTTagCompound camoTag = result.getOrCreateSubCompound("camo");
            NBTTagCompound stackTag = new NBTTagCompound();
            camo.writeToNBT(stackTag);
            camoTag.setTag("stack", stackTag);
            return result;
        }

        @Override
        public boolean canFit(int width, int height) {
            return true;
        }
    };
    RecipeSorter.register("portKeyCamoRecipe", portKeyCamoRecipe.getClass(), Category.SHAPELESS, "");
    ForgeRegistries.RECIPES.register(portKeyCamoRecipe);
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) NBTTagByte(net.minecraft.nbt.NBTTagByte) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) InventoryCrafting(net.minecraft.inventory.InventoryCrafting) World(net.minecraft.world.World) NonNullList(net.minecraft.util.NonNullList) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) UUID(java.util.UUID)

Example 3 with NBTTagByte

use of net.minecraft.nbt.NBTTagByte in project BuildCraft by BuildCraft.

the class NBTUtilBC method writeEnumSet.

/**
 * Writes an {@link EnumSet} to an {@link NBTBase}. The returned type will either be {@link NBTTagByte} or
 * {@link NBTTagByteArray}.
 *
 * @param clazz The class that the {@link EnumSet} is of. This is required as we have no way of getting the class
 *            from the set.
 */
public static <E extends Enum<E>> NBTBase writeEnumSet(EnumSet<E> set, Class<E> clazz) {
    E[] constants = clazz.getEnumConstants();
    if (constants == null)
        throw new IllegalArgumentException("Not an enum type " + clazz);
    BitSet bitset = new BitSet();
    for (E e : constants) {
        if (set.contains(e)) {
            bitset.set(e.ordinal());
        }
    }
    byte[] bytes = bitset.toByteArray();
    if (bytes.length == 1) {
        return new NBTTagByte(bytes[0]);
    } else {
        return new NBTTagByteArray(bytes);
    }
}
Also used : NBTTagByte(net.minecraft.nbt.NBTTagByte) BitSet(java.util.BitSet) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray)

Example 4 with NBTTagByte

use of net.minecraft.nbt.NBTTagByte in project BuildCraft by BuildCraft.

the class JsonUtil method registerNbtSerializersDeserializers.

public static GsonBuilder registerNbtSerializersDeserializers(GsonBuilder gsonBuilder) {
    return gsonBuilder.registerTypeAdapterFactory(new TypeAdapterFactory() {

        @Override
        public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
            return type.getRawType() == NBTBase.class ? new TypeAdapter<T>() {

                @Override
                public void write(JsonWriter out, T value) throws IOException {
                    // noinspection unchecked, RedundantCast
                    Streams.write(((JsonSerializer<T>) (JsonSerializer<NBTBase>) (src, typeOfSrc, context) -> {
                        if (src == NBTUtilBC.NBT_NULL) {
                            return JsonNull.INSTANCE;
                        }
                        switch(src.getId()) {
                            case Constants.NBT.TAG_BYTE:
                                return context.serialize(src, NBTTagByte.class);
                            case Constants.NBT.TAG_SHORT:
                                return context.serialize(src, NBTTagShort.class);
                            case Constants.NBT.TAG_INT:
                                return context.serialize(src, NBTTagInt.class);
                            case Constants.NBT.TAG_LONG:
                                return context.serialize(src, NBTTagLong.class);
                            case Constants.NBT.TAG_FLOAT:
                                return context.serialize(src, NBTTagFloat.class);
                            case Constants.NBT.TAG_DOUBLE:
                                return context.serialize(src, NBTTagDouble.class);
                            case Constants.NBT.TAG_BYTE_ARRAY:
                                return context.serialize(src, NBTTagByteArray.class);
                            case Constants.NBT.TAG_STRING:
                                return context.serialize(src, NBTTagString.class);
                            case Constants.NBT.TAG_LIST:
                                return context.serialize(src, NBTTagList.class);
                            case Constants.NBT.TAG_COMPOUND:
                                return context.serialize(src, NBTTagCompound.class);
                            case Constants.NBT.TAG_INT_ARRAY:
                                return context.serialize(src, NBTTagIntArray.class);
                            default:
                                throw new IllegalArgumentException(src.toString());
                        }
                    }).serialize(value, type.getType(), new JsonSerializationContext() {

                        @Override
                        public JsonElement serialize(Object src) {
                            return gson.toJsonTree(src);
                        }

                        @Override
                        public JsonElement serialize(Object src, Type typeOfSrc) {
                            return gson.toJsonTree(src, typeOfSrc);
                        }
                    }), out);
                }

                @Override
                public T read(JsonReader in) throws IOException {
                    return ((JsonDeserializer<T>) (json, typeOfT, context) -> {
                        if (json.isJsonNull()) {
                            // noinspection unchecked
                            return (T) NBTUtilBC.NBT_NULL;
                        }
                        if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isNumber()) {
                            Number number = json.getAsJsonPrimitive().getAsNumber();
                            if (number instanceof BigInteger || number instanceof Long || number instanceof Integer || number instanceof Short || number instanceof Byte) {
                                return context.deserialize(json, NBTTagLong.class);
                            } else {
                                return context.deserialize(json, NBTTagDouble.class);
                            }
                        }
                        if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isBoolean()) {
                            return context.deserialize(new JsonPrimitive(json.getAsJsonPrimitive().getAsBoolean() ? (byte) 1 : (byte) 0), NBTTagByte.class);
                        }
                        if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isString()) {
                            return context.deserialize(json, NBTTagString.class);
                        }
                        if (json.isJsonArray()) {
                            return context.deserialize(json, NBTTagList.class);
                        }
                        if (json.isJsonObject()) {
                            return context.deserialize(json, NBTTagCompound.class);
                        }
                        throw new IllegalArgumentException(json.toString());
                    }).deserialize(Streams.parse(in), type.getType(), gson::fromJson);
                }
            } : null;
        }
    }).registerTypeAdapter(NBTTagByte.class, (JsonSerializer<NBTTagByte>) (src, typeOfSrc, context) -> new JsonPrimitive(src.getByte())).registerTypeAdapter(NBTTagByte.class, (JsonDeserializer<NBTTagByte>) (json, typeOfT, context) -> new NBTTagByte(json.getAsJsonPrimitive().getAsByte())).registerTypeAdapter(NBTTagShort.class, (JsonSerializer<NBTTagShort>) (src, typeOfSrc, context) -> new JsonPrimitive(src.getShort())).registerTypeAdapter(NBTTagShort.class, (JsonDeserializer<NBTTagShort>) (json, typeOfT, context) -> new NBTTagShort(json.getAsJsonPrimitive().getAsShort())).registerTypeAdapter(NBTTagInt.class, (JsonSerializer<NBTTagInt>) (src, typeOfSrc, context) -> new JsonPrimitive(src.getInt())).registerTypeAdapter(NBTTagInt.class, (JsonDeserializer<NBTTagInt>) (json, typeOfT, context) -> new NBTTagInt(json.getAsJsonPrimitive().getAsInt())).registerTypeAdapter(NBTTagLong.class, (JsonSerializer<NBTTagLong>) (src, typeOfSrc, context) -> new JsonPrimitive(src.getLong())).registerTypeAdapter(NBTTagLong.class, (JsonDeserializer<NBTTagLong>) (json, typeOfT, context) -> new NBTTagLong(json.getAsJsonPrimitive().getAsLong())).registerTypeAdapter(NBTTagFloat.class, (JsonSerializer<NBTTagFloat>) (src, typeOfSrc, context) -> new JsonPrimitive(src.getFloat())).registerTypeAdapter(NBTTagFloat.class, (JsonDeserializer<NBTTagFloat>) (json, typeOfT, context) -> new NBTTagFloat(json.getAsJsonPrimitive().getAsFloat())).registerTypeAdapter(NBTTagDouble.class, (JsonSerializer<NBTTagDouble>) (src, typeOfSrc, context) -> new JsonPrimitive(src.getDouble())).registerTypeAdapter(NBTTagDouble.class, (JsonDeserializer<NBTTagDouble>) (json, typeOfT, context) -> new NBTTagDouble(json.getAsJsonPrimitive().getAsDouble())).registerTypeAdapter(NBTTagByteArray.class, (JsonSerializer<NBTTagByteArray>) (src, typeOfSrc, context) -> {
        JsonArray jsonArray = new JsonArray();
        for (byte element : src.getByteArray()) {
            jsonArray.add(new JsonPrimitive(element));
        }
        return jsonArray;
    }).registerTypeAdapter(NBTTagByteArray.class, (JsonDeserializer<NBTTagByteArray>) (json, typeOfT, context) -> new NBTTagByteArray(ArrayUtils.toPrimitive(StreamSupport.stream(json.getAsJsonArray().spliterator(), false).map(JsonElement::getAsByte).toArray(Byte[]::new)))).registerTypeAdapter(NBTTagString.class, (JsonSerializer<NBTTagString>) (src, typeOfSrc, context) -> new JsonPrimitive(src.getString())).registerTypeAdapter(NBTTagString.class, (JsonDeserializer<NBTTagString>) (json, typeOfT, context) -> new NBTTagString(json.getAsJsonPrimitive().getAsString())).registerTypeAdapter(NBTTagList.class, (JsonSerializer<NBTTagList>) (src, typeOfSrc, context) -> {
        JsonArray jsonArray = new JsonArray();
        for (int i = 0; i < src.tagCount(); i++) {
            NBTBase element = src.get(i);
            jsonArray.add(context.serialize(element, NBTBase.class));
        }
        return jsonArray;
    }).registerTypeAdapter(NBTTagList.class, (JsonDeserializer<NBTTagList>) (json, typeOfT, context) -> {
        NBTTagList nbtTagList = new NBTTagList();
        StreamSupport.stream(json.getAsJsonArray().spliterator(), false).map(element -> context.<NBTBase>deserialize(element, NBTBase.class)).forEach(nbtTagList::appendTag);
        return nbtTagList;
    }).registerTypeAdapter(NBTTagCompound.class, (JsonSerializer<NBTTagCompound>) (src, typeOfSrc, context) -> {
        JsonObject jsonObject = new JsonObject();
        for (String key : src.getKeySet()) {
            jsonObject.add(key, context.serialize(src.getTag(key), NBTBase.class));
        }
        return jsonObject;
    }).registerTypeAdapter(NBTTagCompound.class, (JsonDeserializer<NBTTagCompound>) (json, typeOfT, context) -> {
        NBTTagCompound nbtTagCompound = new NBTTagCompound();
        for (Map.Entry<String, JsonElement> entry : json.getAsJsonObject().entrySet()) {
            nbtTagCompound.setTag(entry.getKey(), context.deserialize(entry.getValue(), NBTBase.class));
        }
        return nbtTagCompound;
    }).registerTypeAdapter(NBTTagIntArray.class, (JsonSerializer<NBTTagIntArray>) (src, typeOfSrc, context) -> {
        JsonArray jsonArray = new JsonArray();
        for (int element : src.getIntArray()) {
            jsonArray.add(new JsonPrimitive(element));
        }
        return jsonArray;
    }).registerTypeAdapter(NBTTagIntArray.class, (JsonDeserializer<NBTTagIntArray>) (json, typeOfT, context) -> new NBTTagIntArray(StreamSupport.stream(json.getAsJsonArray().spliterator(), false).mapToInt(JsonElement::getAsByte).toArray()));
}
Also used : JsonObject(com.google.gson.JsonObject) TypeToken(com.google.gson.reflect.TypeToken) NBTTagByte(net.minecraft.nbt.NBTTagByte) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray) Constants(net.minecraftforge.common.util.Constants) HashMap(java.util.HashMap) JsonSerializer(com.google.gson.JsonSerializer) ArrayUtils(org.apache.commons.lang3.ArrayUtils) NBTTagString(net.minecraft.nbt.NBTTagString) GsonBuilder(com.google.gson.GsonBuilder) TypeAdapter(com.google.gson.TypeAdapter) JsonReader(com.google.gson.stream.JsonReader) NBTTagFloat(net.minecraft.nbt.NBTTagFloat) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) NBTTagList(net.minecraft.nbt.NBTTagList) ImmutableList(com.google.common.collect.ImmutableList) Gson(com.google.gson.Gson) Map(java.util.Map) JsonSerializationContext(com.google.gson.JsonSerializationContext) BigInteger(java.math.BigInteger) StreamSupport(java.util.stream.StreamSupport) JsonPrimitive(com.google.gson.JsonPrimitive) JsonWriter(com.google.gson.stream.JsonWriter) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagInt(net.minecraft.nbt.NBTTagInt) NBTTagDouble(net.minecraft.nbt.NBTTagDouble) NBTTagShort(net.minecraft.nbt.NBTTagShort) Streams(com.google.gson.internal.Streams) ImmutableMap(com.google.common.collect.ImmutableMap) JsonSyntaxException(com.google.gson.JsonSyntaxException) NBTBase(net.minecraft.nbt.NBTBase) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) IOException(java.io.IOException) JsonArray(com.google.gson.JsonArray) Type(java.lang.reflect.Type) JsonNull(com.google.gson.JsonNull) Entry(java.util.Map.Entry) JsonDeserializer(com.google.gson.JsonDeserializer) NBTTagLong(net.minecraft.nbt.NBTTagLong) TypeAdapterFactory(com.google.gson.TypeAdapterFactory) JsonPrimitive(com.google.gson.JsonPrimitive) NBTTagByte(net.minecraft.nbt.NBTTagByte) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) JsonSerializer(com.google.gson.JsonSerializer) NBTTagString(net.minecraft.nbt.NBTTagString) JsonDeserializer(com.google.gson.JsonDeserializer) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) NBTTagList(net.minecraft.nbt.NBTTagList) Entry(java.util.Map.Entry) NBTBase(net.minecraft.nbt.NBTBase) JsonReader(com.google.gson.stream.JsonReader) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagShort(net.minecraft.nbt.NBTTagShort) TypeAdapterFactory(com.google.gson.TypeAdapterFactory) NBTTagFloat(net.minecraft.nbt.NBTTagFloat) NBTTagInt(net.minecraft.nbt.NBTTagInt) JsonWriter(com.google.gson.stream.JsonWriter) BigInteger(java.math.BigInteger) JsonArray(com.google.gson.JsonArray) Type(java.lang.reflect.Type) NBTTagShort(net.minecraft.nbt.NBTTagShort) JsonElement(com.google.gson.JsonElement) JsonSerializationContext(com.google.gson.JsonSerializationContext) NBTTagByte(net.minecraft.nbt.NBTTagByte) TypeAdapter(com.google.gson.TypeAdapter) NBTTagLong(net.minecraft.nbt.NBTTagLong) BigInteger(java.math.BigInteger) JsonObject(com.google.gson.JsonObject) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray) NBTTagLong(net.minecraft.nbt.NBTTagLong) NBTTagDouble(net.minecraft.nbt.NBTTagDouble)

Example 5 with NBTTagByte

use of net.minecraft.nbt.NBTTagByte in project LogisticsPipes by RS485.

the class ItemIdentifier method debugDumpTag.

private void debugDumpTag(NBTBase nbt, StringBuilder sb) {
    if (nbt == null) {
        sb.append("null");
        return;
    }
    if (nbt instanceof NBTTagByte) {
        sb.append("TagByte(data=").append(((NBTTagByte) nbt).getByte()).append(")");
    } else if (nbt instanceof NBTTagShort) {
        sb.append("TagShort(data=").append(((NBTTagShort) nbt).getShort()).append(")");
    } else if (nbt instanceof NBTTagInt) {
        sb.append("TagInt(data=").append(((NBTTagInt) nbt).getInt()).append(")");
    } else if (nbt instanceof NBTTagLong) {
        sb.append("TagLong(data=").append(((NBTTagLong) nbt).getLong()).append(")");
    } else if (nbt instanceof NBTTagFloat) {
        sb.append("TagFloat(data=").append(((NBTTagFloat) nbt).getFloat()).append(")");
    } else if (nbt instanceof NBTTagDouble) {
        sb.append("TagDouble(data=").append(((NBTTagDouble) nbt).getDouble()).append(")");
    } else if (nbt instanceof NBTTagString) {
        sb.append("TagString(data=\"").append(((NBTTagString) nbt).getString()).append("\")");
    } else if (nbt instanceof NBTTagByteArray) {
        sb.append("TagByteArray(data=");
        for (int i = 0; i < ((NBTTagByteArray) nbt).getByteArray().length; i++) {
            sb.append(((NBTTagByteArray) nbt).getByteArray()[i]);
            if (i < ((NBTTagByteArray) nbt).getByteArray().length - 1) {
                sb.append(",");
            }
        }
        sb.append(")");
    } else if (nbt instanceof NBTTagIntArray) {
        sb.append("TagIntArray(data=");
        for (int i = 0; i < ((NBTTagIntArray) nbt).getIntArray().length; i++) {
            sb.append(((NBTTagIntArray) nbt).getIntArray()[i]);
            if (i < ((NBTTagIntArray) nbt).getIntArray().length - 1) {
                sb.append(",");
            }
        }
        sb.append(")");
    } else if (nbt instanceof NBTTagList) {
        sb.append("TagList(data=");
        for (int i = 0; i < ((NBTTagList) nbt).tagCount(); i++) {
            debugDumpTag((((NBTTagList) nbt).get(i)), sb);
            if (i < ((NBTTagList) nbt).tagCount() - 1) {
                sb.append(",");
            }
        }
        sb.append(")");
    } else if (nbt instanceof NBTTagCompound) {
        sb.append("TagCompound(data=");
        for (Iterator<String> iter = ((NBTTagCompound) nbt).getKeySet().iterator(); iter.hasNext(); ) {
            String key = iter.next();
            NBTBase value = ((NBTTagCompound) nbt).getTag(key);
            sb.append("\"").append(key).append("\"=");
            debugDumpTag((value), sb);
            if (iter.hasNext()) {
                sb.append(",");
            }
        }
        sb.append(")");
    } else {
        sb.append(nbt.getClass().getName()).append("(?)");
    }
}
Also used : NBTTagFloat(net.minecraft.nbt.NBTTagFloat) NBTTagInt(net.minecraft.nbt.NBTTagInt) NBTTagByte(net.minecraft.nbt.NBTTagByte) FinalNBTTagCompound(logisticspipes.utils.FinalNBTTagCompound) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagShort(net.minecraft.nbt.NBTTagShort) NBTBase(net.minecraft.nbt.NBTBase) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray) NBTTagLong(net.minecraft.nbt.NBTTagLong) NBTTagDouble(net.minecraft.nbt.NBTTagDouble)

Aggregations

NBTTagByte (net.minecraft.nbt.NBTTagByte)13 NBTTagByteArray (net.minecraft.nbt.NBTTagByteArray)10 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)10 NBTTagList (net.minecraft.nbt.NBTTagList)9 NBTTagString (net.minecraft.nbt.NBTTagString)9 NBTTagDouble (net.minecraft.nbt.NBTTagDouble)8 NBTTagFloat (net.minecraft.nbt.NBTTagFloat)8 NBTTagInt (net.minecraft.nbt.NBTTagInt)8 NBTTagIntArray (net.minecraft.nbt.NBTTagIntArray)8 NBTTagLong (net.minecraft.nbt.NBTTagLong)8 NBTTagShort (net.minecraft.nbt.NBTTagShort)7 NBTBase (net.minecraft.nbt.NBTBase)5 Map (java.util.Map)4 List (java.util.List)3 TByteArrayList (gnu.trove.list.array.TByteArrayList)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 ArrayList (java.util.ArrayList)2 BitSet (java.util.BitSet)2 HashMap (java.util.HashMap)2 Entry (java.util.Map.Entry)2