Search in sources :

Example 1 with BlockMatchInformation

use of hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation in project AstralSorcery by HellFirePvP.

the class BlockTransmutationBuilder method validateAndGet.

@Nonnull
@Override
protected BlockTransmutation validateAndGet() {
    if (this.stateCheck.isEmpty()) {
        throw new IllegalArgumentException("No block input checks!");
    }
    for (BlockMatchInformation inputMatch : this.stateCheck) {
        if (!inputMatch.isValid()) {
            throw new IllegalArgumentException("A block transmutation must not convert 'air' into something!");
        }
    }
    BlockTransmutation tr = new BlockTransmutation(this.id, this.outputState, this.starlight, this.constellation);
    this.stateCheck.forEach(tr::addInputOption);
    tr.setOutputDisplay(this.outputDisplay);
    return tr;
}
Also used : BlockMatchInformation(hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation) BlockTransmutation(hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation) Nonnull(javax.annotation.Nonnull)

Example 2 with BlockMatchInformation

use of hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation 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 BlockMatchInformation

use of hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation in project AstralSorcery by HellFirePvP.

the class BlockTransmutationSerializer method read.

@Override
public BlockTransmutation read(ResourceLocation recipeId, JsonObject json) {
    List<BlockMatchInformation> matchInformation = new ArrayList<>();
    JsonHelper.parseMultipleJsonObjects(json, "input", object -> matchInformation.add(BlockMatchInformation.read(object)));
    if (matchInformation.isEmpty()) {
        throw new IllegalArgumentException("A block transmutation has to have at least 1 input!");
    }
    for (BlockMatchInformation info : matchInformation) {
        if (!info.isValid()) {
            throw new JsonSyntaxException("Block transmutation must not convert an air-block into something!");
        }
    }
    BlockState output = BlockStateHelper.deserializeObject(JSONUtils.getJsonObject(json, "output"));
    ItemStack outputDisplay = new ItemStack(output.getBlock());
    if (JSONUtils.hasField(json, "display")) {
        outputDisplay = JsonHelper.getItemStack(json, "display");
    }
    float starlight = JSONUtils.getFloat(json, "starlight");
    IWeakConstellation matchConstellation = null;
    if (json.has("constellation")) {
        ResourceLocation cstKey = new ResourceLocation(JSONUtils.getString(json, "constellation"));
        IConstellation cst = RegistriesAS.REGISTRY_CONSTELLATIONS.getValue(cstKey);
        if (cst == null) {
            throw new JsonSyntaxException(String.format("Unknown constellation %s!", cstKey.toString()));
        }
        if (!(cst instanceof IWeakConstellation)) {
            throw new JsonSyntaxException(String.format("Constellation %s has to be either a major or dim constellation!", cstKey.toString()));
        }
        matchConstellation = (IWeakConstellation) cst;
    }
    BlockTransmutation tr = new BlockTransmutation(recipeId, output, starlight, matchConstellation);
    matchInformation.forEach(tr::addInputOption);
    tr.setOutputDisplay(outputDisplay);
    return tr;
}
Also used : ArrayList(java.util.ArrayList) BlockMatchInformation(hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation) IWeakConstellation(hellfirepvp.astralsorcery.common.constellation.IWeakConstellation) IConstellation(hellfirepvp.astralsorcery.common.constellation.IConstellation) JsonSyntaxException(com.google.gson.JsonSyntaxException) BlockState(net.minecraft.block.BlockState) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack) BlockTransmutation(hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation)

Example 4 with BlockMatchInformation

use of hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation in project AstralSorcery by HellFirePvP.

the class BlockTransmutationSerializer method write.

@Override
public void write(JsonObject object, BlockTransmutation recipe) {
    JsonArray inputs = new JsonArray();
    for (BlockMatchInformation info : recipe.getInputOptions()) {
        inputs.add(info.serializeJson());
    }
    object.add("input", inputs);
    object.add("output", BlockStateHelper.serializeObject(recipe.getOutput(), true));
    object.add("display", JsonHelper.serializeItemStack(recipe.getOutputDisplay()));
    object.addProperty("starlight", recipe.getStarlightRequired());
    if (recipe.getRequiredConstellation() != null) {
        object.addProperty("constellation", recipe.getRequiredConstellation().getRegistryName().toString());
    }
}
Also used : JsonArray(com.google.gson.JsonArray) BlockMatchInformation(hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation)

