Search in sources :

Example 1 with TileWell

use of hellfirepvp.astralsorcery.common.tile.TileWell in project AstralSorcery by HellFirePvP.

the class BlockWell method onReplaced.

@Override
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
    TileWell tw = MiscUtils.getTileAt(worldIn, pos, TileWell.class, true);
    if (tw != null && !worldIn.isRemote) {
        ItemStack stack = tw.getInventory().getStackInSlot(0);
        if (!stack.isEmpty()) {
            tw.breakCatalyst();
        }
    }
    super.onReplaced(state, worldIn, pos, newState, isMoving);
}
Also used : TileWell(hellfirepvp.astralsorcery.common.tile.TileWell) ItemStack(net.minecraft.item.ItemStack)

Example 2 with TileWell

use of hellfirepvp.astralsorcery.common.tile.TileWell 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

TileWell (hellfirepvp.astralsorcery.common.tile.TileWell)2 ItemStack (net.minecraft.item.ItemStack)2 WellLiquefaction (hellfirepvp.astralsorcery.common.crafting.recipe.WellLiquefaction)1 WellLiquefactionContext (hellfirepvp.astralsorcery.common.crafting.recipe.WellLiquefactionContext)1 FluidActionResult (net.minecraftforge.fluids.FluidActionResult)1 ItemStackHandler (net.minecraftforge.items.ItemStackHandler)1 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)1