Search in sources :

Example 1 with BlockTransmutation

use of hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation 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 BlockTransmutation

use of hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation 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 BlockTransmutation

use of hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation 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 BlockTransmutation

use of hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation 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)

Example 5 with BlockTransmutation

use of hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation in project AstralSorcery by HellFirePvP.

the class BlockTransmutationHandler method receiveStarlight.

@Override
public void receiveStarlight(World world, Random rand, BlockPos pos, BlockState state, IWeakConstellation starlightType, double amount) {
    BlockTransmutation recipe = RecipeTypesAS.TYPE_BLOCK_TRANSMUTATION.findRecipe(new BlockTransmutationContext(world, pos, state, starlightType));
    if (recipe == null) {
        // Wait what
        return;
    }
    WorldBlockPos at = WorldBlockPos.wrapServer(world, pos);
    ActiveTransmutation activeRecipe = runningTransmutations.get(at);
    if (activeRecipe == null || !activeRecipe.recipe.equals(recipe)) {
        activeRecipe = new ActiveTransmutation(recipe);
        runningTransmutations.put(at, activeRecipe);
    }
    activeRecipe.acceptStarlight(amount);
    PktPlayEffect pkt = new PktPlayEffect(PktPlayEffect.Type.BLOCK_TRANSMUTATION_TICK).addData(buf -> ByteBufUtils.writePos(buf, pos));
    PacketChannel.CHANNEL.sendToAllAround(pkt, PacketChannel.pointFromPos(world, pos, 24));
    if (activeRecipe.isFinished() && activeRecipe.finish(world, pos)) {
        runningTransmutations.remove(at);
    }
}
Also used : WorldBlockPos(hellfirepvp.astralsorcery.common.util.block.WorldBlockPos) BlockTransmutationContext(hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutationContext) PktPlayEffect(hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect) BlockTransmutation(hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation)

Aggregations

BlockTransmutation (hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutation)6 IWeakConstellation (hellfirepvp.astralsorcery.common.constellation.IWeakConstellation)4 BlockMatchInformation (hellfirepvp.astralsorcery.common.util.block.BlockMatchInformation)4 IConstellation (hellfirepvp.astralsorcery.common.constellation.IConstellation)3 BlockState (net.minecraft.block.BlockState)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 ActionAddRecipe (com.blamejared.crafttweaker.impl.actions.recipes.ActionAddRecipe)2 ItemStack (net.minecraft.item.ItemStack)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 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 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 BlockTransmutationContext (hellfirepvp.astralsorcery.common.crafting.recipe.BlockTransmutationContext)1 RecipeTypesAS (hellfirepvp.astralsorcery.common.lib.RecipeTypesAS)1 RegistriesAS (hellfirepvp.astralsorcery.common.lib.RegistriesAS)1 PktPlayEffect (hellfirepvp.astralsorcery.common.network.play.server.PktPlayEffect)1