Example 5 with BlockMatchInformation

use of hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation in project AstralSorcery by HellFirePvP.

the class BlockTransmutationManager method removeRecipe.

@ZenCodeType.Method
public void removeRecipe(BlockState outputState, boolean exact) {
    BlockMatchInformation matcher = new BlockMatchInformation(outputState, exact);
    CraftTweakerAPI.apply(new ActionRemoveRecipe(this, iRecipe -> {
        if (iRecipe instanceof BlockTransmutation) {
            BlockTransmutation recipe = (BlockTransmutation) iRecipe;
            return matcher.test(recipe.getOutput());
        }
        return false;
    }, action -> "Removing Block Transmutation recipes that output " + ExpandBlockState.getCommandString(outputState)));
}
Also used : CraftTweakerAPI(com.blamejared.crafttweaker.api.CraftTweakerAPI) ActionRemoveRecipe(com.blamejared.crafttweaker.impl.actions.recipes.ActionRemoveRecipe) IRecipeManager(com.blamejared.crafttweaker.api.managers.IRecipeManager) ActionAddRecipe(com.blamejared.crafttweaker.impl.actions.recipes.ActionAddRecipe) BlockTransmutation(hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation) RegistriesAS(hellfirepvp.astralsorcery.common.lib.RegistriesAS) ITag(net.minecraft.tags.ITag) ZenCodeType(org.openzen.zencode.java.ZenCodeType) IItemStack(com.blamejared.crafttweaker.api.item.IItemStack) ExpandBlockState(com.blamejared.crafttweaker.impl_native.blocks.ExpandBlockState) BlockMatchInformation(hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation) IRecipeType(net.minecraft.item.crafting.IRecipeType) Consumer(java.util.function.Consumer) ZenRegister(com.blamejared.crafttweaker.api.annotations.ZenRegister) Block(net.minecraft.block.Block) IWeakConstellation(hellfirepvp.astralsorcery.common.constellation.IWeakConstellation) ResourceLocation(net.minecraft.util.ResourceLocation) RecipeTypesAS(hellfirepvp.astralsorcery.common.lib.RecipeTypesAS) IConstellation(hellfirepvp.astralsorcery.common.constellation.IConstellation) MCTag(com.blamejared.crafttweaker.impl.tag.MCTag) BlockState(net.minecraft.block.BlockState) BlockMatchInformation(hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation) BlockTransmutation(hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation) ActionRemoveRecipe(com.blamejared.crafttweaker.impl.actions.recipes.ActionRemoveRecipe)

Aggregations

BlockMatchInformation (hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation)5 BlockTransmutation (hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation)4 IWeakConstellation (hellfirepvp.astralsorcery.common.constellation.IWeakConstellation)3 BlockState (net.minecraft.block.BlockState)3 IConstellation (hellfirepvp.astralsorcery.common.constellation.IConstellation)2 ItemStack (net.minecraft.item.ItemStack)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 CraftTweakerAPI (com.blamejared.crafttweaker.api.CraftTweakerAPI)1 ZenRegister (com.blamejared.crafttweaker.api.annotations.ZenRegister)1 IItemStack (com.blamejared.crafttweaker.api.item.IItemStack)1 IRecipeManager (com.blamejared.crafttweaker.api.managers.IRecipeManager)1 ActionAddRecipe (com.blamejared.crafttweaker.impl.actions.recipes.ActionAddRecipe)1 ActionRemoveRecipe (com.blamejared.crafttweaker.impl.actions.recipes.ActionRemoveRecipe)1 MCTag (com.blamejared.crafttweaker.impl.tag.MCTag)1 ExpandBlockState (com.blamejared.crafttweaker.impl_native.blocks.ExpandBlockState)1 JsonArray (com.google.gson.JsonArray)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 RecipeTypesAS (hellfirepvp.astralsorcery.common.lib.RecipeTypesAS)1 RegistriesAS (hellfirepvp.astralsorcery.common.lib.RegistriesAS)1 ByteBufUtils (hellfirepvp.astralsorcery.common.util.data.ByteBufUtils)1