Search in sources :

Example 1 with WellLiquefaction

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

the class WellManager method addRecipe.

@ZenCodeType.Method
public void addRecipe(String name, Fluid output, IIngredient input, float productionMultiplier, float shatterMultiplier, @ZenCodeType.OptionalInt(0x00FF55FF) int color) {
    name = fixRecipeName(name);
    ResourceLocation recipeId = new ResourceLocation(name);
    WellLiquefaction recipe = new WellLiquefaction(recipeId, input.asVanillaIngredient(), output, new Color(color, true), productionMultiplier, shatterMultiplier);
    CraftTweakerAPI.apply(new ActionAddRecipe(this, recipe));
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) WellLiquefaction(hellfirepvp.astralsorcery.common.crafting.recipe.WellLiquefaction)

Example 2 with WellLiquefaction

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

the class WellRecipeSerializer method read.

@Override
public WellLiquefaction read(ResourceLocation recipeId, PacketBuffer buffer) {
    Ingredient input = Ingredient.read(buffer);
    Fluid fluid = ByteBufUtils.readRegistryEntry(buffer);
    float shatter = buffer.readFloat();
    float production = buffer.readFloat();
    Color color = ByteBufUtils.readOptional(buffer, buf -> new Color(buf.readInt(), true));
    return new WellLiquefaction(recipeId, input, fluid, color, production, shatter);
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) Fluid(net.minecraft.fluid.Fluid) WellLiquefaction(hellfirepvp.astralsorcery.common.crafting.recipe.WellLiquefaction)

Example 3 with WellLiquefaction

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

the class WellRecipeSerializer method read.

@Override
public WellLiquefaction read(ResourceLocation recipeId, JsonObject json) {
    Ingredient input = Ingredient.deserialize(JSONUtils.getJsonObject(json, "input"));
    String fluidKey = JSONUtils.getString(json, "output");
    Fluid fluid = ForgeRegistries.FLUIDS.getValue(new ResourceLocation(fluidKey));
    if (fluid == null) {
        throw new JsonSyntaxException("Unknown fluid: " + fluidKey);
    }
    float productionMultiplier = JSONUtils.getFloat(json, "productionMultiplier");
    float shatterMultiplier = JSONUtils.getFloat(json, "shatterMultiplier");
    Color color = null;
    if (json.has("color")) {
        color = JsonHelper.getColor(json, "color");
    }
    return new WellLiquefaction(recipeId, input, fluid, color, productionMultiplier, shatterMultiplier);
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Ingredient(net.minecraft.item.crafting.Ingredient) Fluid(net.minecraft.fluid.Fluid) ResourceLocation(net.minecraft.util.ResourceLocation) WellLiquefaction(hellfirepvp.astralsorcery.common.crafting.recipe.WellLiquefaction)

Example 4 with WellLiquefaction

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

the class BlockWell method onBlockActivated.

@Override
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
    if (!world.isRemote()) {
        ItemStack heldItem = player.getHeldItem(hand);
        if (!heldItem.isEmpty()) {
            TileWell tw = MiscUtils.getTileAt(world, pos, TileWell.class, false);
            if (tw == null) {
                return ActionResultType.PASS;
            }
            WellLiquefaction entry = RecipeTypesAS.TYPE_WELL.findRecipe(new WellLiquefactionContext(heldItem));
            if (entry != null) {
                ItemStackHandler handle = tw.getInventory();
                if (!handle.getStackInSlot(0).isEmpty()) {
                    return ActionResultType.PASS;
                }
                if (!world.isAirBlock(pos.up())) {
                    return ActionResultType.PASS;
                }
                handle.setStackInSlot(0, ItemUtils.copyStackWithSize(heldItem, 1));
                world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
                if (!player.isCreative()) {
                    heldItem.shrink(1);
                }
                if (heldItem.getCount() <= 0) {
                    player.setHeldItem(hand, ItemStack.EMPTY);
                }
            }
            tw.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null).ifPresent((handler) -> {
                FluidActionResult far = FluidUtil.tryFillContainerAndStow(heldItem, handler, new InvWrapper(player.inventory), FluidAttributes.BUCKET_VOLUME, player, true);
                if (far.isSuccess()) {
                    player.setHeldItem(hand, far.getResult());
                    SoundHelper.playSoundAround(SoundEvents.ITEM_BUCKET_FILL, world, pos, 1F, 1F);
                    tw.markForUpdate();
                }
            });
        }
    }
    return ActionResultType.SUCCESS;
}
Also used : ItemStackHandler(net.minecraftforge.items.ItemStackHandler) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) TileWell(hellfirepvp.astralsorcery.common.tile.TileWell) WellLiquefactionContext(hellfirepvp.astralsorcery.common.crafting.recipe.WellLiquefactionContext) ItemStack(net.minecraft.item.ItemStack) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) WellLiquefaction(hellfirepvp.astralsorcery.common.crafting.recipe.WellLiquefaction)

Aggregations

WellLiquefaction (hellfirepvp.astralsorcery.common.crafting.recipe.WellLiquefaction)4 Fluid (net.minecraft.fluid.Fluid)2 Ingredient (net.minecraft.item.crafting.Ingredient)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 WellLiquefactionContext (hellfirepvp.astralsorcery.common.crafting.recipe.WellLiquefactionContext)1 TileWell (hellfirepvp.astralsorcery.common.tile.TileWell)1 ItemStack (net.minecraft.item.ItemStack)1 FluidActionResult (net.minecraftforge.fluids.FluidActionResult)1 ItemStackHandler (net.minecraftforge.items.ItemStackHandler)1 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)1