Search in sources :

Example 1 with WellLiquefactionContext

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

the class TileWell method doClientEffects.

@OnlyIn(Dist.CLIENT)
private void doClientEffects() {
    ItemStack stack = this.inventory.getStackInSlot(0);
    if (!stack.isEmpty()) {
        runningRecipe = RecipeTypesAS.TYPE_WELL.findRecipe(new WellLiquefactionContext(this));
        if (runningRecipe != null) {
            Color color = Color.WHITE;
            if (runningRecipe.getCatalystColor() != null) {
                color = runningRecipe.getCatalystColor();
            }
            doCatalystEffect(color);
        }
    }
    if (tank.getFluidAmount() > 0 && tank.getFluid().getFluid() instanceof FluidLiquidStarlight) {
        BlockLiquidStarlight.playLiquidStarlightBlockEffect(rand, new Vector3(this).add(0, 0.4 + tank.getPercentageFilled() * 0.5, 0), 0.7F);
    }
}
Also used : WellLiquefactionContext(hellfirepvp.astralsorcery.common.crafting.recipe.WellLiquefactionContext) FluidLiquidStarlight(hellfirepvp.astralsorcery.common.fluid.FluidLiquidStarlight) Vector3(hellfirepvp.astralsorcery.common.util.data.Vector3) ItemStack(net.minecraft.item.ItemStack) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 2 with WellLiquefactionContext

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

the class TileWell method tick.

@Override
public void tick() {
    super.tick();
    if (!getWorld().isRemote()) {
        if (this.doesSeeSky()) {
            this.collectStarlight();
        }
        ItemStack stack = this.getInventory().getStackInSlot(0);
        if (!stack.isEmpty()) {
            if (!getWorld().isAirBlock(getPos().up())) {
                breakCatalyst();
            } else {
                if (runningRecipe == null) {
                    runningRecipe = RecipeTypesAS.TYPE_WELL.findRecipe(new WellLiquefactionContext(this));
                }
                if (runningRecipe != null) {
                    int statMultiplier = 1;
                    if (stack.getItem() instanceof CrystalAttributeItem) {
                        CrystalAttributes attributes = ((CrystalAttributeItem) stack.getItem()).getAttributes(stack);
                        if (attributes != null) {
                            statMultiplier = attributes.getTotalTierLevel();
                        }
                    }
                    double gain = Math.sqrt(starlightBuffer) * (statMultiplier * runningRecipe.getProductionMultiplier());
                    if (gain > 0 && tank.getFluidAmount() <= TANK_SIZE) {
                        fillAndDiscardRest(runningRecipe, gain);
                        if (rand.nextInt(750) == 0) {
                            EntityFlare.spawnAmbientFlare(getWorld(), getPos().add(-3 + rand.nextInt(7), 1, -3 + rand.nextInt(7)));
                        }
                    }
                    starlightBuffer = 0;
                    if (rand.nextInt(1 + (int) (1000 * (statMultiplier * runningRecipe.getShatterMultiplier()))) == 0) {
                        breakCatalyst();
                        EntityFlare.spawnAmbientFlare(getWorld(), getPos().add(-3 + rand.nextInt(7), 1, -3 + rand.nextInt(7)));
                    }
                } else {
                    breakCatalyst();
                }
            }
        }
        this.starlightBuffer = 0;
    } else {
        doClientEffects();
    }
}
Also used : CrystalAttributes(hellfirepvp.astralsorcery.common.crystal.CrystalAttributes) WellLiquefactionContext(hellfirepvp.astralsorcery.common.crafting.recipe.WellLiquefactionContext) ItemStack(net.minecraft.item.ItemStack) CrystalAttributeItem(hellfirepvp.astralsorcery.common.crystal.CrystalAttributeItem)

Example 3 with WellLiquefactionContext

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

WellLiquefactionContext (hellfirepvp.astralsorcery.common.crafting.recipe.WellLiquefactionContext)3 ItemStack (net.minecraft.item.ItemStack)3 WellLiquefaction (hellfirepvp.astralsorcery.common.crafting.recipe.WellLiquefaction)1 CrystalAttributeItem (hellfirepvp.astralsorcery.common.crystal.CrystalAttributeItem)1 CrystalAttributes (hellfirepvp.astralsorcery.common.crystal.CrystalAttributes)1 FluidLiquidStarlight (hellfirepvp.astralsorcery.common.fluid.FluidLiquidStarlight)1 TileWell (hellfirepvp.astralsorcery.common.tile.TileWell)1 Vector3 (hellfirepvp.astralsorcery.common.util.data.Vector3)1 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)1 FluidActionResult (net.minecraftforge.fluids.FluidActionResult)1 ItemStackHandler (net.minecraftforge.items.ItemStackHandler)1 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)1