Search in sources :

Example 1 with ByteBufUtils

use of hellfirepvp.astralsorcery.common.util.data.ByteBufUtils in project AstralSorcery by HellFirePvP.

the class PlayerPerkData method read.

public static PlayerPerkData read(PacketBuffer buf, LogicalSide side) {
    PlayerPerkData data = new PlayerPerkData();
    data.perkExp = buf.readDouble();
    data.freePointTokens = ByteBufUtils.readSet(buf, ByteBufUtils::readResourceLocation);
    Set<AppliedPerk> appliedPerks = ByteBufUtils.readSet(buf, buffer -> {
        ResourceLocation key = ByteBufUtils.readResourceLocation(buffer);
        return PerkTree.PERK_TREE.getPerk(side, key).map(AppliedPerk::new).map(perk -> {
            perk.read(buffer);
            return perk;
        }).orElseThrow(() -> new IllegalArgumentException("Unknown perk: " + key));
    });
    appliedPerks.forEach(appliedPerk -> data.perks.put(appliedPerk.getPerk(), appliedPerk));
    return data;
}
Also used : PerkLevelManager(hellfirepvp.astralsorcery.common.perk.PerkLevelManager) ListNBT(net.minecraft.nbt.ListNBT) StringNBT(net.minecraft.nbt.StringNBT) IntStream(java.util.stream.IntStream) ByteBufUtils(hellfirepvp.astralsorcery.common.util.data.ByteBufUtils) java.util(java.util) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) PlayerEntity(net.minecraft.entity.player.PlayerEntity) NBTHelper(hellfirepvp.astralsorcery.common.util.nbt.NBTHelper) Predicate(java.util.function.Predicate) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) AbstractPerk(hellfirepvp.astralsorcery.common.perk.AbstractPerk) Collectors(java.util.stream.Collectors) Dist(net.minecraftforge.api.distmarker.Dist) PktSyncKnowledge(hellfirepvp.astralsorcery.common.network.play.server.PktSyncKnowledge) PerkTree(hellfirepvp.astralsorcery.common.perk.PerkTree) AstralSorcery(hellfirepvp.astralsorcery.AstralSorcery) MathHelper(net.minecraft.util.math.MathHelper) ResourceLocation(net.minecraft.util.ResourceLocation) MapStream(hellfirepvp.astralsorcery.common.util.MapStream) PacketBuffer(net.minecraft.network.PacketBuffer) Nullable(javax.annotation.Nullable) LogicalSide(net.minecraftforge.fml.LogicalSide) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 2 with ByteBufUtils

use of hellfirepvp.astralsorcery.common.util.data.ByteBufUtils in project AstralSorcery by HellFirePvP.

the class BlockTransmutationSerializer method read.

@Nullable
@Override
public BlockTransmutation read(ResourceLocation recipeId, PacketBuffer buffer) {
    List<BlockMatchInformation> matchInformation = ByteBufUtils.readList(buffer, BlockMatchInformation::read);
    BlockState output = ByteBufUtils.readBlockState(buffer);
    ItemStack display = ByteBufUtils.readItemStack(buffer);
    double starlight = buffer.readDouble();
    IWeakConstellation cst = ByteBufUtils.readOptional(buffer, ByteBufUtils::readRegistryEntry);
    BlockTransmutation tr = new BlockTransmutation(recipeId, output, starlight, cst);
    matchInformation.forEach(tr::addInputOption);
    tr.setOutputDisplay(display);
    return tr;
}
Also used : BlockState(net.minecraft.block.BlockState) ByteBufUtils(hellfirepvp.astralsorcery.common.util.data.ByteBufUtils) ItemStack(net.minecraft.item.ItemStack) BlockMatchInformation(hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation) BlockTransmutation(hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation) IWeakConstellation(hellfirepvp.astralsorcery.common.constellation.IWeakConstellation) Nullable(javax.annotation.Nullable)

Example 3 with ByteBufUtils

