Search in sources :

Example 1 with TileEntityDispenser

use of net.minecraft.tileentity.TileEntityDispenser in project MinecraftForge by MinecraftForge.

the class DispenseFluidContainer method fillContainer.

/**
     * Picks up fluid in front of a Dispenser and fills a container with it.
     */
@Nonnull
private ItemStack fillContainer(@Nonnull IBlockSource source, @Nonnull ItemStack stack) {
    World world = source.getWorld();
    EnumFacing dispenserFacing = source.getBlockState().getValue(BlockDispenser.FACING);
    BlockPos blockpos = source.getBlockPos().offset(dispenserFacing);
    FluidActionResult actionResult = FluidUtil.tryPickUpFluid(stack, null, world, blockpos, dispenserFacing.getOpposite());
    ItemStack resultStack = actionResult.getResult();
    if (!actionResult.isSuccess() || resultStack.isEmpty()) {
        return super.dispenseStack(source, stack);
    }
    if (stack.getCount() == 1) {
        return resultStack;
    } else if (((TileEntityDispenser) source.getBlockTileEntity()).addItemStack(resultStack) < 0) {
        this.dispenseBehavior.dispense(source, resultStack);
    }
    ItemStack stackCopy = stack.copy();
    stackCopy.shrink(1);
    return stackCopy;
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) TileEntityDispenser(net.minecraft.tileentity.TileEntityDispenser) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 2 with TileEntityDispenser

use of net.minecraft.tileentity.TileEntityDispenser in project TechReborn by TechReborn.

the class BehaviorDispenseScrapbox method dispenseStack.

@Override
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
    if (dispenseScrapboxes) {
        List<IBaseRecipeType> scrapboxRecipeList = RecipeHandler.getRecipeClassFromName(Reference.SCRAPBOX_RECIPE);
        int random = new Random().nextInt(scrapboxRecipeList.size());
        ItemStack out = scrapboxRecipeList.get(random).getOutput(0);
        stack.splitStack(1);
        TileEntityDispenser tile = source.getBlockTileEntity();
        EnumFacing enumfacing = tile.getWorld().getBlockState(new BlockPos(source.getX(), source.getY(), source.getZ())).getValue(BlockDispenser.FACING);
        IPosition iposition = BlockDispenser.getDispensePosition(source);
        doDispense(source.getWorld(), out, 6, enumfacing, iposition);
    }
    return stack;
}
Also used : IPosition(net.minecraft.dispenser.IPosition) Random(java.util.Random) EnumFacing(net.minecraft.util.EnumFacing) IBaseRecipeType(reborncore.api.recipe.IBaseRecipeType) TileEntityDispenser(net.minecraft.tileentity.TileEntityDispenser) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)2 TileEntityDispenser (net.minecraft.tileentity.TileEntityDispenser)2 EnumFacing (net.minecraft.util.EnumFacing)2 BlockPos (net.minecraft.util.math.BlockPos)2 Random (java.util.Random)1 Nonnull (javax.annotation.Nonnull)1 IPosition (net.minecraft.dispenser.IPosition)1 World (net.minecraft.world.World)1 IBaseRecipeType (reborncore.api.recipe.IBaseRecipeType)1