use of hellfirepvp.astralsorcery.common.util.data.ByteBufUtils in project AstralSorcery by HellFirePvP.

the class SimpleAltarRecipe method read.

public static SimpleAltarRecipe read(ResourceLocation recipeId, PacketBuffer buffer) {
    AltarType type = ByteBufUtils.readEnumValue(buffer, AltarType.class);
    int duration = buffer.readInt();
    int starlight = buffer.readInt();
    AltarRecipeGrid grid = AltarRecipeGrid.read(buffer);
    SimpleAltarRecipe recipe = new SimpleAltarRecipe(recipeId, type, duration, starlight, grid);
    ResourceLocation customType = ByteBufUtils.readOptional(buffer, ByteBufUtils::readResourceLocation);
    if (customType != null) {
        recipe = AltarRecipeTypeHandler.convert(recipe, customType);
        recipe.setCustomRecipeType(customType);
    }
    List<ItemStack> outputs = ByteBufUtils.readList(buffer, ByteBufUtils::readItemStack);
    outputs.forEach(recipe::addOutput);
    recipe.setFocusConstellation(ByteBufUtils.readOptional(buffer, ByteBufUtils::readRegistryEntry));
    ByteBufUtils.readList(buffer, Ingredient::read).forEach(recipe::addRelayInput);
    List<AltarRecipeEffect> effects = ByteBufUtils.readList(buffer, ByteBufUtils::readRegistryEntry);
    for (AltarRecipeEffect effect : effects) {
        recipe.addAltarEffect(effect);
    }
    recipe.readRecipeSync(buffer);
    return recipe;
}
Also used : AltarType(hellfirepvp.astralsorcery.common.block.tile.altar.AltarType) ByteBufUtils(hellfirepvp.astralsorcery.common.util.data.ByteBufUtils) ResourceLocation(net.minecraft.util.ResourceLocation) AltarRecipeGrid(hellfirepvp.astralsorcery.common.crafting.recipe.altar.AltarRecipeGrid) ItemStack(net.minecraft.item.ItemStack) ActiveSimpleAltarRecipe(hellfirepvp.astralsorcery.common.crafting.recipe.altar.ActiveSimpleAltarRecipe) AltarRecipeEffect(hellfirepvp.astralsorcery.common.crafting.recipe.altar.effect.AltarRecipeEffect)

Aggregations

ByteBufUtils (hellfirepvp.astralsorcery.common.util.data.ByteBufUtils)3 Nullable (javax.annotation.Nullable)2 ItemStack (net.minecraft.item.ItemStack)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 AstralSorcery (hellfirepvp.astralsorcery.AstralSorcery)1 AltarType (hellfirepvp.astralsorcery.common.block.tile.altar.AltarType)1 IWeakConstellation (hellfirepvp.astralsorcery.common.constellation.IWeakConstellation)1 BlockTransmutation (hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation)1 ActiveSimpleAltarRecipe (hellfirepvp.astralsorcery.common.crafting.recipe.altar.ActiveSimpleAltarRecipe)1 AltarRecipeGrid (hellfirepvp.astralsorcery.common.crafting.recipe.altar.AltarRecipeGrid)1 AltarRecipeEffect (hellfirepvp.astralsorcery.common.crafting.recipe.altar.effect.AltarRecipeEffect)1 PktSyncKnowledge (hellfirepvp.astralsorcery.common.network.play.server.PktSyncKnowledge)1 AbstractPerk (hellfirepvp.astralsorcery.common.perk.AbstractPerk)1 PerkLevelManager (hellfirepvp.astralsorcery.common.perk.PerkLevelManager)1 PerkTree (hellfirepvp.astralsorcery.common.perk.PerkTree)1 MapStream (hellfirepvp.astralsorcery.common.util.MapStream)1 BlockMatchInformation (hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation)1 NBTHelper (hellfirepvp.astralsorcery.common.util.nbt.NBTHelper)1 java.util (java.util)1 Predicate (java.util.function.Predicate)1